Skip to content

Conversation

@anuraaga
Copy link
Contributor

@anuraaga anuraaga commented Apr 25, 2025

This is the same as #1555 for Python. There is some more effort here because of the message passing model used causing context breaks within the SDK between transport and handler. While we could continue to instrument at the higher level than handler, I thought it's still better to keep as similar between the languages as possible and instead instrumented the message passing itself as well for in-process context propagation.

I also went ahead and bumped the supported version because there were significant changes to how client message handling is done

https://github.com/modelcontextprotocol/python-sdk/releases/tag/v1.6.0

It seemed simpler to raise the target since this is new instrumentation, though targeting both admittedly has a much larger impact on the tests than the instrumentation itself.

/cc @codefromthecrypt

@anuraaga anuraaga requested a review from a team as a code owner April 25, 2025 04:00
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 25, 2025
Copy link
Contributor

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for keeping the code coherent across languages

Comment on lines +47 to +53
# While we prefer to instrument the lowest level primitive, the transports above, it doesn't
# mean context will be propagated to handlers automatically. Notably, the MCP SDK passes
# server messages to a handler with a separate stream in between, losing context. We go
# ahead and instrument this second stream just to propagate context so transports can still
# be used independently while also supporting the major usage of the MCP SDK. Notably, this
# may be a reasonable generic instrumentation for anyio itself to allow its streams to
# propagate context broadly.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the explanation here.

@mikeldking mikeldking merged commit 2ef9208 into Arize-ai:main Apr 25, 2025
9 checks passed
@github-actions github-actions bot mentioned this pull request Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants