docs(server,examples): document extension capabilities with a runnable example (#2387)
This commit is contained in:
parent
f0bf785239
commit
49aeb8eb38
2 changed files with 187 additions and 0 deletions
|
|
@ -166,6 +166,20 @@ const systemPrompt = ['You are a helpful assistant.', instructions].filter(Boole
|
|||
console.log(systemPrompt);
|
||||
```
|
||||
|
||||
### Extension capabilities
|
||||
|
||||
The negotiated server capabilities include `extensions` — a map from extension identifier to that extension's settings object. Read it after connecting via {@linkcode @modelcontextprotocol/client!client/client.Client#getServerCapabilities | client.getServerCapabilities()}:
|
||||
|
||||
```ts source="../examples/guides/clientGuide.examples.ts#extensionCapabilities_read"
|
||||
const extensions = client.getServerCapabilities()?.extensions ?? {};
|
||||
|
||||
if ('com.example/feature-flags' in extensions) {
|
||||
// Advertised on this connection; the entry's value is its settings object.
|
||||
}
|
||||
```
|
||||
|
||||
See [Extension capabilities](./server.md#extension-capabilities) in the server guide for the declaring side.
|
||||
|
||||
## Authentication
|
||||
|
||||
MCP servers can require authentication before accepting client connections (see [Authorization](https://modelcontextprotocol.io/specification/latest/basic/authorization) in the MCP specification). Pass an {@linkcode @modelcontextprotocol/client!client/auth.AuthProvider |
|
||||
|
|
|
|||
|
|
@ -358,6 +358,22 @@ server.registerPrompt(
|
|||
);
|
||||
```
|
||||
|
||||
## Extension capabilities
|
||||
|
||||
A server advertises support for [MCP extensions](https://modelcontextprotocol.io/specification/latest/basic/lifecycle#capability-negotiation) through `capabilities.extensions` — a map from extension identifier to that extension's settings object. Declare entries with
|
||||
{@linkcode @modelcontextprotocol/server!server/server.Server#registerCapabilities | server.server.registerCapabilities()} before connecting:
|
||||
|
||||
```ts source="../examples/guides/serverGuide.examples.ts#extensionCapabilities_register"
|
||||
server.server.registerCapabilities({
|
||||
extensions: { 'com.example/feature-flags': { flags: ['dark-mode', 'beta-search'] } }
|
||||
});
|
||||
```
|
||||
|
||||
The map is advertised in the `initialize` result on legacy connections and in the `server/discover` response on 2026-07-28 ones. Identifiers are prefix-qualified per the spec's `_meta` key naming rules (e.g. `com.example/feature-flags`); each value is free-form JSON for
|
||||
that extension's settings — `{}` means supported with no settings.
|
||||
|
||||
For a runnable pair, see the [`extension-capabilities/` example](../examples/extension-capabilities/README.md); reading the map client-side is covered in the [client guide](./client.md#extension-capabilities).
|
||||
|
||||
## Logging
|
||||
|
||||
> [!WARNING]
|
||||
|
|
|
|||
Loading…
Reference in a new issue