Skip to content

Commit 880a225

Browse files
authored
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.
1 parent 6fc4f53 commit 880a225

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

python/packages/autogen-ext/src/autogen_ext/tools/mcp/_workbench.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ async def list_tools(self) -> List[ToolSchema]:
177177
description = tool.description or ""
178178
parameters = ParametersSchema(
179179
type="object",
180-
properties=tool.inputSchema["properties"],
180+
properties=tool.inputSchema.get("properties", {}),
181181
required=tool.inputSchema.get("required", []),
182182
additionalProperties=tool.inputSchema.get("additionalProperties", False),
183183
)
@@ -279,3 +279,7 @@ def _to_config(self) -> McpWorkbenchConfig:
279279
@classmethod
280280
def _from_config(cls, config: McpWorkbenchConfig) -> Self:
281281
return cls(server_params=config.server_params)
282+
283+
def __del__(self) -> None:
284+
# Ensure the actor is stopped when the workbench is deleted
285+
pass

python/packages/autogen-ext/tests/tools/test_mcp_tools.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,3 +571,27 @@ async def test_mcp_workbench_server_filesystem() -> None:
571571
tool = tools[0]
572572
result = await new_workbench.call_tool(tool["name"], {"path": "README.md"}, CancellationToken())
573573
assert result is not None
574+
575+
576+
@pytest.mark.asyncio
577+
async def test_lazy_init_and_finalize_cleanup() -> None:
578+
params = StdioServerParams(
579+
command="npx",
580+
args=[
581+
"-y",
582+
"@modelcontextprotocol/server-filesystem",
583+
".",
584+
],
585+
read_timeout_seconds=60,
586+
)
587+
workbench = McpWorkbench(server_params=params)
588+
589+
# Before any call, actor should not be initialized
590+
assert workbench._actor is None # type: ignore[reportPrivateUsage]
591+
592+
# Trigger list_tools → lazy start
593+
await workbench.list_tools()
594+
assert workbench._actor is not None # type: ignore[reportPrivateUsage]
595+
assert workbench._actor._active is True # type: ignore[reportPrivateUsage]
596+
597+
del workbench

0 commit comments

Comments
 (0)