Skip to content

Commit 71ae3ac

Browse files
[v2] Мonorepo, sdk-client, sdk-server, sdk-core package split (#1279)
1 parent 384311b commit 71ae3ac

File tree

221 files changed

+12067
-4817
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

221 files changed

+12067
-4817
lines changed

.changeset/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changesets
2+
3+
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
4+
[in our repository](https://github.com/changesets/changesets)
5+
6+
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)

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json",
3+
"changelog": ["@changesets/changelog-github", { "repo": "@modelcontextprotocol/typescript-sdk" }],
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "public",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": ["@modelcontextprotocol/examples-client", "@modelcontextprotocol/examples-server", "@modelcontextprotocol/examples-shared"]
11+
}

.changeset/tender-snails-fold.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@modelcontextprotocol/client': patch
3+
'@modelcontextprotocol/server': patch
4+
---
5+
6+
Initial 2.0.0-alpha.0 client and server package

.github/workflows/main.yml

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,47 @@ jobs:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19-
- uses: actions/checkout@v4
20-
- uses: actions/setup-node@v4
19+
- uses: actions/checkout@v6
20+
21+
- name: Install pnpm
22+
uses: pnpm/action-setup@v4
23+
id: pnpm-install
24+
with:
25+
run_install: false
26+
- uses: actions/setup-node@v6
2127
with:
2228
node-version: 24
23-
cache: npm
29+
cache: pnpm
30+
cache-dependency-path: pnpm-lock.yaml
2431

25-
- run: npm ci
26-
- run: npm run check
27-
- run: npm run build
32+
- run: pnpm install
33+
- run: pnpm run check:all
34+
- run: pnpm run build:all
2835

2936
test:
3037
runs-on: ubuntu-latest
3138
strategy:
3239
fail-fast: false
3340
matrix:
34-
node-version: [18, 24]
41+
node-version: [20, 22, 24]
3542

3643
steps:
37-
- uses: actions/checkout@v4
38-
- uses: actions/setup-node@v4
44+
- uses: actions/checkout@v6
45+
46+
- name: Install pnpm
47+
uses: pnpm/action-setup@v4
48+
id: pnpm-install
49+
with:
50+
run_install: false
51+
- uses: actions/setup-node@v6
3952
with:
4053
node-version: ${{ matrix.node-version }}
41-
cache: npm
54+
cache: pnpm
55+
cache-dependency-path: pnpm-lock.yaml
56+
57+
- run: pnpm install
4258

43-
- run: npm ci
44-
- run: npm test
59+
- run: pnpm test:all
4560

4661
publish:
4762
runs-on: ubuntu-latest
@@ -55,13 +70,19 @@ jobs:
5570

5671
steps:
5772
- uses: actions/checkout@v4
73+
74+
- name: Install pnpm
75+
uses: pnpm/action-setup@v4
76+
id: pnpm-install
77+
with:
78+
run_install: false
5879
- uses: actions/setup-node@v4
5980
with:
6081
node-version: 24
61-
cache: npm
82+
cache: pnpm
83+
cache-dependency-path: pnpm-lock.yaml
6284
registry-url: 'https://registry.npmjs.org'
63-
64-
- run: npm ci
85+
- run: pnpm install
6586

6687
- name: Determine npm tag
6788
id: npm-tag
@@ -84,6 +105,6 @@ jobs:
84105
echo "tag=" >> $GITHUB_OUTPUT
85106
fi
86107
87-
- run: npm publish --provenance --access public ${{ steps.npm-tag.outputs.tag }}
108+
- run: pnpm publish --provenance --access public ${{ steps.npm-tag.outputs.tag }}
88109
env:
89110
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/publish.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Publish Any Commit
2+
23
permissions:
34
contents: read
5+
46
on:
57
pull_request:
68
push:
@@ -14,14 +16,26 @@ jobs:
1416
runs-on: ubuntu-latest
1517

