Skip to content

Python: Move the TypeSafe MCP sample to mcp 2.x - #9756

Draft
Naveen Chatlapalli (1aifanatic) wants to merge 1 commit into
microsoft:mainfrom
1aifanatic:contrib/python-typesafe-mcp-sample
Draft

Naveen Chatlapalli (1aifanatic) wants to merge 1 commit into
microsoft:mainfrom
1aifanatic:contrib/python-typesafe-mcp-sample

Conversation

@1aifanatic

Copy link
Copy Markdown
Contributor

Motivation & Context

The TypeSafe MCP sample (packages/typesafe/samples/mcp_function_calling.py with mcp_weather_server.py) can't connect to its server under either supported mcp major version:

mcp installed what fails
>=1.27.0,<2, as the README command and both PEP 723 headers pin The Agent Framework MCP client: ToolException: Failed to create MCP session ... cannot import name 'Client' from 'mcp'. Since the MCP SDK 2.x migration, core's MCP tools need mcp 2.x; core's all extra pins mcp>=2.2.0,<3.
2.x, e.g. the workspace's 2.3.0 The server subprocess: No module named 'mcp.server.fastmcp' (FastMCP became MCPServer in 2.x). The client then reports Connection closed.

Description & Review Guide

  • What are the major changes?
    • mcp_weather_server.py now uses mcp.server.mcpserver.MCPServer, the same API as samples/04-hosting/mcp/mcpserver_app.py. The tool passes structured_output=False so it still returns plain text (Seattle is sunny and 22 C.), matching the sample's documented output. Without it, mcp 2.x returns {"result": "..."} as the text content.
    • Both PEP 723 headers and the README run command now require mcp>=2.2.0,<3.
  • What is the impact of these changes? Sample only.
  • What do you want reviewers to focus on? Nothing special.

Verification: with the README's command (uv run --with "mcp>=2.2.0,<3" --package agent-framework-typesafe ...), MCPStdioTool launched the server, discovered get_weather, and returned Seattle is sunny and 22 C. for {"city": "Seattle", "detailed": false}. On main, both rows above fail. uv run --script mcp_weather_server.py also resolves and starts the server. I couldn't run the full sample because it needs a TYPESAFE_API_KEY. I found this by type-checking the example code shipped inside packages: pyright reported "FastMCP" is unknown import symbol.

Related Issue

N/A - trivial change: the sample is updated to the MCP SDK major version that Agent Framework's MCP client already requires.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: Claude Code helped find this by type-checking the package samples, reproduce both failure modes, port the server, and draft this description.

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 links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • 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.

🤖 Generated with Claude Code

The MCP sample pinned mcp<2, but Agent Framework's MCP client imports
mcp.Client from mcp 2.x, so the documented command failed to open the MCP
session. With mcp 2.x installed instead, the weather server failed to start
because FastMCP was renamed to MCPServer. Port the server to MCPServer,
keep its tool returning plain text, and pin both scripts and the README
command to mcp>=2.2.0,<3 like the rest of the repository.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 27, 2026 12:48
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Oct 27, 2026

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.

🟢 Approval recommended

The narrow sample-only migration aligns with existing repository usage and dependency requirements, with no unresolved findings.

No open issues 🎉

What changed in this PR

Updates the TypeSafe MCP sample to MCP 2.x, aligning it with the Agent Framework MCP client’s dependency requirements.

Changes:

  • Updates both script dependency headers and the README command to mcp>=2.2.0,<3.
  • Replaces FastMCP with MCPServer.
  • Disables structured output to preserve the documented plain-text weather response.
File Description
python/​packages/​typesafe/​samples/​README.md Updates the run command to require MCP 2.x.
python/​packages/​typesafe/​samples/​mcp_weather_server.py Migrates the server API and dependency while preserving plain-text output.
python/​packages/​typesafe/​samples/​mcp_function_calling.py Aligns the client script’s dependency with MCP 2.x.

Review effort: Balanced

This branch was previously deployed

1 inactive deployment
github-app-auth — bef59e85 Deployed Oct 27, 2026 by 1aifanatic via team_check #7675
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants