The official TypeScript SDK for Model Context Protocol servers and clients
by modelcontextprotocolLast 12 weeks ยท 93 commits
5 of 6 standards met
Problem The method sends a GET request to open an SSE stream during initialization. Per the MCP spec, the server MAY respond with if it doesn't support SSE streams, and the client correctly handles this. However, many MCP servers return 404 Not Found or 406 Not Acceptable instead of 405 for this GET request: 404: Server doesn't have a GET handler for the MCP endpoint (only POST) 406: Server rejects header (e.g., requires both and ) Both cases mean the same thing: the server does not offer an SSE stream at the GET endpoint. But the client treats them as fatal errors, preventing the connection even though POST-based communication would work fine. Current Behavior This causes errors like: Affected Clients This impacts any client consuming the SDK, including: Gemini CLI () โ #5268, #2787 MCP Inspector โ #1150 LibreChat** and other MCP consumers Proposed Fix Treat 404 and 406 the same as 405 โ all indicate the server does not offer an SSE stream at the GET endpoint: The client will then proceed with POST-based communication, which works correctly for these servers. Reproduction 1. Set up an MCP server that only supports POST (no GET SSE stream) 2. Connect using 3. The GET request returns 404 โ client throws and disconnects 4. POST would have worked fine Environment : latest Discovered while debugging Gemini CLI v0.32.1 connecting to a remote HTTP MCP server (ArmorCode)
Replace the internal AssertObjectSchema (z.custom) with proper Zod schemas (JSONValueSchema, JSONObjectSchema, JSONArraySchema) that produce correct JSON types, aligning the SDK's inferred types with the spec. Also syncs spec.types.ts and adds missing SDK types (error codes, ResultResponse types, MetaObject types) to pass spec type checks. Motivation and Context How Has This Been Tested? Breaking Changes Types of changes [x] Bug fix (non-breaking change which fixes an issue) [x] New feature (non-breaking change which adds functionality) [ ] Breaking change (fix or feature that would cause existing functionality to change) [ ] Documentation update Checklist [x] I have read the MCP Documentation [x] My code follows the repository's style guidelines [x] New and existing tests pass locally [x] I have added appropriate error handling [x] I have added or updated documentation as needed Additional context
Repository: modelcontextprotocol/typescript-sdk. Description: The official TypeScript SDK for Model Context Protocol servers and clients Stars: 11762, Forks: 1652. Primary language: TypeScript. Languages: TypeScript (97.4%), JavaScript (2.4%), Shell (0.2%). Homepage: https://modelcontextprotocol.io Latest release: v1.27.1 (1w ago). Open PRs: 100, open issues: 233. Last activity: 3h ago. Community health: 87%. Top contributors: jspahrsummers, ihrpr, ochafik, bhosmer-ant, felixweinberger, KKonstantinov, jerome3o-anthropic, cliffhall, allenzhou101, mattzcarey and others.
TypeScript
According to SEP-2133, the protocol supports extensions which be be advertised in the capabilities object. This PR adds this field to the SDK Motivation and Context This enables extensions to build upon the typescript-sdk How Has This Been Tested? Existing and new tests pass. Breaking Changes No Types of changes [ ] Bug fix (non-breaking change which fixes an issue) [X] New feature (non-breaking change which adds functionality) [ ] Breaking change (fix or feature that would cause existing functionality to change) [ ] Documentation update Checklist [X] I have read the MCP Documentation [X] My code follows the repository's style guidelines [X] New and existing tests pass locally [X] I have added appropriate error handling [ ] I have added or updated documentation as needed Additional context
Refactor RegisteredTool, RegisteredPrompt, RegisteredResource to proper classes Motivation and Context The , , , and types were previously plain object types. This refactoring converts them to proper classes with: Private fields using syntax for encapsulation Getter methods for read-only access to properties Simplified method using for protocol fields Constructor callbacks pattern for communicating with New getter methods on to retrieve all registered items Added support to (for parity with protocol type) How Has This Been Tested? passes passes 487 tests passing Breaking Changes Yes, users will need to update their code: Note: In v1, the method used which did not match the field used in . This inconsistency has been fixed in v2 โ both now use . New getter methods on : โ โ โ โ Types of changes [ ] Bug fix (non-breaking change which fixes an issue) [x] New feature (non-breaking change which adds functionality) [x] Breaking change (fix or feature that would cause existing functionality to change) [x] Documentation update Checklist [x] I have read the MCP Documentation [x] My code follows the repository's style guidelines [x] New and existing tests pass locally [x] I have added appropriate error handling [x] I have added or updated documentation as needed Additional context New file structure Key design decisions 1. Private fields with : Uses JavaScript private class fields for true encapsulation 2. Protocol fields grouped: Protocol-derived fields stored in object, SDK-specific fields stored separately 3. Simplified update(): Uses so new protocol fields automatically work 4. Constructor callbacks: Classes receive , , callbacks for communicating state changes to 5. Type derivation with Omit**: Config types derived from protocol types using to automatically include new fields
Add integration tests that run MCP server/client round-trips natively on Bun and Deno using their respective test runners, verifying the SDK works across runtimes beyond Node.js. Add bun.test.ts using bun:test + Bun.serve() Add deno.test.ts using Deno.test + Deno.serve() + node:assert Add test-runtimes CI job (Bun 1.x + Deno v2.x matrix) Gate publish job on test-runtimes passing Exclude runtime-specific tests from vitest and tsconfig Motivation and Context How Has This Been Tested? Breaking Changes Types of changes [ ] Bug fix (non-breaking change which fixes an issue) [x] New feature (non-breaking change which adds functionality) [ ] Breaking change (fix or feature that would cause existing functionality to change) [x] Documentation update Checklist [x] I have read the MCP Documentation [x] My code follows the repository's style guidelines [x] New and existing tests pass locally [x] I have added appropriate error handling [x] I have added or updated documentation as needed Additional context