1618
steps:
17-
- uses: actions/checkout@v4
18-
- uses: actions/setup-node@v4
19+
- uses: actions/checkout@v6
20+
21+
- name: Install pnpm
22+
uses: pnpm/action-setup@v4
23+
with:
24+
run_install: false
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v6
1928
with:
2029
node-version: 24
21-
cache: npm
30+
cache: pnpm
31+
cache-dependency-path: pnpm-lock.yaml
32+
registry-url: 'https://registry.npmjs.org'
33+
34+
- name: Install dependencies
35+
run: pnpm install
36+
37+
- name: Build packages
38+
run: pnpm run build:all
2239

23-
- run: npm ci
24-
- name: Build
25-
run: npm run build
26-
- name: Publish
27-
run: npx pkg-pr-new publish
40+
- name: Publish preview packages
41+
run: pnpm dlx pkg-pr-new publish --packageManager=npm --pnpm './packages/server' './packages/client'

.github/workflows/release.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Release
2+
3+
permissions:
4+
contents: write
5+
pull-requests: write
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
12+
concurrency: ${{ github.workflow }}-${{ github.ref }}
13+
14+
jobs:
15+
release:
16+
name: Release
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v6
20+
21+
- name: Install pnpm
22+
uses: pnpm/action-setup@v4
23+
with:
24+
run_install: false
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v6
28+
with:
29+
node-version: 24
30+
cache: pnpm
31+
cache-dependency-path: pnpm-lock.yaml
32+
registry-url: 'https://registry.npmjs.org'
33+
34+
- name: Install dependencies
35+
run: pnpm install
36+
37+
- name: Create Release Pull Request or Publish to npm
38+
id: changesets
39+
uses: changesets/action@v1
40+
with:
41+
publish: pnpm run build:all && pnpm changeset publish
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
45+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/update-spec-types.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,35 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Checkout repository
18-
uses: actions/checkout@v4
18+
uses: actions/checkout@v6
19+
20+
- name: Install pnpm
21+
uses: pnpm/action-setup@v4
22+
id: pnpm-install
23+
with:
24+
run_install: false
1925

2026
- name: Setup Node.js
21-
uses: actions/setup-node@v4
27+
uses: actions/setup-node@v6
2228
with:
23-
node-version: '24'
29+
node-version: 24
30+
cache: pnpm
31+
cache-dependency-path: pnpm-lock.yaml
2432

2533
- name: Install dependencies
26-
run: npm ci
34+
run: pnpm install
2735

2836
- name: Fetch latest spec types
29-
run: npm run fetch:spec-types
37+
run: pnpm run fetch:spec-types
3038

3139
- name: Check for changes
3240
id: check_changes
3341
run: |
34-
if git diff --quiet src/spec.types.ts; then
42+
if git diff --quiet packages/core/src/types/spec.types.ts; then
3543
echo "has_changes=false" >> $GITHUB_OUTPUT
3644
else
3745
echo "has_changes=true" >> $GITHUB_OUTPUT
38-
LATEST_SHA=$(grep "Last updated from commit:" src/spec.types.ts | cut -d: -f2 | tr -d ' ')
46+
LATEST_SHA=$(grep "Last updated from commit:" packages/core/src/types/spec.types.ts | cut -d: -f2 | tr -d ' ')
3947
echo "sha=$LATEST_SHA" >> $GITHUB_OUTPUT
4048
fi
4149
@@ -48,12 +56,12 @@ jobs:
4856
git config user.email "github-actions[bot]@users.noreply.github.com"
4957
5058
git checkout -B update-spec-types
51-
git add src/spec.types.ts
59+
git add packages/core/src/types/spec.types.ts
5260
git commit -m "chore: update spec.types.ts from upstream"
5361
git push -f origin update-spec-types
5462
5563
# Create PR if it doesn't exist, or update if it does
56-
PR_BODY="This PR updates \`src/spec.types.ts\` from the Model Context Protocol specification.
64+
PR_BODY="This PR updates \`packages/core/src/types/spec.types.ts\` from the Model Context Protocol specification.
5765
5866
Source file: https://github.com/modelcontextprotocol/modelcontextprotocol/blob/${{ steps.check_changes.outputs.sha }}/schema/draft/schema.ts
5967

