René's URL Explorer Experiment


Title: Pass entire request object to handlers; add raw request to MCP base Request · Issue #195 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Pass entire request object to handlers; add raw request to MCP base Request · Issue #195 · modelcontextprotocol/python-sdk

X Title: Pass entire request object to handlers; add raw request to MCP base Request · Issue #195 · modelcontextprotocol/python-sdk

Description: Is your feature request related to a problem? Please describe. I have an MCP server that sits in front of my API to allow LLMs to interact with it. My API requires an authorization header. I have hacked a way to do this in my fork, but e...

Open Graph Description: Is your feature request related to a problem? Please describe. I have an MCP server that sits in front of my API to allow LLMs to interact with it. My API requires an authorization header. I have h...

X Description: Is your feature request related to a problem? Please describe. I have an MCP server that sits in front of my API to allow LLMs to interact with it. My API requires an authorization header. I have h...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Pass entire request object to handlers; add raw request to MCP base Request","articleBody":"**Is your feature request related to a problem? Please describe.**\nI have an MCP server that sits in front of my API to allow LLMs to interact with it. My API requires an authorization header.\n\nI have hacked a way to do this in my fork, but essentially the MCP client is able to pass through headers. Only need to use this for the `/sse` request. Currently, the handlers extract the arguments they need in the decorator. We could instead add a field to the base Request class called `raw_request` or `headers` if we just need that and then ensure this is added to the request object before passing it to the handler.\n\n**Describe the solution you'd like**\n```python\n# src/mcp/types.py\nclass Request(BaseModel, Generic[RequestParamsT, MethodT]):\n    \"\"\"Base class for JSON-RPC requests.\"\"\"\n\n    method: MethodT\n    params: RequestParamsT\n    headers: dict[str, Any] | None = None # \u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\n    model_config = ConfigDict(extra=\"allow\")\n\n---------------------\n# src/mcp/server/fastmcp/server.py\n    def call_tool(self):\n        def decorator(\n            func: Callable[\n                ...,\n                Awaitable[\n                    Sequence[\n                        types.TextContent | types.ImageContent | types.EmbeddedResource\n                    ]\n                ],\n            ],\n        ):\n            logger.debug(\"Registering handler for CallToolRequest\")\n\n            async def handler(req: types.CallToolRequest):\n                try:\n                    results = await func(req)  # \u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\n                    return types.ServerResult(\n                        types.CallToolResult(content=list(results), isError=False)\n                    )\n                except Exception as e:\n                    return types.ServerResult(\n                        types.CallToolResult(\n                            content=[types.TextContent(type=\"text\", text=str(e))],\n                            isError=True,\n                        )\n                    )\n\n            self.request_handlers[types.CallToolRequest] = handler\n            return func\n\n        return decorator\n\n-----------------------------\n# src/mcp/server/fastmcp/server.py\n    async def run_sse_async(self, middleware: list[type] = []) -\u003e None:\n        \"\"\"Run the server using SSE transport.\"\"\"\n        from starlette.applications import Starlette\n        from starlette.routing import Mount, Route\n\n        sse = SseServerTransport(\"/messages/\")\n\n        async def handle_sse(request):\n            async with sse.connect_sse(\n                request.scope, request.receive, request._send\n            ) as streams:\n                await self._mcp_server.run(\n                    streams[0],\n                    streams[1],\n                    self._mcp_server.create_initialization_options(),\n                    raw_request=request, # \u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\n                )\n\n        starlette_app = Starlette(\n            debug=self.settings.debug,\n            routes=[\n                Route(\"/sse\", endpoint=handle_sse),\n                Mount(\"/messages/\", app=sse.handle_post_message),\n            ],\n        )\n\n        config = uvicorn.Config(\n            starlette_app,\n            host=self.settings.host,\n            port=self.settings.port,\n            log_level=self.settings.log_level.lower(),\n        )\n        server = uvicorn.Server(config)\n        await server.serve()\n\n---------------------------\n# src/mcp/server/lowlevel/server.py\n    async def run(\n        self,\n        read_stream: MemoryObjectReceiveStream[types.JSONRPCMessage | Exception],\n        write_stream: MemoryObjectSendStream[types.JSONRPCMessage],\n        initialization_options: InitializationOptions,\n        raw_request: Any | None = None, # \u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\n        # When False, exceptions are returned as messages to the client.\n        # When True, exceptions are raised, which will cause the server to shut down\n        # but also make tracing exceptions much easier during testing and when using\n        # in-process servers.\n        raise_exceptions: bool = False,\n    ):\n        with warnings.catch_warnings(record=True) as w:\n            async with ServerSession(\n                read_stream, write_stream, initialization_options\n            ) as session:\n                async for message in session.incoming_messages:\n                    logger.debug(f\"Received message: {message}\")\n\n                    match message:\n                        case (\n                            RequestResponder(\n                                request=types.ClientRequest(root=req)\n                            ) as responder\n                        ):\n                            with responder:\n                                if raw_request is not None:\n                                    req.headers = raw_request.headers # \u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\n                                await self._handle_request(\n                                    message, req, session, raise_exceptions\n                                )\n                        case types.ClientNotification(root=notify):\n                            await self._handle_notification(notify)\n\n                    for warning in w:\n                        logger.info(\n                            f\"Warning: {warning.category.__name__}: {warning.message}\"\n                        )\n```\n\nand then use this like:\n\n```python\n# already supported on client\ntransport = await exit_stack.enter_async_context(\n    sse_client(url, headers={\"authorization\": \"...\"})\n)\n```\n\n```python\n# on server\nmcp_server = FastMCP(\"example\", transport=\"sse\")\n\nasync def handle_call_tool(\n    self: FastMCP, req: types.CallToolRequest # \u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\n) -\u003e Sequence[types.TextContent | types.ImageContent | types.EmbeddedResource]:\n    headers = {}\n    if \"authorization\" in req.headers:\n        headers = {\"Authorization\": req.headers[\"authorization\"]}\n    # ...http client call to api or if MCP is served from the app itself, check the key\n```\n\nI know auth is a part of the 2025 H1 roadmap so this may be usurped already in terms of how things will be supported. This goes beyond auth headers though since it could be useful to have access to the raw request in total instead within the tool execution context.","author":{"url":"https://github.com/mconflitti-pbc","@type":"Person","name":"mconflitti-pbc"},"datePublished":"2025-02-07T18:37:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/195/python-sdk/issues/195"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f38067ec-5c9c-f4eb-ef7c-a3e86ee60c0c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCE60:168706:1442CC9:1CF774C:6A5A228B
html-safe-nonce1fb0457952a80bc70ddcca470426fc437da951ffbdd02ba61573a40c7a967206
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTYwOjE2ODcwNjoxNDQyQ0M5OjFDRjc3NEM6NkE1QTIyOEIiLCJ2aXNpdG9yX2lkIjoiMTYxMzA5NjMzNjk4Mjk0MjM0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac3febbc334f31f98d60f7b275eb520a370c5b3488db8cd3aa58c79ecf39787f47
hovercard-subject-tagissue:2838832293
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/195/issue_layout
twitter:imagehttps://opengraph.githubassets.com/2d61cbcdbfdb0f06f53eda6d503b3cedf541b2f934123f068759d555b07d8015/modelcontextprotocol/python-sdk/issues/195
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/2d61cbcdbfdb0f06f53eda6d503b3cedf541b2f934123f068759d555b07d8015/modelcontextprotocol/python-sdk/issues/195
og:image:altIs your feature request related to a problem? Please describe. I have an MCP server that sits in front of my API to allow LLMs to interact with it. My API requires an authorization header. I have h...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemconflitti-pbc
hostnamegithub.com
expected-hostnamegithub.com
Nonee31742e80bbd077fd5679c13ed870ce4e0c13803a2fa5beaae557b6769de2c8a
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
releasec9fcdbf98c619d1561ed843fa01d9766a32b5cd9
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/195#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F195
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F195
Sign up https://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/195
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/195
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/195
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/issues/195
modelcontextprotocol https://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Notifications https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Fork 3.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Star 23.6k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Code https://github.com/modelcontextprotocol/python-sdk
Issues 255 https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests 303 https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality 6 https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Code https://github.com/modelcontextprotocol/python-sdk
Issues https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Pass entire request object to handlers; add raw request to MCP base Requesthttps://github.com/modelcontextprotocol/python-sdk/issues/195#top
enhancementRequest for a new feature that's not currently supportedhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22enhancement%22
https://github.com/mconflitti-pbc
mconflitti-pbchttps://github.com/mconflitti-pbc
on Feb 7, 2025https://github.com/modelcontextprotocol/python-sdk/issues/195#issue-2838832293
enhancementRequest for a new feature that's not currently supportedhttps://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

Viewport: width=device-width


URLs of crawlers that visited me.