Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions python/packages/core/agent_framework/_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,12 +1076,17 @@ async def call_tool(self, tool_name: str, **kwargs: Any) -> str | list[Content]:
raise ToolExecutionException(
"Tools are not loaded for this server, please set load_tools=True in the constructor."
)
# Extract user-supplied _meta before filtering so it is forwarded as
# MCP request metadata rather than as a tool argument.
user_meta = kwargs.pop("_meta", None)

# Filter out framework kwargs that cannot be serialized by the MCP SDK.
# These are internal objects passed through the function invocation pipeline
# that should not be forwarded to external MCP servers.
# conversation_id is an internal tracking ID used by services like Azure AI.
# options contains metadata/store used by AG-UI for Azure AI client requirements.
# response_format is a Pydantic model class used for structured output (not serializable).
# _meta is handled separately and merged into the MCP request meta field.
filtered_kwargs = {
k: v
for k, v in kwargs.items()
Expand All @@ -1095,11 +1100,13 @@ async def call_tool(self, tool_name: str, **kwargs: Any) -> str | list[Content]:
"conversation_id",
"options",
"response_format",
"_meta",
}
}

# Inject OpenTelemetry trace context into MCP _meta for distributed tracing.
otel_meta = _inject_otel_into_mcp_meta()
# Merge user-supplied _meta with OpenTelemetry trace context.
# User keys take precedence; OTel keys fill in non-conflicting slots.
otel_meta = _inject_otel_into_mcp_meta(dict(user_meta) if user_meta else None)

parser = self.parse_tool_results or self._parse_tool_result_from_mcp
# Try the operation, reconnecting once if the connection is closed
Expand Down
Loading
Loading