Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
be2e264
proof of concept: v2 monorepo, package split
KKonstantinov Dec 10, 2025
cfa0615
barrel exports, imports
KKonstantinov Dec 10, 2025
8922ada
add vitest config
KKonstantinov Dec 10, 2025
ebeacac
clean up
KKonstantinov Dec 10, 2025
d372e75
save commit
KKonstantinov Dec 10, 2025
4db8d1b
eslint, vitest setup; successful shared/ tests pass
KKonstantinov Dec 10, 2025
617f14e
save commit; successful tests; successful checks
KKonstantinov Dec 12, 2025
0446560
Merge branch 'main' of github.com:modelcontextprotocol/typescript-sdk…
KKonstantinov Dec 12, 2025
a089abc
save commit
KKonstantinov Dec 12, 2025
647e5f0
save commit
KKonstantinov Dec 12, 2025
6c0818f
lint fix
KKonstantinov Dec 12, 2025
ea354fc
main.yml fix
KKonstantinov Dec 12, 2025
951a234
main.yml fix
KKonstantinov Dec 12, 2025
a7e60b9
add packageManager in package.json
KKonstantinov Dec 12, 2025
9d1e86c
typecheck fix, test main.yml fix
KKonstantinov Dec 12, 2025
236e934
check:all fix
KKonstantinov Dec 12, 2025
f20be12
import fixes
KKonstantinov Dec 12, 2025
c9fcc39
test fix
KKonstantinov Dec 12, 2025
f939900
imports fix
KKonstantinov Dec 12, 2025
d9cd7fe
imports fix
KKonstantinov Dec 12, 2025
f057363
import sorting
KKonstantinov Dec 12, 2025
c3be975
clean up
KKonstantinov Dec 12, 2025
c3353c9
pr-pkg-new update
KKonstantinov Dec 12, 2025
f1c45f2
pkg-pr-new update
KKonstantinov Dec 12, 2025
3e0657f
test imports, pnpm catalogs, package.json cleanup
KKonstantinov Dec 12, 2025
9f519c5
introduce named catalogs, slim down dependencies to minimum required …
KKonstantinov Dec 12, 2025
3c11e9f
add pnpm minimum version in engines
KKonstantinov Dec 12, 2025
c182b5d
add packageManager to package.json
KKonstantinov Dec 12, 2025
3275de7
pkg-pr-new update
KKonstantinov Dec 12, 2025
2020e7f
merge commit
KKonstantinov Dec 15, 2025
c21a566
ajv fix on nodenext
KKonstantinov Dec 15, 2025
d957fc0
Merge branch 'main' of github.com:modelcontextprotocol/typescript-sdk…
KKonstantinov Dec 15, 2025
7e92ba4
clean up package.json files
KKonstantinov Dec 15, 2025
7bd609c
add tsdown
KKonstantinov Dec 15, 2025
15b27d0
update pnpm lock
KKonstantinov Dec 15, 2025
ea2fc03
eslint config
KKonstantinov Dec 15, 2025
5662909
merge commit
KKonstantinov Dec 15, 2025
b5390d4
imports fix
KKonstantinov Dec 15, 2025
228097e
Merge branch 'main' into feature/v2-monorepo-setup
KKonstantinov Dec 15, 2025
76a86a5
remove deprecated tseslint.config
KKonstantinov Dec 15, 2025
2dee387
Merge branch 'feature/v2-monorepo-setup' of github.com:KKonstantinov/…
KKonstantinov Dec 15, 2025
b532047
Merge branch 'main' of github.com:modelcontextprotocol/typescript-sdk…
KKonstantinov Dec 16, 2025
a942551
move examples out of packages, tsconfig clean up, tsdown config
KKonstantinov Dec 17, 2025
2ff0cc5
fix test_1277
KKonstantinov Dec 18, 2025
88573af
restructure test helpers, integration tests, clean up package.json
KKonstantinov Dec 18, 2025
3ad9577
helpers package.json fix
KKonstantinov Dec 18, 2025
f01e323
prettier fix
KKonstantinov Dec 18, 2025
9c9d10b
add changesets
KKonstantinov Dec 18, 2025
7eb6fe3
add changeset
KKonstantinov Dec 18, 2025
8bbd59f
changeset config
KKonstantinov Dec 18, 2025
3f6e352
changesets config
KKonstantinov Dec 18, 2025
60de202
test helpers
KKonstantinov Dec 18, 2025
0067a00
bring back accidental in-memory.test.ts miss
KKonstantinov Dec 19, 2025
46d289f
add building for examples, add node 20 in main.yml
KKonstantinov Dec 19, 2025
f5e0796
prettier fix
KKonstantinov Dec 19, 2025
8c18f8d
pnpm lock
KKonstantinov Dec 19, 2025
d828014
bring back tsgo
KKonstantinov Dec 19, 2025
3e80c82
update README docs
KKonstantinov Dec 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works with multi-package repos, or single-package repos to help you version and publish your code. You can find the full documentation for it
[in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
15 changes: 15 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "@modelcontextprotocol/typescript-sdk" }],
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": [
"@modelcontextprotocol/sdk-examples-client",
"@modelcontextprotocol/sdk-examples-server",
"@modelcontextprotocol/sdk-examples-shared"
]
}
6 changes: 6 additions & 0 deletions .changeset/tender-snails-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modelcontextprotocol/sdk-client': patch
'@modelcontextprotocol/sdk-server': patch
---

