FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Python: MCP long-running task support in Python by peibekwe · Pull Request #6319 · microsoft/agent-framework · GitHub

Repository navigation

Python: MCP long-running task support in Python - #6319

Merged
Peter Ibekwe (peibekwe) merged 6 commits into
mainfrom
peibekwe/mcp-lro-python
Jun 5, 2026
Merged

Peter Ibekwe (peibekwe) merged 6 commits into
mainfrom
peibekwe/mcp-lro-python

Conversation

Copy link
Copy Markdown
Contributor

Motivation and Context

Ports the MCP long-running task (SEP-2663) feature from .NET to Python. When an MCP server advertises a tool with execution.taskSupport == "required", MCPTool now transparently drives the tools/call - tasks/get (polled) - tasks/result lifecycle, so the agent's function-calling loop sees a normal synchronous tool result.

This is purely additive, those tools could not complete via plain tools/call before, so the new path fixes a previously broken case without changing any existing behavior. Matches The work done in #5994

Fixes #6258

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
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings June 4, 2026 00:24
Evan Mattson (moonbox3) added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Jun 4, 2026
github-actions Bot changed the title MCP long-running task support in Python Python: MCP long-running task support in Python Jun 4, 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

Adds Python-side support for MCP SEP-2663 long-running tasks so tools advertising execution.taskSupport == "required" are executed via the tools/call → tasks/get (poll) → tasks/result lifecycle while still presenting a normal synchronous tool result to the agent loop.

Changes:

  • Implement MCP long-running task orchestration in MCPTool.call_tool (task-aware routing, polling, result coercion, cancellation, reconnect behavior, and legacy fallbacks).
  • Add extensive unit coverage for required/optional routing, TTL propagation, polling interval clamping, cancellation behavior, reconnect semantics, and legacy/fallback server responses.
  • Document and sample the feature (new sample script + README updates + core AGENTS.md update) and export MCPTaskOptions as a public API.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
python/samples/02-agents/mcp/README.md Adds the new long-running task sample and documents additional prerequisites for it.
python/samples/02-agents/mcp/mcp_long_running_task.py New end-to-end sample that self-spawns a stdio MCP server advertising taskSupport=required and exercises transparent task handling.
python/packages/core/tests/core/test_mcp.py New test region covering the SEP-2663 lifecycle, fallbacks, reconnect/cancellation behavior, and option validation.
python/packages/core/AGENTS.md Documents the MCP task feature and usage/behavior at a high level (one bullet needs to be corrected to match implementation).
python/packages/core/agent_framework/_mcp.py Core implementation: MCPTaskOptions, task-support discovery from list_tools, task-aware call_tool routing, and the tasks/* lifecycle driver.
python/packages/core/agent_framework/_feature_stage.py Adds the MCP_LONG_RUNNING_TASKS experimental feature flag identifier.
python/packages/core/agent_framework/init.py Exports MCPTaskOptions from the public package surface.

Comment thread python/packages/core/AGENTS.md Outdated

github-actions Bot commented Jun 4, 2026 •
edited
Loading

Copy link
Copy Markdown
Contributor

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _feature_stage.py1681094%109, 155, 210, 221, 241, 279, 290, 296, 327, 355
   _mcp.py10468891%230, 249, 404, 464–465, 594, 656, 669, 693–694, 713–716, 718–719, 723, 749, 782–784, 786, 839–841, 896–897, 1080, 1121–1122, 1135, 1138, 1146–1147, 1152–1153, 1159, 1207–1208, 1223–1224, 1232–1233, 1238–1239, 1245, 1309, 1312, 1339, 1362–1366, 1389–1391, 1396, 1400–1401, 1485, 1494, 1500, 1561, 1576–1577, 1584–1585, 1590–1591, 1596, 1600, 1617, 1679, 1868, 1870, 1892, 1894–1897, 1910–1911, 1958, 2010–2011, 2014, 2500
TOTAL38273444788% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
7630 34 💤 0 ❌ 0 🔥 2m 1s ⏱️

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Automated Code Review

Reviewers: 4 | Confidence: 88% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by peibekwe's agents

Peter Ibekwe (peibekwe) and others added 3 commits June 3, 2026 17:34
- pyupgrade: drop forward-reference string annotations in _mcp.py (Python 3.10+ resolves them natively now that MCPTaskOptions is defined before use).

- AGENTS.md: align reconnect description with current behavior. Phase 1 (initial tools/call) does NOT retry on connection loss; raises 'connection lost; task state unknown' instead, so a server that accepted the request but lost the response cannot start the operation twice. Phase 2 (tasks/get / tasks/result) still reconnects once against the same task_id.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Peter Ibekwe (peibekwe) marked this pull request as ready for review June 4, 2026 00:52

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Automated Code Review

Reviewers: 3 | Confidence: 85% | Result: All clear

Reviewed: Security Reliability, Test Coverage, Design Approach


Automated review by peibekwe's agents

Vincent Biret (baywet) deleted the peibekwe/mcp-lro-python branch September 17, 2026 14:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

Python: Port MCP LRO support to Python

4 participants


Back | FazBrowse Home | New Git URL