Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
254b89b
Python: fix(core): do not replay MCP tools/call without an idempotenc…
he-yufeng Oct 22, 2026
56d0dd8
Python: test(core): opt the reset integration into the trust gate
he-yufeng Oct 22, 2026
13c789d
Merge branch 'main' into fix/mcp-call-no-replay-without-idempotency
he-yufeng Oct 23, 2026
b6246e3
Python: test(core): align MCP replay fixtures with SDK and replay gate
he-yufeng Oct 25, 2026
6303696
Merge remote-tracking branch 'origin/main' into resume/mcp-call-no-re…
he-yufeng Oct 25, 2026
9e17ca1
Merge remote-tracking branch 'origin/main' into resume/mcp-call-no-re…
he-yufeng Oct 27, 2026
31d2547
Python: test(core): narrow MCP session before await assertion
he-yufeng Oct 27, 2026
0d553af
Merge remote-tracking branch 'origin/main' into resume/mcp-call-no-re…
he-yufeng Oct 28, 2026
53f1de1
Python: fix(core): pin MCP replay eligibility to initial catalog
he-yufeng Oct 28, 2026
5b0bb51
Merge remote-tracking branch 'origin/main' into resume/mcp-call-no-re…
he-yufeng Oct 28, 2026
bc22c21
test(core): exercise MCP reconnect through active client
he-yufeng Nov 4, 2026
df44595
Merge remote-tracking branch 'upstream/main' into resume/mcp-call-no-…
he-yufeng Nov 4, 2026
b3018e4
fix(core): remove duplicate MCP annotation state updates
he-yufeng Nov 6, 2026
33f0c0f
Merge remote-tracking branch 'upstream/main' into fix/mcp-call-no-rep…
he-yufeng Nov 7, 2026
ec388cf
fix(core): bind MCP replay eligibility to dispatch identity
he-yufeng Nov 10, 2026
3e66e6a
Merge remote-tracking branch 'upstream/main' into fix/mcp-call-no-rep…
he-yufeng Nov 10, 2026
d48d8c7
chore: merge upstream main for CI baseline
he-yufeng Nov 13, 2026
f27315a
chore: merge upstream MCP result ownership changes
he-yufeng Nov 14, 2026
b663721
Python: [BREAKING] stop replaying an MCP tools/call whose response wa…
he-yufeng Nov 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/packages/core/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ The vector store API is experimental under the shared `VECTOR_STORES` feature ID
and reconnect or effective header-identity changes replace a framework-owned Client's per-Client cache. Agent
Framework does not expose shared-store or cache-mode configuration.
- **MCP Tasks extension** - The current Agent Framework MCP client does not implement the `io.modelcontextprotocol/tasks` runtime. Tools that advertise `execution.taskSupport == "required"` are skipped with a warning; optional and task-free tools continue through ordinary `tools/call`. Tasks client support is tracked in microsoft/agent-framework#9215.
- **Plain `tools/call` never replays after connection loss** - On `ClosedResourceError` / session-terminated `MCPError` the request may already have executed server-side, so `_call_tool_with_retries` dispatches once. It recovers the connection through the existing `_recover_connection_after_loss` helpers, then raises `ToolExecutionException` stating the outcome is unknown and the call was not retried, with the connection error as the inner exception, a redacted WARNING log, and the connection error type on the span. Server `ToolAnnotations` are advisory and never authorize a replay, so there is no trust or idempotency setting. A later, distinct call proceeds on the replacement connection. Caller-owned connections keep failing with their existing 'cannot be recreated' error before any of this. Read-only discovery (`tools/list`) and `get_prompt` keep their reconnect-and-retry behavior.

### File Access Harness (`_harness/_file_access.py`)

Expand Down
21 changes: 21 additions & 0 deletions python/packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,27 @@ asyncio.run(main())

