Hello, I have enabled the mcp instrument in my agent and I can see it getting registered. When my mcp client calls the tool_call I can see the flow going inside the mcp instrument but there seems to be some pydanticserializationunexpectedvalue(expected initialize request serialized value listtoolrequest) Anyone facing similar issues??
This issue is not directly documented in the provided data sources, but similar MCP tracing and serialization issues have been discussed. The MCP instrumentor for Python (openinference-instrumentation-mcp) is responsible for context propagation and does not generate its own telemetry; it relies on other instrumentors for span creation. Serialization errors involving Pydantic (such as "unexpected value" or mismatched request types) are often due to version mismatches or incompatibilities between the MCP client/server, the instrumentor, and Pydantic itself. Specifically, Phoenix and its instrumentors have known compatibility issues with certain Pydantic versions, and errors like "expected initialize request serialized value listtoolrequest" may indicate a mismatch in expected message formats or schema definitions between client and server components (reference, reference).To resolve, ensure all related packages (mcp, openinference-instrumentation-mcp, pydantic, and Phoenix) are on compatible versions—preferably the latest, or as specified in the MCP tracing tutorial. Also, check that the client and server are using the same transport and message schema. If the problem persists, provide the full stack trace and versions for more targeted help.Would you like more detail or a step-by-step troubleshooting guide?Sources:
- Phoenix issue: Python SDK broken with pydantic<2.6
- Phoenix issue: pydantic 2.4.1–2.7.1 incompatibility
- MCP tracing tutorial
💡 Hint: Mention RunLLM in the thread for followups.
StackTrace :
UserWarning: Pydantic serializer warnings:
PydanticSerializationUnexpectedValue(Expected `PingRequest` - serialized value may not be as expected [input_value=ListToolsRequest(method='...-498c5b942be44b9f-01'))), input_type=ListToolsRequest])
PydanticSerializationUnexpectedValue(Expected `InitializeRequest` - serialized value may not be as expected [input_value=ListToolsRequest(method='...-498c5b942be44b9f-01'))), input_type=ListToolsRequest])
PydanticSerializationUnexpectedValue(Expected `CompleteRequest` - serialized value may not be as expected [input_value=ListToolsRequest(method='...-498c5b942be44b9f-01'))), input_type=ListToolsRequest])async def execute_mcp_tool(self, request,tool_to_call): with tracer.start_as_current_span( name=f"Tool - {tool_to_call.name}", attributes={ SpanAttributes.OPENINFERENCE_SPAN_KIND: OpenInferenceSpanKindValues.TOOL.value, SpanAttributes.TOOL_NAME: tool_to_call.name, SpanAttributes.TOOL_DESCRIPTION: tool_to_call.description, SpanAttributes.TOOL_PARAMETERS: tool_call.model_dump().get('function').get('arguments'), ToolAttributes.TOOL_JSON_SCHEMA: '' }, ) as tool_span: metadata = self.metadata response = None try: async with self.mcp.client as client: request = json.loads(request) request['input']['metadata'] = metadata response = await client.call_tool(tool_to_call.name, request) except Exception as e: print(e) print(f'Exception occurred while executing tool:{tool_to_call.name}, {Exception}') if response.content and len(response.content) > 0: content = response.content[0].text if hasattr(response.content[0], 'text') else str( response.content[0]) else: content = None tool_span.set_attributes({ SpanAttributes.OUTPUT_VALUE: content, SpanAttributes.OUTPUT_MIME_TYPE: "application/json" })
return contentoccurs for all the tools
tool input argument:
class input(BaseModel):
metadata: ToolMetadataObject
name: str
query: QueryObjectWorked like a charm Thanks a lot
