Skip to content

Handle MCP request metadata being a dict - #1360

Merged
alexmojaki merged 2 commits into
mainfrom
alex/mcp-fix
Sep 1, 2025
Merged

alexmojaki merged 2 commits into
mainfrom
alex/mcp-fix

Conversation

@alexmojaki

Copy link
Copy Markdown
Contributor

Closes #1359

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: c5deb69
Status: ✅  Deploy successful!
Preview URL: https://6b2b7653.logfire-docs.pages.dev
Branch Preview URL: https://alex-mcp-fix.logfire-docs.pages.dev

View logs

@alexmojaki alexmojaki changed the title Alex/mcp fix Handle MCP request metadata being a dict Sep 1, 2025
@alexmojaki
alexmojaki marked this pull request as ready for review September 1, 2025 11:56
@alexmojaki
alexmojaki requested a review from Copilot September 1, 2025 11:56

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 pull request addresses issue #1359 by handling cases where MCP request metadata can be either a dict or a structured object. The fix ensures that the MCP integration correctly processes metadata regardless of its format, preventing potential errors when extracting tracing context from request parameters.

  • Modified MCP integration to handle both dict and object types for request metadata
  • Added comprehensive test coverage for both metadata formats
  • Simplified test setup by removing unnecessary warning handling and refactored server initialization

Reviewed Changes

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

File Description
logfire/_internal/integrations/mcp.py Added type checking to handle metadata as either dict or structured object
tests/otel_integrations/test_openai_agents_mcp.py Added test cases for both dict and object metadata formats, simplified test setup

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread logfire/_internal/integrations/mcp.py Resolved
@alexmojaki
alexmojaki merged commit ff624e4 into main Sep 1, 2025
@alexmojaki
alexmojaki deleted the alex/mcp-fix branch September 1, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: 'dict' object has no attribute 'model_dump' when using logfire.instrument_mcp

2 participants