René's URL Explorer Experiment


Title: Client: expose an outbound request seam (the send_raw_request TODO) so observers can see a request before it is written · Issue #3715 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Client: expose an outbound request seam (the send_raw_request TODO) so observers can see a request before it is written · Issue #3715 · modelcontextprotocol/python-sdk

X Title: Client: expose an outbound request seam (the send_raw_request TODO) so observers can see a request before it is written · Issue #3715 · modelcontextprotocol/python-sdk

Description: Summary There is no supported way for code outside the SDK to observe or wrap an outgoing client request at the point where it is built and written. The dispatcher already says as much in a TODO: # mcp/shared/jsonrpc_dispatcher.py, JSONR...

Open Graph Description: Summary There is no supported way for code outside the SDK to observe or wrap an outgoing client request at the point where it is built and written. The dispatcher already says as much in a TODO: #...

X Description: Summary There is no supported way for code outside the SDK to observe or wrap an outgoing client request at the point where it is built and written. The dispatcher already says as much in a TODO: #...

Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3715

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.112.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Client: expose an outbound request seam (the send_raw_request TODO) so observers can see a request before it is written","articleBody":"### Summary\n\nThere is no supported way for code outside the SDK to observe or wrap an outgoing client request at the point where it is built and written. The dispatcher already says as much in a TODO:\n\n```python\n# mcp/shared/jsonrpc_dispatcher.py, JSONRPCDispatcher.send_raw_request\n# TODO(maxisbey): move the otel span + inject into an outbound\n# middleware once that seam exists; the dispatcher should not own otel.\nwith otel_span(span_name, kind=SpanKind.CLIENT, ...):\n    inject_trace_context(out_meta)\n    msg = JSONRPCRequest(jsonrpc=\"2.0\", id=request_id, method=method, params=out_params)\n    ...\n    await self._write(msg, plan.metadata)\n```\n\nThis issue asks for that seam on the client side, as the counterpart of the existing lowlevel `Server.middleware`. It is related to #1233 (middleware support), which so far discusses the server side only.\n\nVersion checked: `mcp` 2.2.0.\n\n### Use case\n\nInstrumentation and policy tooling that needs to act on a `tools/call` **before** it leaves the process, for example:\n\n- emitting a \"tool call started\" event with the tool name and arguments to an observability pipeline or a policy engine, so a decision can be made while the request is still local;\n- attaching or rewriting `_meta` (correlation ids, session ids) in addition to the trace context;\n- refusing a request locally.\n\nThe event has to be tied to the same trace context that goes on the wire, so it must be emitted from inside the span the dispatcher opens (`MCP send tools/call \u003ctool>`), where `inject_trace_context` runs. That is the only place where the method, the tool name, the arguments and the outgoing `traceparent` are all known together.\n\n### What we do today, and why it is fragile\n\nBecause there is no seam, the only option is to wrap the module-level function `mcp.shared.jsonrpc_dispatcher.inject_trace_context`, which is called inside that span, and use it as the \"request is about to be written\" signal. That depends on:\n\n- a private import name in `jsonrpc_dispatcher` (a rename or a move into `_otel` only would silently stop it working);\n- `inject_trace_context` being called exactly once per request, inside the span, before the write;\n- the arguments being passed through a side channel (a contextvar set by a wrapper around `ClientSession.send_request`), because the hook only receives the `_meta` dict.\n\nWrapping `ClientSession.send_request` instead does not work for this purpose: it runs outside the dispatcher's span, so anything emitted there carries a different span id than the `traceparent` that is sent.\n\n### Proposal\n\nSomething minimal and symmetrical to the server middleware, for example a keyword-only `middleware` on the client session/dispatcher, called once per outgoing request with an object exposing at least:\n\n- `method`, `params` (read-only view of what will be sent) and a mutable `meta` (the `_meta` that will be sent);\n- a way to call the next stage.\n\nand run **inside** the OpenTelemetry span, so that observers see the same span context that `inject_trace_context` uses. The built-in OTel injection could then become the first middleware, which resolves the TODO.\n\nOpen questions:\n\n1. Is this the seam you had in mind in the TODO, or is something different planned for the client?\n2. Should it also cover notifications, or requests only?\n3. Position relative to the OTel span: inside it (needed for the use case above), or outside it?\n4. Would you prefer this as part of #1233, or as a separate piece of work?\n\n### Alternatives considered\n\n- Wrapping `inject_trace_context` (what we do now): works, but depends on private structure as above.\n- Wrapping `ClientSession.send_request`: wrong span, see above.\n- Using the HTTP client hooks (httpx event hooks): they see the already-encoded HTTP request, not the method and arguments, and only exist on HTTP transports, not stdio.\n\nHappy to help with a PR if the shape is agreed.\n\n---\n\nI would like to fix this myself once the shape is agreed (and a maintainer is fine with that). AI disclosure: this issue was drafted with AI assistance (Claude Code); I reviewed the text and checked the quoted code against `mcp` 2.2.0.\n","author":{"url":"https://github.com/rafaelsilva29","@type":"Person","name":"rafaelsilva29"},"datePublished":"2026-10-15T13:13:34Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3715"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d2549c22-7c47-cfd1-0e94-769ab80c8eb5
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA2F8:1B13E8:2DBA41E:3BE62B6:6B056B95
html-safe-nonce53ba0ca25d5c39ff1e3ec05ec4b6ecd2b8c57b1af17e1a3618422de113c15d2a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMkY4OjFCMTNFODoyREJBNDFFOjNCRTYyQjY6NkIwNTZCOTUiLCJ2aXNpdG9yX2lkIjoiNzI3MTg1NzgyNjk5MjMxOTM4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac58983899306c5ff1b47892fc5400015e54eb17827ab94f6c853e61432ef2d0a9
hovercard-subject-tagissue:5866812174
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/3715/issue_layout
twitter:imagehttps://opengraph.githubassets.com/297ec7f1a410c1a6c29b5ad44c688476e16a9ce3728a8e49c0c32a4f1f3fc745/modelcontextprotocol/python-sdk/issues/3715
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/297ec7f1a410c1a6c29b5ad44c688476e16a9ce3728a8e49c0c32a4f1f3fc745/modelcontextprotocol/python-sdk/issues/3715
og:image:altSummary There is no supported way for code outside the SDK to observe or wrap an outgoing client request at the point where it is built and written. The dispatcher already says as much in a TODO: #...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerafaelsilva29
hostnamegithub.com
expected-hostnamegithub.com
None9b4256ac5f3e310e7945ef5b71c9cb9e264357b1eb20e91d369ed6502a4c486c
turbo-cache-controlno-preview
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef089e689ad324655ac44bf6cdbc04d976105b374
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/3715#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F3715
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F3715
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3715
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3715
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3715
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues320 (320)https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests112 (112)https://github.com/modelcontextprotocol/python-sdk/pulls
Actionshttps://github.com/modelcontextprotocol/python-sdk/actions
Projectshttps://github.com/modelcontextprotocol/python-sdk/projects
Security and quality12 (12)https://github.com/modelcontextprotocol/python-sdk/security
Insightshttps://github.com/modelcontextprotocol/python-sdk/insights
https://github.com/modelcontextprotocol/python-sdk
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3715
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3715
Client: expose an outbound request seam (the send_raw_request TODO) so observers can see a request before it is writtenhttps://github.com/modelcontextprotocol/python-sdk/issues/3715#top
enhancementhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22enhancement%22
https://github.com/rafaelsilva29
rafaelsilva29https://github.com/rafaelsilva29
on Oct 15, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3715#issue-5866812174
#1233https://github.com/modelcontextprotocol/python-sdk/issues/1233
Middleware Support in MCP #1233https://github.com/modelcontextprotocol/python-sdk/issues/1233
claudehttps://github.com/apps/claude
enhancementhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22enhancement%22
on Oct 15, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3715#event-33338325845
https://github.com/Ben-Home
Ben-Homehttps://github.com/Ben-Home
on Oct 16, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3715#issuecomment-6218463844
https://github.com/sattyamjjain
sattyamjjainhttps://github.com/sattyamjjain
on Oct 17, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3715#issuecomment-6231213703
https://github.com/rafaelsilva29
rafaelsilva29https://github.com/rafaelsilva29
on Oct 20, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3715#issuecomment-6288945518
@sattyamjjainhttps://github.com/sattyamjjain
agntcy/observe#143https://github.com/agntcy/observe/pull/143
https://github.com/MarouaBoud
MarouaBoudhttps://github.com/MarouaBoud
on Oct 24, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3715#issuecomment-6386747023
https://github.com/MarouaBoud
MarouaBoudhttps://github.com/MarouaBoud
on Oct 24, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3715#issuecomment-6387122868
https://github.com/rafaelsilva29
rafaelsilva29https://github.com/rafaelsilva29
on Oct 26, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3715#issuecomment-6418507734
@MarouaBoudhttps://github.com/MarouaBoud
rafaelsilva29/python-sdk, branch feat/client-outbound-request-hookshttps://github.com/rafaelsilva29/python-sdk/tree/feat/client-outbound-request-hooks
Sign up for freehttps://github.com/signup?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3715
Sign in to commenthttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3715
enhancementhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22enhancement%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.