CLAUDE.md

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
55
## Build & Test Commands
66

77
```sh
8-
npm run build # Build ESM and CJS versions
9-
npm run lint # Run ESLint and Prettier check
10-
npm run lint:fix # Auto-fix lint and formatting issues
11-
npm test # Run all tests (vitest)
12-
npm run test:watch # Run tests in watch mode
13-
npx vitest path/to/file.test.ts # Run specific test file
14-
npx vitest -t "test name" # Run tests matching pattern
15-
npm run typecheck # Type-check without emitting
8+
pnpm install # Install all workspace dependencies
9+
10+
pnpm build:all # Build all packages
11+
pnpm lint:all # Run ESLint + Prettier checks across all packages
12+
pnpm lint:fix:all # Auto-fix lint and formatting issues across all packages
13+
pnpm typecheck:all # Type-check all packages
14+
pnpm test:all # Run all tests (vitest) across all packages
15+
pnpm check:all # typecheck + lint across all packages
16+
17+
# Run a single package script (examples)
18+
# Run a single package script from the repo root with pnpm filter
19+
pnpm --filter @modelcontextprotocol/core test # vitest run (core)
20+
pnpm --filter @modelcontextprotocol/core test:watch # vitest (watch)
21+
pnpm --filter @modelcontextprotocol/core test -- path/to/file.test.ts
22+
pnpm --filter @modelcontextprotocol/core test -- -t "test name"
1623
```
1724

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

3239
The SDK is organized into three main layers:
3340

34-
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.
41+
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.
3542

36-
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.
43+
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.
3744

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

4350
### Transport System
4451

45-
Transports (`src/shared/transport.ts`) provide the communication layer:
52+
Transports (`packages/core/src/shared/transport.ts`) provide the communication layer:
4653

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

5158
### Server-Side Features
5259

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

5764
### Client-Side Features
5865

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

6572
### Experimental Features
6673

67-
Located in `src/experimental/`:
74+
Located in `packages/*/src/experimental/`:
6875

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

7178
### Zod Compatibility
7279

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

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

7885
### Validation
7986

80-
Pluggable JSON Schema validation (`src/validation/`):
87+
Pluggable JSON Schema validation (`packages/core/src/validation/`):
8188

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

8592
### Examples
8693

87-
Runnable examples in `src/examples/`:
94+
Runnable examples in `examples/`:
8895

89-
- `server/` - Various server configurations (stateful, stateless, OAuth, etc.)
90-
- `client/` - Client examples (basic, OAuth, parallel calls, etc.)
91-
- `shared/` - Shared utilities like in-memory event store
96+
- `examples/server/src/` - Various server configurations (stateful, stateless, OAuth, etc.)
97+
- `examples/client/src/` - Client examples (basic, OAuth, parallel calls, etc.)
98+
- `examples/shared/src/` - Shared utilities (OAuth demo provider, etc.)
9299

93100
## Message Flow (Bidirectional Protocol)
94101

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

99106
```
100107
Protocol (abstract base)
101-
├── Client (src/client/index.ts) - can send requests TO server, handle requests FROM server
102-
└── Server (src/server/index.ts) - can send requests TO client, handle requests FROM client
103-
└── McpServer (src/server/mcp.ts) - high-level wrapper around Server
108+
├── Client (packages/client/src/client/client.ts) - can send requests TO server, handle requests FROM server
109+
└── Server (packages/server/src/server/server.ts) - can send requests TO client, handle requests FROM client
110+
└── McpServer (packages/server/src/server/mcp.ts) - high-level wrapper around Server
104111
```
105112

106113
### Outbound Flow: Sending Requests

0 commit comments

Comments
 (0)