mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-18 08:03:26 +02:00
Demonstrate registration of tools conditioned upon client capability support. Also, obviated need for clientConnected callback to pass sessionId because we defer initial fetching of roots happens when you run the get-roots-list tool.
* In how-it-works.md, - added a section on conditional tool registration * In server/index.ts - import registerConditionalTools - in an oninitialized handler for the server, call registerConditionalTools - removed clientConnected from ServerFactoryResponse and all mentions in docs * In tools/index.ts - export a registerConditionalTools function - refactor/move calls to registerGetRootsListTool, registerTriggerElicitationRequestTool, and registerTriggerSamplingRequestTool out of registerTools and into registerConditionalTools * In server/roots.ts - only act if client supports roots - remove setInterval from call to requestRoots. It isn't happening during the initialze handshake anymore, so it doesn't interfere with that process if called immediaately * In get-roots-list.ts, trigger-elicitation-request.ts, and trigger-sampling-request.ts, - only register tool if client supports capability * Throughout the rest of the files, removing all references to `clientConnected`
This commit is contained in:
@@ -7,9 +7,19 @@
|
||||
| [Extension Points](extension.md)
|
||||
| How It Works**
|
||||
|
||||
## Resource Subscriptions
|
||||
# Conditional Tool Registration
|
||||
|
||||
Each client manages its own resource subscriptions and receives notifications only for the URIs it subscribed to, independent of other clients.
|
||||
### Module: `server/index.ts`
|
||||
|
||||
- Some tools require client support for the capability they demonstrate. These are:
|
||||
- `get-roots-list`
|
||||
- `trigger-elicitation-request`
|
||||
- `trigger-sampling-request`
|
||||
- Client capabilities aren't known until after initilization handshake is complete.
|
||||
- Most tools are registered immediately during the Server Factory execution, prior to client connection.
|
||||
- To defer registration of these commands until client capabilities are known, a `registerConditionalTools(server)` function is invoked from an `onintitialized` handler.
|
||||
|
||||
## Resource Subscriptions
|
||||
|
||||
### Module: `resources/subscriptions.ts`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user