Python: Pass MCP server tools to Claude and Copilot agents - #7835
Python: Pass MCP server tools to Claude and Copilot agents#7835NekoPunch (orangeCatDeveloper) wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds shared MCP tool expansion so Claude and GitHub Copilot agents can expose MCP server functions.
Changes:
- Adds
_expand_mcp_tools()with connection, validation, and deduplication. - Integrates expansion and lifecycle management into both provider agents.
- Adds MCP expansion and concurrency tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
python/packages/core/agent_framework/_mcp.py |
Adds shared MCP expansion helper. |
python/packages/core/tests/core/test_mcp.py |
Tests expansion and validation. |
python/packages/claude/agent_framework_claude/_agent.py |
Integrates MCP tools into Claude SDK options. |
python/packages/claude/tests/test_claude_agent.py |
Tests Claude MCP integration. |
python/packages/github_copilot/agent_framework_github_copilot/_agent.py |
Integrates MCP tools into Copilot sessions. |
python/packages/github_copilot/tests/test_github_copilot_agent.py |
Tests Copilot MCP integration. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
/review |
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (2 commit(s)): cabe20e88030, 68d2e04cce20
Model: gpt-5.6-sol
Overview
The PR centralizes MCP expansion and gives both provider agents explicit connection ownership, duplicate-name validation, progressive-disclosure rejection, approval integration, and concurrency guards. The new behavior is well covered across agent-, default-, and run-level tools, but the provider dependency bounds do not yet guarantee the new core helper exists. Copilot also retains dynamically supplied per-run MCP connections for the lifetime of the agent, allowing resources to accumulate across completed runs.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
3 verified findings remained after source verification (2 high, 1 medium) across 2 files. Details are attached to the affected lines below.
Affected areas: python/packages/claude/agent_framework_claude/_agent.py, python/packages/github_copilot/agent_framework_github_copilot/_agent.py
Both agents only understood FunctionTool, so an MCPTool handed to them was silently dropped and its remote tools never reached the model. They now expand MCP servers the way ChatAgent already does.
b54b8a4 to
e4e6670
Compare
Motivation & Context
An MCP server handed to
ClaudeAgentorGitHubCopilotAgentis silently dropped: no error, no warning, and none of its tools reach the model.The same code works on
ChatAgent, so the failure looks like a model problem rather than a wiring one.Description & Review Guide
Both provider agents convert tools themselves and only recognise
FunctionTool; anything else is skipped. AnMCPToolis a server connection rather than a callable tool, so it fell into that branch and never contributed anything.ChatAgentalready handles this: it connects the server and passes the tools the server exposes. That step now lives in a shared core helper,_expand_mcp_tools(), which both agents call before they build their SDK options. It connects each server on an agent-owned exit stack, expandstool.functions, rejects duplicate tool names with the same messageChatAgentuses, and refuses servers configured for progressive disclosure, whose loader tools only work inside a framework function-calling run.The configured tool list is never modified, so a server reconnects on the next run after
stop(), and expansion is serialised per agent because runs are deliberately not.MCP servers work with both agents. Two behaviours are worth a reviewer's opinion: a server using
use_progressive_disclosureis now rejected with an explicit error rather than silently exposing unusable loader tools, and an injectedClaudeSDKClientnow logs a warning that configured tools cannot be registered (its options belong to the caller, so this already applied to every tool type).Tools are expanded into function tools rather than translated into each SDK's native
mcp_serversconfig, matchingChatAgent. The native path would bypassallowed_tools,approval_mode, sampling approval and OTel spans, and neither SDK has a websocket server config. Worth its own issue if the native direction is wanted.Because both provider packages now use a core helper, their
agent-framework-corelower bound needs to move when they are next released.Before / after, same real MCP stdio server exposing
get_weatherandget_forecast, inspecting the options each agent hands to its SDK:Related Issue
Fixes #3651
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.