Skip to content

logfire.instrument_mcp #947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 2 tasks
samuelcolvin opened this issue Mar 23, 2025 · 1 comment · Fixed by #966
Closed
1 of 2 tasks

logfire.instrument_mcp #947

samuelcolvin opened this issue Mar 23, 2025 · 1 comment · Fixed by #966
Assignees

Comments

@samuelcolvin
Copy link
Member

samuelcolvin commented Mar 23, 2025

Description

Idea is to instrument:

  • client messages
  • SSE messages from the server
  • record logs as individual zero-duration spans? at least on the client

Needs:

Also needs POST messages to be shown with the right trace/parent span.

E.g. if I run the following I see:

from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerHTTP

import logfire

logfire.configure()
logfire.instrument_httpx()
logfire.instrument_pydantic_ai()

server = MCPServerHTTP(url='http://localhost:3001/sse')
agent = Agent('openai:gpt-4o', mcp_servers=[server])


async def main():
    async with agent.run_mcp_servers():
        result = await agent.run('How many days between 2000-01-01 and 2025-03-18?')
    print(result.data)
    #> There are 9,208 days between January 1, 2000, and March 18, 2025.


if __name__ == '__main__':
    import asyncio

    asyncio.run(main())

I see:

Image

All those posts to localhost/messages should be within the agent run trace

@Kludex
Copy link
Member

Kludex commented Mar 23, 2025

I think using instrument_starlette should already give something for SSE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants