Skip to content

Python: Support MCP tool binding by reference in declarative YAML#5052

Open
hashwnath wants to merge 1 commit intomicrosoft:mainfrom
hashwnath:fix/mcp-tool-binding-by-reference-4927
Open

Python: Support MCP tool binding by reference in declarative YAML#5052
hashwnath wants to merge 1 commit intomicrosoft:mainfrom
hashwnath:fix/mcp-tool-binding-by-reference-4927

Conversation

@hashwnath
Copy link
Copy Markdown
Contributor

Summary

Fixes #4927

AgentFactory._parse_tool() ignores self.bindings for the McpTool case, unlike FunctionTool where bindings correctly resolve the callable. This causes pre-built MCP tool dicts passed via AgentFactory(bindings={"product-mcp": mcp_tool}) to be silently ignored — the factory always constructs the tool from YAML fields, resulting in server_url: '' and a 500 error when no url is specified in the YAML.

This PR adds binding resolution for McpTool in _parse_tool(), mirroring the existing FunctionTool pattern:

  1. Explicit bindings — checks tool_resource.bindings list against self.bindings dict
  2. Name-based fallback — matches tool_resource.name directly against self.bindings keys

If a binding resolves, the pre-built tool dict is returned directly. If no binding matches, the existing dict-building logic runs unchanged.

Changes

  • _loader.py: Added binding-by-reference resolution in the McpTool case of _parse_tool()
  • test_declarative_loader.py: Added 4 tests:

Test plan

  • All 723 existing declarative tests pass
  • New tests verify both binding resolution paths and the fallback
  • Ruff format and lint clean
  • Regression test verifies the exact issue scenario (no server_url: '')

…crosoft#4927)

Add binding resolution for McpTool in AgentFactory._parse_tool(), matching
the existing FunctionTool pattern. MCP tools can now be resolved either by
explicit bindings list or by matching the tool name against factory bindings,
allowing pre-built MCP tool dicts to be passed via AgentFactory(bindings=...)
instead of requiring full connection details in every YAML file.

Fixes microsoft#4927
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Support MCP tool binding by reference in declarative YAML

2 participants