Skip to content

Python: Introducing Local MCP Servers - #389

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 5 commits into
microsoft:mainfrom
eavanvalkenburg:mcp_new
Aug 13, 2025
Merged

Python: Introducing Local MCP Servers#389
Eduard van Valkenburg (eavanvalkenburg) merged 5 commits into
microsoft:mainfrom
eavanvalkenburg:mcp_new

Conversation

@eavanvalkenburg

@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) commented Aug 11, 2025

Copy link
Copy Markdown
Member

Motivation and Context

Adds MCP tools to AF

Closes #292

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • I didn't break anyone 😄

Copilot AI review requested due to automatic review settings August 11, 2025 08:36
@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) added the python Usage: [Issues, PRs], Target: Python label Aug 11, 2025
@github-actions github-actions Bot changed the title Mcp tools Python: Mcp tools Aug 11, 2025

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

This PR adds MCP (Model Context Protocol) tools integration to the Agent Framework, enabling agents to connect to and use MCP servers for extended functionality. The implementation provides multiple connection types (stdio, SSE, websocket, and streamable HTTP) and seamlessly integrates MCP tools with existing agent capabilities.

  • Adds comprehensive MCP server integration with support for multiple transport protocols
  • Extends ChatClientAgent to accept and manage MCP tools alongside traditional tools
  • Includes sample implementations demonstrating MCP usage with both OpenAI chat and responses clients

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
python/packages/main/agent_framework/_mcp.py Core MCP implementation with server classes and protocol conversion utilities
python/packages/main/agent_framework/_agents.py Extended ChatClientAgent to support MCP tools with proper context management
python/packages/main/agent_framework/init.py Exported MCP classes for public API
python/packages/main/pyproject.toml Added mcp>=1.12 dependency
python/packages/main/tests/main/test_mcp.py Comprehensive test suite for MCP functionality
python/samples/getting_started/agents/openai_chat_client/openai_chat_client_with_local_mcp.py Sample showing MCP usage with OpenAI chat client
python/samples/getting_started/agents/openai_responses_client/openai_responses_client_with_local_mcp.py Sample showing MCP usage with OpenAI responses client
python/pyproject.toml Updated install command to include all extras
python/.vscode/launch.json Added justMyCode: false for debugging
.github/workflows/python-merge-tests.yml Added LOCAL_MCP_URL environment variable for CI

Comment thread python/packages/main/agent_framework/_mcp.py
Comment thread python/packages/main/agent_framework/_mcp.py Outdated
Comment thread python/packages/main/agent_framework/_mcp.py
Comment thread python/packages/main/agent_framework/_mcp.py Outdated
Comment thread python/packages/main/agent_framework/_mcp.py Outdated
Comment thread python/packages/main/tests/main/test_mcp.py
Comment thread python/packages/main/tests/main/test_mcp.py Outdated

@ekzhu Eric Zhu (ekzhu) 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.

Looks great!

Are we planning to also include the sampling and elicitation features of MCP used currently?

See the AG branch that uses them to drive the agent actions: microsoft/autogen#6833

@eavanvalkenburg

Copy link
Copy Markdown
Member Author

Eric Zhu (@ekzhu) sampling already works, you can pass a ChatClient to the constructor of the McpServer and that is used to do sampling if requested. I have not looked at elicitation, but I will, thanks for pointing to that

@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) marked this pull request as ready for review August 12, 2025 13:19
@eavanvalkenburg

Copy link
Copy Markdown
Member Author

added a issue to track elicitation #398

@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) changed the title Python: Mcp tools Python: Introducing Local MCP Servers Aug 12, 2025
@victordibia

Victor Dibia (victordibia) commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

This looks great Eduard van Valkenburg (@eavanvalkenburg)

One future thing to track is our thinking on how to “pipe” in streamed updates from tools. Many tools have agentic behaviors (long running) can send notifications (resource updates, progress notifications, logging ). These may include useful information or even partial results which the rest of the application can benefit from (as well as UI updates). Might be worth exploring a setup where devs can pass in a message handler callback for these scenarios.

related post on long runnning tools here.

@eavanvalkenburg

Copy link
Copy Markdown
Member Author

thanks Victor Dibia (@victordibia), peterychang is working on broader support for long-running things, and I think this might fit in there. we do already have a message handler in here, so that can easily be extended to handle other updates, and elicitation depends on broader user request structures we are working on, as noted, already a issue created for tracking that.

@eavanvalkenburg

Eduard van Valkenburg (eavanvalkenburg) commented Aug 13, 2025

Copy link
Copy Markdown
Member Author

Python Test Coverage

Python Test Coverage Report
FileStmtsMissCoverMissing
packages/azure/agent_framework_azure
   _assistants_client.py36877%100, 103, 114–117, 121–122
   _chat_client.py60591%103, 151, 153, 166–167
   _entra_id_authentication.py231630%35–36, 40–44, 46, 66–67, 71–75, 77
   _responses_client.py31293%92, 99
   _shared.py81890%158–159, 221, 224, 237, 239, 249, 257
packages/foundry/agent_framework_foundry
   _chat_client.py22912047%144–145, 152–153, 156–159, 161–162, 165–167, 169, 178, 200, 218, 230, 233, 237–238, 241, 244, 247–248, 264–269, 289, 292–293, 295, 297, 301–302, 305, 308, 314, 318–319, 321–322, 328–329, 335, 337, 342–343, 345, 347, 349, 359–362, 364–365, 371–374, 382–386, 394, 399–401, 409, 414, 421, 430, 441, 443–449, 453, 458, 483–491, 493–494, 496–500, 505, 511, 528–529, 531, 538–545, 561, 586, 605–606
