Skip to content

Python: Pass MCP server tools to Claude and Copilot agents - #7835

Open
NekoPunch (orangeCatDeveloper) wants to merge 3 commits into
microsoft:mainfrom
orangeCatDeveloper:python-mcp-tools-claude-copilot
Open

Python: Pass MCP server tools to Claude and Copilot agents#7835
NekoPunch (orangeCatDeveloper) wants to merge 3 commits into
microsoft:mainfrom
orangeCatDeveloper:python-mcp-tools-claude-copilot

Conversation

@orangeCatDeveloper

Copy link
Copy Markdown
Contributor

Motivation & Context

An MCP server handed to ClaudeAgent or GitHubCopilotAgent is silently dropped: no error, no warning, and none of its tools reach the model.

weather = MCPStdioTool(name="weather", command="python", args=["weather_server.py"])

agent = ClaudeAgent(tools=[weather])
await agent.run("What is the weather in Beijing?")   # "I have no tool for that"

The same code works on ChatAgent, so the failure looks like a model problem rather than a wiring one.

Description & Review Guide

  • What are the major changes?

Both provider agents convert tools themselves and only recognise FunctionTool; anything else is skipped. An MCPTool is a server connection rather than a callable tool, so it fell into that branch and never contributed anything.

ChatAgent already 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, expands tool.functions, rejects duplicate tool names with the same message ChatAgent uses, 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.

  • What is the impact of these changes?

MCP servers work with both agents. Two behaviours are worth a reviewer's opinion: a server using use_progressive_disclosure is now rejected with an explicit error rather than silently exposing unusable loader tools, and an injected ClaudeSDKClient now 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_servers config, matching ChatAgent. The native path would bypass allowed_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-core lower bound needs to move when they are next released.

Before / after, same real MCP stdio server exposing get_weather and get_forecast, inspecting the options each agent hands to its SDK:

before                          after
Claude  allowed_tools : []  →   ['mcp___agent_framework_tools__get_weather',
                                 'mcp___agent_framework_tools__get_forecast']
Claude  mcp_servers   : []  →   ['_agent_framework_tools']
Copilot tools         : []  →   ['get_weather', 'get_forecast']

Related Issue

Fixes #3651

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread python/packages/claude/agent_framework_claude/_agent.py Outdated
@giles17

Copy link
Copy Markdown
Contributor

/review

@github-actions

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/claude/agent_framework_claude
   _agent.py3792792%429–430, 434, 447–449, 460–461, 481–482, 548–549, 599, 603, 605, 609, 618, 706, 711–712, 787, 875, 888, 950–953
packages/core/agent_framework
   _mcp.py140711591%285, 291, 400, 419, 640, 719–720, 834, 859, 910, 1025, 1028, 1038, 1042, 1089–1090, 1095, 1102–1103, 1110, 1115–1116, 1123–1124, 1128, 1133–1134, 1143, 1150–1151, 1169, 1182, 1206–1207, 1226–1229, 1231–1232, 1236, 1262, 1296–1298, 1300, 1354–1356, 1415–1416, 1699, 1740–1741, 1754, 1757, 1766–1767, 1772–1773, 1779, 1833–1834, 1854–1855, 1864–1865, 1870–1871, 1877, 1955, 1958, 1985, 2008–2012, 2035–2037, 2042, 2046–2047, 2154, 2161, 2163, 2239, 2254–2255, 2262–2263, 2268–2269, 2274, 2278, 2293, 2355, 2538, 2540, 2562, 2564–2567, 2580–2581, 2625, 2687, 3191–3192, 3237, 3468–3469, 3487
packages/github_copilot/agent_framework_github_copilot
   _agent.py5222595%106–107, 152, 161–163, 167, 310–311, 315, 797, 812–813, 892, 905, 1042, 1046, 1215, 1249–1250, 1289, 1292, 1429, 1533, 1552
TOTAL48115449090% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9726 36 💤 0 ❌ 0 🔥 2m 7s ⏱️

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread python/packages/claude/agent_framework_claude/_agent.py
Comment thread python/packages/github_copilot/agent_framework_github_copilot/_agent.py Outdated
Comment thread python/packages/github_copilot/agent_framework_github_copilot/_agent.py Outdated
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Feature]: Add Support for Converting Agent Framework MCPTools to GitHub Copilot SDK / Claude SDK

3 participants