Skip to content

Commit bd905ef

Browse files
authored
Merge branch 'main' into fix/exact-optional-property-types
2 parents e943b7a + 327243c commit bd905ef

119 files changed

Lines changed: 5486 additions & 3292 deletions

File tree

Some content is hidden

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

.changeset/add-hono-peer-dep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/node': patch
3+
---
4+
5+
Add missing `hono` peer dependency to `@modelcontextprotocol/node`. The package already depends on `@hono/node-server` which requires `hono` at runtime, but `hono` was only listed in the workspace root, not as a peer dependency of the package itself.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/core': patch
3+
---
4+
5+
Fix InMemoryTaskStore to enforce session isolation. Previously, sessionId was accepted but ignored on all TaskStore methods, allowing any session to enumerate, read, and mutate tasks created by other sessions. The store now persists sessionId at creation time and enforces ownership on all reads and writes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Source: https://github.com/anthropics/claude-code-action/blob/main/docs/code-review.md
2+
name: Claude Code Review
3+
4+
on:
5+
pull_request:
6+
types: [opened, synchronize, ready_for_review, reopened]
7+
8+
jobs:
9+
claude-review:
10+
if: github.event.pull_request.head.repo.fork == false && github.actor != 'dependabot[bot]'
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
pull-requests: read
15+
issues: read
16+
id-token: write
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v6
21+
with:
22+
fetch-depth: 1
23+
24+
- name: Run Claude Code Review
25+
id: claude-review
26+
uses: anthropics/claude-code-action@v1
27+
with:
28+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
29+
plugin_marketplaces: "https://github.com/anthropics/claude-code.git"
30+
plugins: "code-review@claude-code-plugins"
31+
prompt: "/code-review:code-review ${{ github.repository }}/pull/${{ github.event.pull_request.number }}"

.github/workflows/claude.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Source: https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
2+
name: Claude Code
3+
4+
on:
5+
issue_comment:
6+
types: [created]
7+
pull_request_review_comment:
8+
types: [created]
9+
issues:
10+
types: [opened, assigned]
11+
pull_request_review:
12+
types: [submitted]
13+
14+
jobs:
15+
claude:
16+
if: |
17+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
18+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
19+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
20+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
pull-requests: read
25+
issues: read
26+
id-token: write
27+
actions: read
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v6
31+
with:
32+
fetch-depth: 1
33+
34+
- name: Run Claude Code
35+
id: claude
36+
uses: anthropics/claude-code-action@v1
37+
with:
38+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
39+
use_commit_signing: true
40+
additional_permissions: |
41+
actions: read

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
registry = "https://registry.npmjs.org/"
2+
manage-package-manager-versions=false