You can explore additional agent samples [here](https://github.com/microsoft/agent-framework/tree/main/python/samples/02-agents).

### MCP tool calls after a lost response

**Breaking change:** a `tools/call` whose connection drops is no longer sent a second
time. The server may have executed the request before the response was lost, so
re-issuing it could run a non-idempotent operation twice. `call_tool` and tool
invocations now raise `ToolExecutionException` stating that the outcome is unknown
and the call was not retried, with the connection error as `__cause__`. Server
`idempotentHint` and `readOnlyHint` annotations are advisory and do not enable a
retry. Discovery (`tools/list`) and `get_prompt` keep their existing retry behavior.

For framework-owned connections the connection is still recovered before the
exception surfaces, so a later, different call proceeds normally. Caller-supplied
`Client` and `ClientSession` objects are never recreated and keep their existing
"caller-owned and cannot be recreated" error.

Catch `ToolExecutionException` around calls that must not run twice and reconcile the
outcome in your own code, for example by reading back the record the tool writes, or
by using a server that enforces an idempotency key. Then retry explicitly if it is
safe. This prevents the framework from duplicating an operation; it is not an
exactly-once guarantee.

### MCP HTTP client ownership and cookies

**Breaking change:** HTTP clients created by `MCPStreamableHTTPTool` no longer persist
Expand Down
132 changes: 66 additions & 66 deletions python/packages/core/agent_framework/_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3757,7 +3757,9 @@ async def call_tool(self, tool_name: str, **kwargs: Any) -> str | list[Content]:

Raises:
ToolExecutionException: If the MCP server is not connected, tools are not loaded,
or the tool call fails.
or the tool call fails. A dropped connection raises with the remote execution
outcome unknown and the connection error as the cause: the call is not retried,
because it may already have executed on the server.
"""
return await self._call_tool(tool_name, kwargs)

Expand Down Expand Up @@ -3811,78 +3813,76 @@ async def _call_tool_with_retries(
parser: Callable[..., str | list[Content]],
span: otel_trace.Span,
) -> str | list[Content]:
"""Execute the MCP tools/call RPC with retry logic."""
"""Execute the MCP tools/call RPC, recovering the connection without replaying the call."""
from anyio import ClosedResourceError
from mcp import MCPError

for attempt in range(2):
failed_connection = self._connection
close_generation = self._close_generation
span_error_recorded = False
try:
result = await self._invoke_tool(tool_name, kwargs, trace_context)
_capture_mcp_result(self, result)
if result.is_error:
parsed = parser(result)
text = (
"\n".join(c.text for c in parsed if c.type == "text" and c.text)
if isinstance(parsed, list)
else str(parsed)
)
# Per OTel MCP semconv: set error.type="tool_error" for isError results
if span.is_recording():
set_mcp_span_error(span, "tool_error", text or str(parsed))
span_error_recorded = True
raise _mcp_tool_execution_exception(text or str(parsed))
return parser(result)
except ToolExecutionException as tool_ex:
if span.is_recording() and not span_error_recorded:
set_mcp_span_error(span, type(tool_ex).__name__, str(tool_ex))
raise
except (ClosedResourceError, MCPError) as call_ex:
if not self._is_connection_loss(call_ex):
error_message = call_ex.error.message if isinstance(call_ex, MCPError) else str(call_ex)
if span.is_recording():
set_mcp_span_error(span, type(call_ex).__name__, error_message)
raise _mcp_tool_execution_exception(error_message, inner_exception=call_ex) from call_ex

if attempt == 0:
try:
await self._recover_connection_after_loss(
operation="tool call",
inner_exception=call_ex,
load_configured=True,
failed_connection=failed_connection,
close_generation=close_generation,
)
except ToolExecutionException as recovery_error:
if span.is_recording():
set_mcp_span_error(span, type(recovery_error).__name__, str(recovery_error))
raise
continue

# Second attempt also failed, give up.
_log_mcp_exception(
logging.ERROR,
call_ex,
"MCP connection closed unexpectedly after reconnection: %s",
call_ex,
redacted_message="MCP tool call connection closed after reconnection",
failed_connection = self._connection
close_generation = self._close_generation
span_error_recorded = False
try:
result = await self._invoke_tool(tool_name, kwargs, trace_context)
_capture_mcp_result(self, result)
if result.is_error:
parsed = parser(result)
text = (
"\n".join(c.text for c in parsed if c.type == "text" and c.text)
if isinstance(parsed, list)
else str(parsed)
)
# Per OTel MCP semconv: set error.type="tool_error" for isError results
if span.is_recording():
set_mcp_span_error(span, type(call_ex).__name__, str(call_ex))
raise _mcp_tool_execution_exception(
f"Failed to call tool '{tool_name}' - connection lost.",
set_mcp_span_error(span, "tool_error", text or str(parsed))
span_error_recorded = True
raise _mcp_tool_execution_exception(text or str(parsed))
return parser(result)
except ToolExecutionException as tool_ex:
if span.is_recording() and not span_error_recorded:
set_mcp_span_error(span, type(tool_ex).__name__, str(tool_ex))
raise
except (ClosedResourceError, MCPError) as call_ex:
if not self._is_connection_loss(call_ex):
error_message = call_ex.error.message if isinstance(call_ex, MCPError) else str(call_ex)
if span.is_recording():
set_mcp_span_error(span, type(call_ex).__name__, error_message)
raise _mcp_tool_execution_exception(error_message, inner_exception=call_ex) from call_ex

# The server may have executed the request before the response was lost, so the
# outcome is unknown and re-issuing it could duplicate a non-idempotent effect.
# Restore availability for the next call and leave the retry decision to the caller.
try:
await self._recover_connection_after_loss(
operation="tool call",
inner_exception=call_ex,
) from call_ex
except Exception as ex:
load_configured=True,
failed_connection=failed_connection,
close_generation=close_generation,
)
except ToolExecutionException as recovery_error:
if span.is_recording():
set_mcp_span_error(span, type(ex).__name__, str(ex))
raise _mcp_tool_execution_exception(f"Failed to call tool '{tool_name}'.", inner_exception=ex) from ex
retries_exhausted = _mcp_tool_execution_exception(f"Failed to call tool '{tool_name}' after retries.")
if span.is_recording():
set_mcp_span_error(span, type(retries_exhausted).__name__, str(retries_exhausted))
raise retries_exhausted
set_mcp_span_error(span, type(recovery_error).__name__, str(recovery_error))
raise
if span.is_recording():
set_mcp_span_error(span, type(call_ex).__name__, str(call_ex))
_log_mcp_exception(
logging.WARNING,
call_ex,
"MCP tool call %r lost its response and was not retried: %s",
tool_name,
call_ex,
redacted_message="MCP tool call outcome is unknown after connection loss; the call was not retried",
)
raise _mcp_tool_execution_exception(
f"Failed to call tool '{tool_name}' - connection lost and the remote execution "
"outcome is unknown. The call was not retried because it may already have "
"executed on the server. The connection was re-established, so a later call "
"can proceed; reconcile the outcome before retrying this one.",
inner_exception=call_ex,
) from call_ex
except Exception as ex:
if span.is_recording():
set_mcp_span_error(span, type(ex).__name__, str(ex))
raise _mcp_tool_execution_exception(f"Failed to call tool '{tool_name}'.", inner_exception=ex) from ex

def _resolved_extra_args(self, tool_name: str) -> set[str]:
"""Return the user-configured extra argument names allowed for a tool."""
Expand Down
Loading
Loading