Skip to content

Commit 5acf49c

Browse files
committed
docs: clarify V2 type safety for handler registration
Add note explaining that standard MCP methods retain full type safety via RequestTypeMap/NotificationTypeMap indexing. Custom methods need ProtocolSpec generic (from protocol-concrete branch) to get typed params/results.
1 parent e282b55 commit 5acf49c

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

docs/v2-sdk-impact-analysis.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,18 @@ Key changes:
6767
Schema objects like `CallToolRequestSchema` are **no longer passed** to these methods.
6868
Instead, a method string is used and the SDK internally resolves the correct schema.
6969

70-
The protocol-concrete branch adds a **3-arg overload** for custom (non-spec) methods:
70+
**Type safety is preserved** for standard MCP methods — `M` narrows to a string literal
71+
that indexes `RequestTypeMap`/`NotificationTypeMap`, so handler params/return are fully typed:
7172
```typescript
73+
// TypeScript infers: request is CallToolRequest, return must be CallToolResult
74+
server.setRequestHandler('tools/call', async (request, ctx) => { ... });
75+
```
76+
77+
For **custom (non-spec) methods** like ext-apps' `ui/*`, the untyped string fallback gives
78+
`Record<string, unknown>` params. To get type safety on custom methods, use the
79+
protocol-concrete branch's **3-arg overload** with a `ProtocolSpec` generic:
80+
```typescript
81+
// With ProtocolSpec, params/result are typed from the spec:
7282
protocol.setRequestHandler('ui/initialize', paramsSchema, handler)
7383
```
7484

0 commit comments

Comments
 (0)