CLAUDE.md

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ pnpm --filter @modelcontextprotocol/core test -- path/to/file.test.ts
2222
pnpm --filter @modelcontextprotocol/core test -- -t "test name"
2323
```
2424

25+
## Breaking Changes
26+
27+
When making breaking changes, document them in **both**:
28+
29+
- `docs/migration.md` — human-readable guide with before/after code examples
30+
- `docs/migration-SKILL.md` — LLM-optimized mapping tables for mechanical migration
31+
32+
Include what changed, why, and how to migrate. Search for related sections and group related changes together rather than adding new standalone sections.
33+
2534
## Code Style Guidelines
2635

2736
- **TypeScript**: Strict type checking, ES modules, explicit return types
@@ -79,12 +88,11 @@ Located in `packages/*/src/experimental/`:
7988

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

82-
### Zod Compatibility
91+
### Zod Schemas
8392

84-
The SDK uses `zod/v4` internally but supports both v3 and v4 APIs. Compatibility utilities:
93+
The SDK uses `zod/v4` internally. Schema utilities live in:
8594

86-
- `packages/core/src/util/zod-compat.ts` - Schema parsing helpers that work across versions
87-
- `packages/core/src/util/zod-json-schema-compat.ts` - Converts Zod schemas to JSON Schema
95+
- `packages/core/src/util/schema.ts` - AnySchema alias and helpers for inspecting Zod objects
8896

8997
### Validation
9098

@@ -136,37 +144,51 @@ When a request arrives from the remote side:
136144
2. **`Protocol.connect()`** routes to `_onrequest()`, `_onresponse()`, or `_onnotification()`
137145
3. **`Protocol._onrequest()`**:
138146
- Looks up handler in `_requestHandlers` map (keyed by method name)
139-
- Creates `RequestHandlerExtra` with `signal`, `sessionId`, `sendNotification`, `sendRequest`
147+
- Creates `BaseContext` with `signal`, `sessionId`, `sendNotification`, `sendRequest`, etc.
148+
- Calls `buildContext()` to let subclasses enrich the context (e.g., Server adds `requestInfo`)
140149
- Invokes handler, sends JSON-RPC response back via transport
141-
4. **Handler** was registered via `setRequestHandler(Schema, handler)`
150+
4. **Handler** was registered via `setRequestHandler('method', handler)`
142151

143152
### Handler Registration
144153

145154
```typescript
146155
// In Client (for server→client requests like sampling, elicitation)
147-
client.setRequestHandler(CreateMessageRequestSchema, async (request, extra) => {
156+
client.setRequestHandler('sampling/createMessage', async (request, ctx) => {
148157
// Handle sampling request from server
149158
return { role: "assistant", content: {...}, model: "..." };
150159
});
151160

152161
// In Server (for client→server requests like tools/call)
153-
server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
162+
server.setRequestHandler('tools/call', async (request, ctx) => {
154163
// Handle tool call from client
155164
return { content: [...] };
156165
});
157166
```
158167

159-
### Request Handler Extra
168+
### Request Handler Context
169+
170+
The `ctx` parameter in handlers provides a structured context:
171+
172+
**`BaseContext`** (common to both Server and Client), fields organized into nested groups:
173+
174+
- `sessionId?`: Transport session identifier
175+
- `mcpReq`: Request-level concerns
176+
- `id`: JSON-RPC message ID
177+
- `method`: Request method string (e.g., 'tools/call')
178+
- `_meta?`: Request metadata
179+
- `signal`: AbortSignal for cancellation
180+
- `send(request, schema, options?)`: Send related request (for bidirectional flows)
181+
- `notify(notification)`: Send related notification back
182+
- `http?`: HTTP transport info (undefined for stdio)
183+
- `authInfo?`: Validated auth token info
184+
- `task?`: Task context (`{ id?, store, requestedTtl? }`) when task storage is configured
185+
186+
**`ServerContext`** extends `BaseContext.mcpReq` and `BaseContext.http?` via type intersection:
160187

161-
The `extra` parameter in handlers (`RequestHandlerExtra`) provides:
188+
- `mcpReq` adds: `log(level, data, logger?)`, `elicitInput(params, options?)`, `requestSampling(params, options?)`
189+
- `http?` adds: `req?` (HTTP request info), `closeSSE?`, `closeStandaloneSSE?`
162190

163-
- `signal`: AbortSignal for cancellation
164-
- `sessionId`: Transport session identifier
165-
- `authInfo`: Validated auth token info (if authenticated)
166-
- `requestId`: JSON-RPC message ID
167-
- `sendNotification(notification)`: Send related notification back
168-
- `sendRequest(request, schema)`: Send related request (for bidirectional flows)
169-
- `taskStore`: Task storage interface (if tasks enabled)
191+
**`ClientContext`** is currently identical to `BaseContext`.
170192

171193
### Capability Checking
172194

@@ -197,7 +219,7 @@ const result = await server.createMessage({
197219
});
198220

199221
// Client must have registered handler:
200-
client.setRequestHandler(CreateMessageRequestSchema, async (request, extra) => {
222+
client.setRequestHandler('sampling/createMessage', async (request, extra) => {
201223
// Client-side LLM call
202224
return { role: "assistant", content: {...} };
203225
});
@@ -208,7 +230,7 @@ client.setRequestHandler(CreateMessageRequestSchema, async (request, extra) => {
208230
### Request Handler Registration (Low-Level Server)
209231

210232
```typescript
211-
server.setRequestHandler(SomeRequestSchema, async (request, extra) => {
233+
server.setRequestHandler('tools/call', async (request, extra) => {
212234
// extra contains sessionId, authInfo, sendNotification, etc.
213235
return {
214236
/* result */

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ This monorepo publishes split packages:
3939
- **`@modelcontextprotocol/server`**: build MCP servers
4040
- **`@modelcontextprotocol/client`**: build MCP clients
4141

42-
Both packages have a **required peer dependency** on `zod` for schema validation. The SDK internally imports from `zod/v4`, but remains compatible with projects using Zod v3.25+.
42+
Both packages have a **required peer dependency** on `zod` for schema validation. The SDK uses Zod v4.
4343

4444
### Middleware packages (optional)
4545

0 commit comments

Comments
 (0)