FIX/McpWorkbench_errors_properties_and_grace_shutdown (#6444)

## Why are these changes needed?
Our McpWorkbench required properties however mongodb-lens's some tools
do not has it. I will fix it from when properties is None, -> {}
Our McpWorkbench now does not have stop routine with without async with
McpWorkbench(params) as workbench: and lazy init. So, I will adding def
__del__: pass just insert that, It could show error.

## Related issue number

Closes #6425

## Checks

- [ ] I've included any doc changes needed for
<https://microsoft.github.io/autogen/>. See
<https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to
build and test documentation locally.
- [x] I've added tests (if relevant) corresponding to the changes
introduced in this PR.
- [x] I've made sure all auto checks have passed.
This commit is contained in:
EeS 2025-05-03 07:23:54 +09:00 committed by GitHub
parent 6fc4f53212
commit 880a225cb2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View File

@ -177,7 +177,7 @@ class McpWorkbench(Workbench, Component[McpWorkbenchConfig]):
description = tool.description or ""
parameters = ParametersSchema(
type="object",
properties=tool.inputSchema["properties"],
properties=tool.inputSchema.get("properties", {}),
required=tool.inputSchema.get("required", []),
additionalProperties=tool.inputSchema.get("additionalProperties", False),
)
@ -279,3 +279,7 @@ class McpWorkbench(Workbench, Component[McpWorkbenchConfig]):
@classmethod
def _from_config(cls, config: McpWorkbenchConfig) -> Self:
return cls(server_params=config.server_params)
def __del__(self) -> None:
# Ensure the actor is stopped when the workbench is deleted
pass

View File

@ -571,3 +571,27 @@ async def test_mcp_workbench_server_filesystem() -> None:
tool = tools[0]
result = await new_workbench.call_tool(tool["name"], {"path": "README.md"}, CancellationToken())
assert result is not None
@pytest.mark.asyncio
async def test_lazy_init_and_finalize_cleanup() -> None:
params = StdioServerParams(
command="npx",
args=[
"-y",
"@modelcontextprotocol/server-filesystem",
".",
],
read_timeout_seconds=60,
)
workbench = McpWorkbench(server_params=params)
# Before any call, actor should not be initialized
assert workbench._actor is None # type: ignore[reportPrivateUsage]
# Trigger list_tools → lazy start
await workbench.list_tools()
assert workbench._actor is not None # type: ignore[reportPrivateUsage]
assert workbench._actor._active is True # type: ignore[reportPrivateUsage]
del workbench