Initial 2.0.0-alpha.0 client and server package
53 changes: 37 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,47 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6

- name: Install pnpm
uses: pnpm/action-setup@v4
id: pnpm-install
with:
run_install: false
- uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
cache: pnpm
cache-dependency-path: pnpm-lock.yaml

- run: npm ci
- run: npm run check
- run: npm run build
- run: pnpm install
- run: pnpm run check:all
- run: pnpm run build:all

test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [18, 24]
node-version: [20, 22, 24]

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6

- name: Install pnpm
uses: pnpm/action-setup@v4
id: pnpm-install
with:
run_install: false
- uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: npm
cache: pnpm
cache-dependency-path: pnpm-lock.yaml

- run: pnpm install

- run: npm ci
- run: npm test
- run: pnpm test:all

publish:
runs-on: ubuntu-latest
Expand All @@ -55,13 +70,19 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
id: pnpm-install
with:
run_install: false
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
registry-url: 'https://registry.npmjs.org'

- run: npm ci
- run: pnpm install

- name: Determine npm tag
id: npm-tag
Expand All @@ -84,6 +105,6 @@ jobs:
echo "tag=" >> $GITHUB_OUTPUT
fi

- run: npm publish --provenance --access public ${{ steps.npm-tag.outputs.tag }}
- run: pnpm publish --provenance --access public ${{ steps.npm-tag.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
30 changes: 22 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Publish Any Commit

permissions:
contents: read

on:
pull_request:
push:
Expand All @@ -14,14 +16,26 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: pnpm install

- name: Build packages
run: pnpm run build:all

- run: npm ci
- name: Build
run: npm run build
- name: Publish
run: npx pkg-pr-new publish
- name: Publish preview packages
run: pnpm dlx pkg-pr-new publish --packageManager=pnpm --pnpm './packages/server' './packages/client'
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Release

permissions:
contents: write
pull-requests: write

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: pnpm install

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
publish: pnpm run build:all && pnpm changeset publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
26 changes: 17 additions & 9 deletions .github/workflows/update-spec-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,35 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v6

- name: Install pnpm
uses: pnpm/action-setup@v4
id: pnpm-install
with:
run_install: false

- name: Setup Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v6
with:
node-version: '24'
node-version: 24
cache: pnpm
cache-dependency-path: pnpm-lock.yaml

- name: Install dependencies
run: npm ci
run: pnpm install

- name: Fetch latest spec types
run: npm run fetch:spec-types
run: pnpm run fetch:spec-types

- name: Check for changes
id: check_changes
run: |
if git diff --quiet src/spec.types.ts; then
if git diff --quiet packages/core/src/types/spec.types.ts; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
LATEST_SHA=$(grep "Last updated from commit:" src/spec.types.ts | cut -d: -f2 | tr -d ' ')
LATEST_SHA=$(grep "Last updated from commit:" packages/core/src/types/spec.types.ts | cut -d: -f2 | tr -d ' ')
echo "sha=$LATEST_SHA" >> $GITHUB_OUTPUT
fi

Expand All @@ -48,12 +56,12 @@ jobs:
git config user.email "github-actions[bot]@users.noreply.github.com"

git checkout -B update-spec-types
git add src/spec.types.ts
git add packages/core/src/types/spec.types.ts
git commit -m "chore: update spec.types.ts from upstream"
git push -f origin update-spec-types

# Create PR if it doesn't exist, or update if it does
PR_BODY="This PR updates \`src/spec.types.ts\` from the Model Context Protocol specification.
PR_BODY="This PR updates \`packages/core/src/types/spec.types.ts\` from the Model Context Protocol specification.

Source file: https://github.com/modelcontextprotocol/modelcontextprotocol/blob/${{ steps.check_changes.outputs.sha }}/schema/draft/schema.ts

Expand Down
73 changes: 40 additions & 33 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
## Build & Test Commands

```sh
npm run build # Build ESM and CJS versions
npm run lint # Run ESLint and Prettier check
npm run lint:fix # Auto-fix lint and formatting issues
npm test # Run all tests (vitest)
npm run test:watch # Run tests in watch mode
npx vitest path/to/file.test.ts # Run specific test file
npx vitest -t "test name" # Run tests matching pattern
npm run typecheck # Type-check without emitting
pnpm install # Install all workspace dependencies

pnpm build:all # Build all packages
pnpm lint:all # Run ESLint + Prettier checks across all packages
pnpm lint:fix:all # Auto-fix lint and formatting issues across all packages
pnpm typecheck:all # Type-check all packages
pnpm test:all # Run all tests (vitest) across all packages
pnpm check:all # typecheck + lint across all packages

# Run a single package script (examples)
# Run a single package script from the repo root with pnpm filter
pnpm --filter @modelcontextprotocol/sdk-core test # vitest run (core)
pnpm --filter @modelcontextprotocol/sdk-core test:watch # vitest (watch)
pnpm --filter @modelcontextprotocol/sdk-core test -- path/to/file.test.ts
pnpm --filter @modelcontextprotocol/sdk-core test -- -t "test name"
```

## Code Style Guidelines
Expand All @@ -31,64 +38,64 @@ npm run typecheck # Type-check without emitting

The SDK is organized into three main layers:

1. **Types Layer** (`src/types.ts`) - Protocol types generated from the MCP specification. All JSON-RPC message types, schemas, and protocol constants are defined here using Zod v4.
1. **Types Layer** (`packages/core/src/types/types.ts`) - Protocol types generated from the MCP specification. All JSON-RPC message types, schemas, and protocol constants are defined here using Zod v4.

2. **Protocol Layer** (`src/shared/protocol.ts`) - The abstract `Protocol` class that handles JSON-RPC message routing, request/response correlation, capability negotiation, and transport management. Both `Client` and `Server` extend this class.
2. **Protocol Layer** (`packages/core/src/shared/protocol.ts`) - The abstract `Protocol` class that handles JSON-RPC message routing, request/response correlation, capability negotiation, and transport management. Both `Client` and `Server` extend this class.

3. **High-Level APIs**:
- `Client` (`src/client/index.ts`) - Low-level client extending Protocol with typed methods for all MCP operations
- `Server` (`src/server/index.ts`) - Low-level server extending Protocol with request handler registration
- `McpServer` (`src/server/mcp.ts`) - High-level server API with simplified resource/tool/prompt registration
- `Client` (`packages/client/src/client/client.ts`) - Client implementation extending Protocol with typed methods for MCP operations
- `Server` (`packages/server/src/server/server.ts`) - Server implementation extending Protocol with request handler registration
- `McpServer` (`packages/server/src/server/mcp.ts`) - High-level server API with simplified resource/tool/prompt registration

### Transport System

Transports (`src/shared/transport.ts`) provide the communication layer:
Transports (`packages/core/src/shared/transport.ts`) provide the communication layer:

- **Streamable HTTP** (`src/server/streamableHttp.ts`, `src/client/streamableHttp.ts`) - Recommended transport for remote servers, supports SSE for streaming
- **SSE** (`src/server/sse.ts`, `src/client/sse.ts`) - Legacy HTTP+SSE transport for backwards compatibility
- **stdio** (`src/server/stdio.ts`, `src/client/stdio.ts`) - For local process-spawned integrations
- **Streamable HTTP** (`packages/server/src/server/streamableHttp.ts`, `packages/client/src/client/streamableHttp.ts`) - Recommended transport for remote servers, supports SSE for streaming
- **SSE** (`packages/server/src/server/sse.ts`, `packages/client/src/client/sse.ts`) - Legacy HTTP+SSE transport for backwards compatibility
- **stdio** (`packages/server/src/server/stdio.ts`, `packages/client/src/client/stdio.ts`) - For local process-spawned integrations

### Server-Side Features

- **Tools/Resources/Prompts**: Registered via `McpServer.tool()`, `.resource()`, `.prompt()` methods
- **OAuth/Auth**: Full OAuth 2.0 server implementation in `src/server/auth/`
- **Completions**: Auto-completion support via `src/server/completable.ts`
- **OAuth/Auth**: Full OAuth 2.0 server implementation in `packages/server/src/server/auth/`
- **Completions**: Auto-completion support via `packages/server/src/server/completable.ts`

### Client-Side Features

- **Auth**: OAuth client support in `src/client/auth.ts` and `src/client/auth-extensions.ts`
- **Middleware**: Request middleware in `src/client/middleware.ts`
- **Auth**: OAuth client support in `packages/client/src/client/auth.ts` and `packages/client/src/client/auth-extensions.ts`
- **Middleware**: Request middleware in `packages/client/src/client/middleware.ts`
- **Sampling**: Clients can handle `sampling/createMessage` requests from servers (LLM completions)
- **Elicitation**: Clients can handle `elicitation/create` requests for user input (form or URL mode)
- **Roots**: Clients can expose filesystem roots to servers via `roots/list`

### Experimental Features

Located in `src/experimental/`:
Located in `packages/*/src/experimental/`:

- **Tasks**: Long-running task support with polling/resumption (`src/experimental/tasks/`)
- **Tasks**: Long-running task support with polling/resumption (`packages/core/src/experimental/tasks/`)

### Zod Compatibility

The SDK uses `zod/v4` internally but supports both v3 and v4 APIs. Compatibility utilities:

- `src/server/zod-compat.ts` - Schema parsing helpers that work across versions
- `src/server/zod-json-schema-compat.ts` - Converts Zod schemas to JSON Schema
- `packages/core/src/util/zod-compat.ts` - Schema parsing helpers that work across versions
- `packages/core/src/util/zod-json-schema-compat.ts` - Converts Zod schemas to JSON Schema

### Validation

Pluggable JSON Schema validation (`src/validation/`):
Pluggable JSON Schema validation (`packages/core/src/validation/`):

- `ajv-provider.ts` - Default Ajv-based validator
- `cfworker-provider.ts` - Cloudflare Workers-compatible alternative

### Examples

Runnable examples in `src/examples/`:
Runnable examples in `examples/`:

- `server/` - Various server configurations (stateful, stateless, OAuth, etc.)
- `client/` - Client examples (basic, OAuth, parallel calls, etc.)
- `shared/` - Shared utilities like in-memory event store
- `examples/server/src/` - Various server configurations (stateful, stateless, OAuth, etc.)
- `examples/client/src/` - Client examples (basic, OAuth, parallel calls, etc.)
- `examples/shared/src/` - Shared utilities (OAuth demo provider, etc.)

## Message Flow (Bidirectional Protocol)

Expand All @@ -98,9 +105,9 @@ MCP is bidirectional: both client and server can send requests. Understanding th

```
Protocol (abstract base)
├── Client (src/client/index.ts) - can send requests TO server, handle requests FROM server
└── Server (src/server/index.ts) - can send requests TO client, handle requests FROM client
└── McpServer (src/server/mcp.ts) - high-level wrapper around Server
├── Client (packages/client/src/client/client.ts) - can send requests TO server, handle requests FROM server
└── Server (packages/server/src/server/server.ts) - can send requests TO client, handle requests FROM client
└── McpServer (packages/server/src/server/mcp.ts) - high-level wrapper around Server
```

### Outbound Flow: Sending Requests
Expand Down
Loading
Loading