René's URL Explorer Experiment


Title: Clarify JSON-RPC error code for 'session not found' responses · Issue #1821 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Clarify JSON-RPC error code for 'session not found' responses · Issue #1821 · modelcontextprotocol/python-sdk

X Title: Clarify JSON-RPC error code for 'session not found' responses · Issue #1821 · modelcontextprotocol/python-sdk

Description: Summary The Python SDK and TypeScript SDK use different JSON-RPC error codes for "session not found" responses (HTTP 404). The MCP specification does not define which error code to use, and there are deeper questions about whether MCP sh...

Open Graph Description: Summary The Python SDK and TypeScript SDK use different JSON-RPC error codes for "session not found" responses (HTTP 404). The MCP specification does not define which error code to use, and there a...

X Description: Summary The Python SDK and TypeScript SDK use different JSON-RPC error codes for "session not found" responses (HTTP 404). The MCP specification does not define which error code to use, a...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Clarify JSON-RPC error code for 'session not found' responses","articleBody":"## Summary\n\nThe Python SDK and TypeScript SDK use **different JSON-RPC error codes** for \"session not found\" responses (HTTP 404). The MCP specification does not define which error code to use, and there are deeper questions about whether MCP should be using certain error code ranges at all.\n\nThis issue tracks the need for spec clarification and subsequent SDK alignment.\n\n---\n\n## Current State\n\n### What the Spec Says\n\nThe [Streamable HTTP transport spec](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management) defines the HTTP status code but not the JSON-RPC error code:\n\n\u003e The server **MAY** terminate the session at any time, after which it **MUST** respond to requests containing that session ID with **HTTP 404 Not Found**.\n\nThe spec is silent on what JSON-RPC error code (if any) should be in the response body.\n\n### SDK Implementations\n\n| SDK | HTTP Status | JSON-RPC Error Code | `id` Field |\n|-----|-------------|---------------------|------------|\n| **TypeScript** | 404 | `-32001` | `null` |\n| **Python** | 404 | `-32600` (INVALID_REQUEST) | `\"server-error\"` |\n\n**TypeScript SDK** (`packages/server/src/server/streamableHttp.ts`, [`validateSession` method](https://github.com/modelcontextprotocol/typescript-sdk/blob/b0ef89ffaf6db8b3c52cd8919e8949b0f1da9ca4/packages/server/src/server/streamableHttp.ts#L829)):\n```typescript\nif (sessionId !== this.sessionId) {\n    // Reject requests with invalid session ID with 404 Not Found\n    return this.createJsonErrorResponse(404, -32_001, 'Session not found');\n}\n```\n\nWhere `createJsonErrorResponse` always sets `id: null`.\n\n**Python SDK** (`src/mcp/server/streamable_http_manager.py`, [lines 244-250](https://github.com/modelcontextprotocol/python-sdk/blob/b38716e/src/mcp/server/streamable_http_manager.py#L244-L250)):\n```python\n# Unknown or expired session ID - return 404 per MCP spec\n# TODO: Align error code once spec clarifies\n# See: https://github.com/modelcontextprotocol/python-sdk/issues/1821\nerror_response = JSONRPCError(\n    jsonrpc=\"2.0\",\n    id=\"server-error\",\n    error=ErrorData(\n        code=INVALID_REQUEST,  # -32600\n        message=\"Session not found\",\n    ),\n)\n```\n\n### The `id` Field Problem\n\nIn addition to the error code divergence, the Python SDK uses `id: \"server-error\"` which appears to violate the [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification):\n\n\u003e If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request), it **MUST** be Null.\n\nWhen rejecting a request at the session/transport level (before parsing individual JSON-RPC messages), the server cannot determine a request `id`. Per the spec, `id` MUST be `null` in this case. The TypeScript SDK correctly uses `null`.\n\n---\n\n## The Deeper Problem\n\n### JSON-RPC Error Code Ranges\n\nPer the [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification):\n\n| Range | Reserved For |\n|-------|--------------|\n| -32700 to -32600 | Standard JSON-RPC errors (Parse error, Invalid Request, etc.) |\n| -32000 to -32099 | **Implementation-defined server errors** (i.e., JSON-RPC library implementations) |\n| Everything else | Application-defined errors |\n\n### The Issue with MCP's Error Codes\n\n[Spec Issue #509](https://github.com/modelcontextprotocol/modelcontextprotocol/issues/509) points out that MCP incorrectly uses error codes in the `-32000` to `-32099` range. This range is reserved for **JSON-RPC library implementations**, not applications like MCP. Since MCP is an application built on top of JSON-RPC, it should use codes **outside** this reserved range.\n\nHowever, both SDKs already use this range:\n- TypeScript: `-32000` (ConnectionClosed), `-32001` (RequestTimeout / Session not found)\n- Python: `-32000` (CONNECTION_CLOSED), `-32042` (URL_ELICITATION_REQUIRED)\n\n### Current Error Codes in Schema (2025-11-25)\n\nThe MCP schema only defines these error codes:\n```typescript\n// Standard JSON-RPC (correct usage)\nexport const PARSE_ERROR = -32700;\nexport const INVALID_REQUEST = -32600;\nexport const METHOD_NOT_FOUND = -32601;\nexport const INVALID_PARAMS = -32602;\nexport const INTERNAL_ERROR = -32603;\n\n// MCP-specific (in the problematic reserved range)\nexport const URL_ELICITATION_REQUIRED = -32042;\n```\n\nNo error code is defined for \"session not found\".\n\nNote: The draft schema (via merged [PR #2038](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2038)) now adds typed interfaces (`ParseError`, `InvalidRequestError`, `MethodNotFoundError`, `InvalidParamsError`, `InternalError`) with doc comments for each standard error code, but does not add any new MCP-specific error codes.\n\n---\n\n## Related Issues and PRs\n\n### MCP Spec Repo\n| Issue/PR | Title | Status |\n|----------|-------|--------|\n| [#509](https://github.com/modelcontextprotocol/modelcontextprotocol/issues/509) | spec defines improper error codes | Open |\n| [#1545](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/1545) | Change invalid resource URI error code from -32002 to -32602 | Open |\n| [#2164](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2164) | SEP-2164: Standardize resource not found error code (-32602) | Open |\n| [#1549](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/1549) | Make schema.ts source of truth for error codes | Closed (superseded by [#2038](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2038), merged) |\n| [#2038](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2038) | Upgrade Schema Reference page (typed error interfaces) | Merged |\n| [#1398](https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1398) | Streamable HTTP: clarification for error cases | Open |\n| [#1442](https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1442) | SEP: Make MCP Stateless (proposes `-32001` for session errors) | Open |\n\n### Python SDK\n| Issue/PR | Title | Status |\n|----------|-------|--------|\n| [#1727](https://github.com/modelcontextprotocol/python-sdk/issues/1727) | StreamableHTTPSessionManager returns 400 instead of 404 | Closed (fixed by #1808) |\n| [#1808](https://github.com/modelcontextprotocol/python-sdk/pull/1808) | fix: return HTTP 404 for unknown session IDs | Merged |\n\n### TypeScript SDK\n| Issue/PR | Title | Status |\n|----------|-------|--------|\n| [#389](https://github.com/modelcontextprotocol/typescript-sdk/issues/389) | Examples use incorrect status for invalid session IDs | Open |\n| [#85](https://github.com/modelcontextprotocol/typescript-sdk/issues/85) | SDK errors should use -32000 to -32099 | Closed |\n\n---\n\n## Questions for Spec Clarification\n\n1. **What JSON-RPC error code should be used for \"session not found\"?**\n   - TypeScript uses `-32001`\n   - Python uses `-32600` (INVALID_REQUEST)\n   - SEP-1442 proposes `-32001`\n\n2. **Should MCP define a dedicated error code for session errors?**\n   - If so, should it be in the `-32000` to `-32099` range (current practice) or outside it (per JSON-RPC spec)?\n\n3. **What should the `id` field be in the error response?**\n   - TypeScript uses `null` (correct per JSON-RPC 2.0 spec)\n   - Python uses `\"server-error\"` (likely a violation — see \"The `id` Field Problem\" above)\n   - JSON-RPC spec says `null` when request ID is unknown\n\n---\n\n## Action Items\n\n1. **Spec team**: Clarify the expected JSON-RPC error code for session-related errors in the transport spec or schema\n2. **SDK teams**: Align implementations once spec guidance is provided\n3. **This SDK**: Fix `id` field to use `null` instead of `\"server-error\"`, and update error code once spec guidance is provided\n\n---\n\n## References\n\n- [JSON-RPC 2.0 Specification](https://www.jsonrpc.org/specification)\n- [MCP Streamable HTTP Transport Spec](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management)\n- [MCP Schema (2025-11-25)](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2025-11-25/schema.ts)\n","author":{"url":"https://github.com/maxisbey","@type":"Person","name":"maxisbey"},"datePublished":"2025-12-31T13:47:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1821/python-sdk/issues/1821"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:44feb0be-bb17-7629-cf19-b2ec1753ee4f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB48C:356ACF:4869E2D:6643C6E:6A56F3E6
html-safe-noncecd99439ee7aea1ab194b185253199fee5bd50d24f4051254af99db186ecf2d97
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNDhDOjM1NkFDRjo0ODY5RTJEOjY2NDNDNkU6NkE1NkYzRTYiLCJ2aXNpdG9yX2lkIjoiMjU2NjQ4NzM4MzQzNzkzMTQ5NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaccfd8486125d8ad6e7defe4eb1372f70923c57caf9d873252af3e284e05e4122f
hovercard-subject-tagissue:3772865875
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/1821/issue_layout
twitter:imagehttps://opengraph.githubassets.com/aeba0af46e06f1ed67b1305547536bb5696e4a05c35de15df644ac10d8c09520/modelcontextprotocol/python-sdk/issues/1821
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/aeba0af46e06f1ed67b1305547536bb5696e4a05c35de15df644ac10d8c09520/modelcontextprotocol/python-sdk/issues/1821
og:image:altSummary The Python SDK and TypeScript SDK use different JSON-RPC error codes for "session not found" responses (HTTP 404). The MCP specification does not define which error code to use, and there a...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemaxisbey
hostnamegithub.com
expected-hostnamegithub.com
None4eb29e5f807bd95e41196adfbc6d28f9af12d89830d8b684f3e871774ddff2fc
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
releaseb056788a129fb0194b61f2ebb4c43f6a9f4dfd27
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/1821#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F1821
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%2F1821
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/1821
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/1821
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/1821
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/issues/1821
modelcontextprotocol https://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Notifications https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Fork 3.6k 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 251 https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests 289 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
Clarify JSON-RPC error code for 'session not found' responseshttps://github.com/modelcontextprotocol/python-sdk/issues/1821#top
improves spec complianceWhen a change improves ability of SDK users to comply with spec definitionhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22improves%20spec%20compliance%22
pending SEP approvalWhen a PR is attached as an implementation detail to a SEP, we mark it as such for triage.https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22pending%20SEP%20approval%22
v2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixeshttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v2%22
https://github.com/maxisbey
maxisbeyhttps://github.com/maxisbey
on Dec 31, 2025https://github.com/modelcontextprotocol/python-sdk/issues/1821#issue-3772865875
Streamable HTTP transport spechttps://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management
validateSession methodhttps://github.com/modelcontextprotocol/typescript-sdk/blob/b0ef89ffaf6db8b3c52cd8919e8949b0f1da9ca4/packages/server/src/server/streamableHttp.ts#L829
lines 244-250https://github.com/modelcontextprotocol/python-sdk/blob/b38716e/src/mcp/server/streamable_http_manager.py#L244-L250
JSON-RPC 2.0 specificationhttps://www.jsonrpc.org/specification
JSON-RPC 2.0 specificationhttps://www.jsonrpc.org/specification
Spec Issue #509https://github.com/modelcontextprotocol/modelcontextprotocol/issues/509
PR #2038https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2038
#509https://github.com/modelcontextprotocol/modelcontextprotocol/issues/509
#1545https://github.com/modelcontextprotocol/modelcontextprotocol/pull/1545
#2164https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2164
#1549https://github.com/modelcontextprotocol/modelcontextprotocol/pull/1549
#2038https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2038
#2038https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2038
#1398https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1398
#1442https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1442
#1727https://github.com/modelcontextprotocol/python-sdk/issues/1727
#1808https://github.com/modelcontextprotocol/python-sdk/pull/1808
#1808https://github.com/modelcontextprotocol/python-sdk/pull/1808
#389https://github.com/modelcontextprotocol/typescript-sdk/issues/389
#85https://github.com/modelcontextprotocol/typescript-sdk/issues/85
JSON-RPC 2.0 Specificationhttps://www.jsonrpc.org/specification
MCP Streamable HTTP Transport Spechttps://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management
MCP Schema (2025-11-25)https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2025-11-25/schema.ts
improves spec complianceWhen a change improves ability of SDK users to comply with spec definitionhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22improves%20spec%20compliance%22
pending SEP approvalWhen a PR is attached as an implementation detail to a SEP, we mark it as such for triage.https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22pending%20SEP%20approval%22
v2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixeshttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v2%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.