Add guide for workbench and mcp & bug fixes for create_mcp_server_session (#6392)

Add user guide for workbench and mcp

*Also fixed a bug in create_mcp_server_session that included "type" in
the parameters Resolves: #6392
This commit is contained in:
Eric Zhu 2025-04-24 14:19:09 -07:00 committed by GitHub
parent f059262b6d
commit cbd8745f2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 355 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -48,6 +48,7 @@ framework/component-config
components/model-clients
components/model-context
components/tools
components/workbench
components/command-line-code-executors
```

View File

@ -52,6 +52,28 @@ class ToolResult(BaseModel):
is_error: bool = False
"""Whether the tool execution resulted in an error."""
def to_text(self, replace_image: str | None = None) -> str:
"""
Convert the result to a text string.
Args:
replace_image (str | None): The string to replace the image content with.
If None, the image content will be included in the text as base64 string.
Returns:
str: The text representation of the result.
"""
parts: List[str] = []
for content in self.result:
if isinstance(content, TextResultContent):
parts.append(content.content)
elif isinstance(content, ImageResultContent):
if replace_image is not None:
parts.append(replace_image)
else:
parts.append(f"[Image: {content.content.to_base64()}]")
return "\n".join(parts)
class Workbench(ABC, ComponentBase[BaseModel]):
"""

View File

@ -57,6 +57,7 @@ async def test_static_workbench() -> None:
assert result_1.name == "test_tool_1"
assert result_1.result[0].type == "TextResultContent"
assert result_1.result[0].content == "10"
assert result_1.to_text() == "10"
assert result_1.is_error is False
# Call tool with error
@ -64,6 +65,7 @@ async def test_static_workbench() -> None:
assert result_2.name == "test_tool_2"
assert result_2.result[0].type == "TextResultContent"
assert result_2.result[0].content == "This is a test error"
assert result_2.to_text() == "This is a test error"
assert result_2.is_error is True
# Save state.
@ -109,6 +111,7 @@ async def test_static_workbench() -> None:
assert result_1.name == "test_tool_1"
assert result_1.result[0].type == "TextResultContent"
assert result_1.result[0].content == "10"
assert result_1.to_text() == "10"
assert result_1.is_error is False
# Call tool with error
@ -116,4 +119,5 @@ async def test_static_workbench() -> None:
assert result_2.name == "test_tool_2"
assert result_2.result[0].type == "TextResultContent"
assert result_2.result[0].content == "This is a test error"
assert result_2.to_text() == "This is a test error"
assert result_2.is_error is True

View File

@ -23,6 +23,6 @@ async def create_mcp_server_session(
) as session:
yield session
elif isinstance(server_params, SseServerParams):
async with sse_client(**server_params.model_dump()) as (read, write):
async with sse_client(**server_params.model_dump(exclude={"type"})) as (read, write):
async with ClientSession(read_stream=read, write_stream=write) as session:
yield session