packages/main/agent_framework
   _agents.py1922288%67, 222, 417, 437–440, 447, 457, 527–528, 530, 533, 651–652, 654, 657, 765, 777, 782–783, 785
   _cancellation_token.py31310%3–6, 10, 13–16, 18, 20–24, 26, 28–29, 31, 33–35, 37, 39, 41–43, 46–47, 49–50
   _clients.py1561789%56, 66–68, 126–127, 145–146, 189–190, 393, 437, 504, 584, 634, 662, 664
   _logging.py80100% 
   _mcp.py30812061%133, 143–144, 165, 188, 198, 202, 204, 206, 253, 257–262, 265–266, 276–278, 281–283, 285–290, 292–294, 297–298, 310–311, 315–320, 326–327, 331–332, 336, 338, 342–343, 347, 361, 376–386, 391, 394–395, 399, 414, 417–418, 422, 443, 448, 450, 457–458, 463, 465, 471–474, 481–485, 558, 563–567, 632, 635–643, 710, 713–723, 779, 782–784
   _pydantic.py27196%61
   _tools.py131596%113, 159, 239, 264, 313
   _types.py7397789%162, 180–184, 216, 456–461, 463, 466–469, 471–472, 492, 497, 501, 505–507, 560–565, 567, 570–573, 575–576, 592–602, 605–609, 712, 942, 946, 948, 1437, 1441–1443, 1474, 1638, 1643, 1677, 1734, 1738, 1761, 1793, 1805, 1837–1839, 1906, 1911
   exceptions.py310100% 
   guard_rails.py10100%4, 6–7, 9, 12–13, 16, 21–22, 25
   telemetry.py2972790%315–317, 420, 422, 424, 426, 428, 430, 432, 434, 436, 476, 481, 654, 656, 658, 660, 662, 664, 666, 668, 670, 672, 674, 701, 724
packages/main/agent_framework/openai
   _assistants_client.py18812831%146, 159, 162, 166–167, 170, 173, 176–177, 209, 211, 213, 215, 218, 221, 224, 228, 232–233, 235–238, 242, 244, 249–250, 252, 254, 256, 259, 261–264, 272–276, 278–280, 288–291, 299, 304–305, 312, 321, 332, 334–339, 341, 349, 351–355, 357–358, 360–369, 371–372, 374–376, 381, 386–387, 392–393, 395, 400–403, 405, 407, 409–413, 416–419, 421–424, 431–432, 434–435, 437, 443–444, 446–447, 451, 453, 460, 462–463, 465–467, 469, 479–480
   _chat_client.py1793679%98–99, 103, 116–123, 125–126, 133, 137, 159, 181, 208, 219–221, 246–247, 249, 255, 298, 301, 303, 305, 307–309, 323–324, 330, 343
   _exceptions.py330100% 
   _responses_client.py28321822%142, 228, 251, 262–265, 269–270, 272–273, 278–282, 286, 290–291, 303–307, 311–312, 315–316, 318, 322–323, 326–329, 333, 337–338, 348–361, 367–370, 379–380, 382–383, 387, 389–392, 394–395, 397, 399–406, 425–428, 433–434, 436, 446, 448–451, 470–474, 477–483, 492–493, 503–504, 517–518, 534–538, 541–547, 554–560, 568, 570–572, 581–583, 590–593, 601–609, 618–621, 623–647, 656–657, 659, 669, 674–678, 686–687, 690–707, 716–718, 725, 727, 732–736, 741–742, 746–747, 750
   _shared.py731382%55–60, 62–65, 67, 171, 182
packages/workflow/agent_framework_workflow
   _checkpoint.py122397%40, 165–166
   _const.py10100% 
   _edge.py64592%71, 74, 101, 139, 153
   _events.py49981%37, 41, 49, 53, 100, 124, 128, 136, 140
   _executor.py1092081%62, 80, 236–240, 245, 247–250, 254–256, 258, 262, 264–265, 330
   _runner.py1702982%84–86, 88, 134, 167–169, 189–193, 197, 201–202, 223–224, 236–237, 248–250, 254, 261–263, 268–269
   _runner_context.py117694%205, 208, 227, 248, 270, 285
   _shared_state.py35585%28–29, 33–34, 68
   _typing_utils.py17852%26, 33–36, 43–44, 50
   _validation.py2062189%178, 296, 299, 357, 361, 448, 450, 453–454, 456–458, 460–462, 465–469, 474
   _workflow.py1762983%44, 109, 131, 181, 189–191, 203, 217, 319, 339–340, 342–344, 359–361, 369–370, 379–385, 390, 392
   _workflow_context.py37975%40, 77, 86, 91, 99–100, 104–106
TOTAL4249100876% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
422 31 💤 0 ❌ 0 🔥 7.527s ⏱️

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 13, 2025
Merged via the queue into microsoft:main with commit ad3d817 Aug 13, 2025
22 checks passed
Reuben Bond (ReubenBond) pushed a commit to ReubenBond/agent-framework that referenced this pull request Oct 28, 2025
* mcp parts

* mcp parts 2

* removed structured output in favor of handling in chatresponse, mcp as AITool and running samples

* updated naming

* fixed test
AQ-1970 (Arturo-Quiroga-MSFT) pushed a commit to Arturo-Quiroga-MSFT/agent-framework-public that referenced this pull request Nov 23, 2025
* mcp parts

* mcp parts 2

* removed structured output in favor of handling in chatresponse, mcp as AITool and running samples

* updated naming

* fixed test
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: local MCP support

4 participants