You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the available roots change, notify the server with {@linkcode@modelcontextprotocol/client!client/client.Client#sendRootsListChanged | client.sendRootsListChanged()}.
489
489
490
+
### Request context
491
+
492
+
Handlers receive the request context (`ctx`) as their second argument. `ctx.mcpReq.protocolVersion` (from {@linkcode@modelcontextprotocol/client!index.BaseContext | BaseContext}) is the protocol version governing the request:
-**`client`** — server-only: the calling client's declared `capabilities` and implementation `info`
633
636
634
637
`BaseContext` is the common base type shared by both `ServerContext` and `ClientContext`. `ServerContext` extends each group with server-specific additions via type intersection.
Copy file name to clipboardExpand all lines: docs/server.md
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -495,6 +495,51 @@ server.registerTool(
495
495
);
496
496
```
497
497
498
+
## Reading request context
499
+
500
+
Every handler receives the request context (`ctx`) as its second argument. Beyond the helpers shown above, it carries per-request facts about the caller:
501
+
502
+
-`ctx.mcpReq.protocolVersion` (from {@linkcode@modelcontextprotocol/server!index.BaseContext | BaseContext}) — the protocol version governing the request.
503
+
-`ctx.client.capabilities` and `ctx.client.info` (from {@linkcode@modelcontextprotocol/server!index.ServerContext | ServerContext}) — the calling client's declared capabilities and implementation info.
504
+
505
+
Check `ctx.client.capabilities` before sending a [server-initiated request](#server-initiated-requests) so you never ask a client to do something it cannot — for example, only [elicit input](#elicitation) when the client declared the `elicitation` capability:
// ... delete records, attributing the request to `caller` ...
535
+
return { content: [{ type: 'text', text: `Deleted all records in ${table} (requested by ${caller})` }] };
536
+
}
537
+
);
538
+
```
539
+
540
+
> [!IMPORTANT]
541
+
> Capabilities are declarations, not authorization. Never use them to gate access to tools, resources, or data — that is the authorization layer's job.
0 commit comments