Skip to content

Commit 1655417

Browse files
committed
consolidate docs
1 parent 8bb045d commit 1655417

File tree

7 files changed

+251
-248
lines changed

7 files changed

+251
-248
lines changed

README.md

Lines changed: 32 additions & 35 deletions
Large diffs are not rendered by default.

docs/capabilities.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
## Sampling
2+
3+
MCP servers can request LLM completions from connected clients that support the sampling capability. This lets your tools offload summarisation or generation to the client’s model.
4+
5+
For a runnable server that combines tools, logging and tasks, see:
6+
7+
- [`toolWithSampleServer.ts`](../src/examples/server/toolWithSampleServer.ts)
8+
9+
In practice you will:
10+
11+
- Declare the sampling capability on the client.
12+
- Call `server.server.createMessage(...)` from within a tool handler.
13+
- Return the model’s response as structured content and/or text.
14+
15+
Refer to the MCP spec’s sampling section for full request/response details.
16+
17+
## Elicitation
18+
19+
### Form elicitation
20+
21+
Form elicitation lets a tool ask the user for additional, **non‑sensitive** information via a schema‑driven form. The server sends a schema and message, and the client is responsible for collecting and returning the data.
22+
23+
Runnable example:
24+
25+
- Server: [`elicitationFormExample.ts`](../src/examples/server/elicitationFormExample.ts)
26+
- Client‑side handling: [`simpleStreamableHttp.ts`](../src/examples/client/simpleStreamableHttp.ts)
27+
28+
The `simpleStreamableHttp` server also includes a `collect-user-info` tool that demonstrates how to drive elicitation from a tool and handle the response.
29+
30+
### URL elicitation
31+
32+
URL elicitation is designed for sensitive data and secure web‑based flows (e.g., collecting an API key, confirming a payment, or doing third‑party OAuth). Instead of returning form data, the server asks the client to open a URL and the rest of the flow happens in the browser.
33+
34+
Runnable example:
35+
36+
- Server: [`elicitationUrlExample.ts`](../src/examples/server/elicitationUrlExample.ts)
37+
- Client: [`elicitationUrlExample.ts`](../src/examples/client/elicitationUrlExample.ts)
38+
39+
Key points:
40+
41+
- Use `mode: 'url'` when calling `server.server.elicitInput(...)`.
42+
- Implement a client‑side handler for `ElicitRequestSchema` that:
43+
- Shows the full URL and reason to the user.
44+
- Asks for explicit consent.
45+
- Opens the URL in the system browser.
46+
47+
Sensitive information **must not** be collected via form elicitation; always use URL elicitation or out‑of‑band flows for secrets.
48+
49+
## Task-based execution (experimental)
50+
51+
Task-based execution enables “call-now, fetch-later” patterns for long-running operations. Instead of returning a result immediately, a tool creates a task that can be polled or resumed later.
52+
53+
The APIs live under the experimental `.experimental.tasks` namespace and may change without notice.
54+
55+
### Server-side concepts
56+
57+
On the server you will:
58+
59+
- Provide a `TaskStore` implementation that persists task metadata and results.
60+
- Enable the `tasks` capability when constructing the server.
61+
- Register tools with `server.experimental.tasks.registerToolTask(...)`.
62+
63+
For a runnable example that uses the in-memory store shipped with the SDK, see:
64+
65+
- [`toolWithSampleServer.ts`](../src/examples/server/toolWithSampleServer.ts)
66+
- `src/experimental/tasks/stores/in-memory.ts`
67+
68+
### Client-side usage
69+
70+
On the client, you use:
71+
72+
- `client.experimental.tasks.callToolStream(...)` to start a tool call that may create a task and emit status updates over time.
73+
- `client.getTask(...)` and `client.getTaskResult(...)` to check status and fetch results after reconnecting.
74+
75+
The interactive client in:
76+
77+
- [`simpleStreamableHttp.ts`](../src/examples/client/simpleStreamableHttp.ts)
78+
79+
includes commands to demonstrate calling tools that support tasks and handling their lifecycle.
80+
81+
See the MCP spec’s tasks section and the example server/client above for a full walkthrough of the task status lifecycle and TTL handling.

docs/client.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ The SDK provides a high-level `Client` class that connects to MCP servers over d
88

99
Runnable client examples live under:
1010

11-
- `src/examples/client/simpleStreamableHttp.ts`
12-
- `src/examples/client/streamableHttpWithSseFallbackClient.ts`
13-
- `src/examples/client/ssePollingClient.ts`
14-
- `src/examples/client/multipleClientsParallel.ts`
15-
- `src/examples/client/parallelToolCallsClient.ts`
11+
- [`simpleStreamableHttp.ts`](../src/examples/client/simpleStreamableHttp.ts)
12+
- [`streamableHttpWithSseFallbackClient.ts`](../src/examples/client/streamableHttpWithSseFallbackClient.ts)
13+
- [`ssePollingClient.ts`](../src/examples/client/ssePollingClient.ts)
14+
- [`multipleClientsParallel.ts`](../src/examples/client/multipleClientsParallel.ts)
15+
- [`parallelToolCallsClient.ts`](../src/examples/client/parallelToolCallsClient.ts)
1616

1717
## Connecting and basic operations
1818

@@ -25,7 +25,7 @@ A typical flow:
2525
- `listPrompts`, `getPrompt`
2626
- `listResources`, `readResource`
2727

28-
See `src/examples/client/simpleStreamableHttp.ts` for an interactive CLI client that exercises these methods and shows how to handle notifications, elicitation and tasks.
28+
See [`simpleStreamableHttp.ts`](../src/examples/client/simpleStreamableHttp.ts) for an interactive CLI client that exercises these methods and shows how to handle notifications, elicitation and tasks.
2929

3030
## Transports and backwards compatibility
3131

@@ -36,7 +36,7 @@ To support both modern Streamable HTTP and legacy SSE servers, use a client that
3636

3737
Runnable example:
3838

39-
- `src/examples/client/streamableHttpWithSseFallbackClient.ts`
39+
- [`streamableHttpWithSseFallbackClient.ts`](../src/examples/client/streamableHttpWithSseFallbackClient.ts)
4040

4141
## OAuth client authentication helpers
4242

@@ -48,10 +48,10 @@ For OAuth-secured MCP servers, the client `auth` module exposes:
4848

4949
Examples:
5050

51-
- `src/examples/client/simpleOAuthClient.ts`
52-
- `src/examples/client/simpleOAuthClientProvider.ts`
53-
- `src/examples/client/simpleClientCredentials.ts`
54-
- Server-side auth demo: `src/examples/server/demoInMemoryOAuthProvider.ts`
51+
- [`simpleOAuthClient.ts`](../src/examples/client/simpleOAuthClient.ts)
52+
- [`simpleOAuthClientProvider.ts`](../src/examples/client/simpleOAuthClientProvider.ts)
53+
- [`simpleClientCredentials.ts`](../src/examples/client/simpleClientCredentials.ts)
54+
- Server-side auth demo: [`demoInMemoryOAuthProvider.ts`](../src/examples/server/demoInMemoryOAuthProvider.ts)
5555

5656
These examples show how to:
5757

docs/sampling-and-elicitation.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

docs/server.md

Lines changed: 127 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ This SDK lets you build MCP servers in TypeScript and connect them to different
88

99
For a complete, runnable example server, see:
1010

11-
- `src/examples/server/simpleStreamableHttp.ts` – feature‑rich Streamable HTTP server
12-
- `src/examples/server/jsonResponseStreamableHttp.ts` – Streamable HTTP with JSON response mode
13-
- `src/examples/server/simpleStatelessStreamableHttp.ts` – stateless Streamable HTTP server
14-
- `src/examples/server/simpleSseServer.ts` – deprecated HTTP+SSE transport
15-
- `src/examples/server/sseAndStreamableHttpCompatibleServer.ts` – backwards‑compatible server for old and new clients
11+
- [`simpleStreamableHttp.ts`](../src/examples/server/simpleStreamableHttp.ts) – feature‑rich Streamable HTTP server
12+
- [`jsonResponseStreamableHttp.ts`](../src/examples/server/jsonResponseStreamableHttp.ts) – Streamable HTTP with JSON response mode
13+
- [`simpleStatelessStreamableHttp.ts`](../src/examples/server/simpleStatelessStreamableHttp.ts) – stateless Streamable HTTP server
14+
- [`simpleSseServer.ts`](../src/examples/server/simpleSseServer.ts) – deprecated HTTP+SSE transport
15+
- [`sseAndStreamableHttpCompatibleServer.ts`](../src/examples/server/sseAndStreamableHttpCompatibleServer.ts) – backwards‑compatible server for old and new clients
1616

1717
## Transports
1818

@@ -27,9 +27,9 @@ Streamable HTTP is the modern, fully featured transport. It supports:
2727

2828
Key examples:
2929

30-
- `src/examples/server/simpleStreamableHttp.ts` – sessions, logging, tasks, elicitation, auth hooks
31-
- `src/examples/server/jsonResponseStreamableHttp.ts``enableJsonResponse: true`, no SSE
32-
- `src/examples/server/standaloneSseWithGetStreamableHttp.ts` – notifications with Streamable HTTP GET + SSE
30+
- [`simpleStreamableHttp.ts`](../src/examples/server/simpleStreamableHttp.ts) – sessions, logging, tasks, elicitation, auth hooks
31+
- [`jsonResponseStreamableHttp.ts`](../src/examples/server/jsonResponseStreamableHttp.ts)`enableJsonResponse: true`, no SSE
32+
- [`standaloneSseWithGetStreamableHttp.ts`](../src/examples/server/standaloneSseWithGetStreamableHttp.ts) – notifications with Streamable HTTP GET + SSE
3333

3434
See the MCP spec for full transport details:
3535
`https://modelcontextprotocol.io/specification/2025-03-26/basic/transports`
@@ -43,46 +43,156 @@ Streamable HTTP can run:
4343

4444
Examples:
4545

46-
- Stateless Streamable HTTP: `src/examples/server/simpleStatelessStreamableHttp.ts`
47-
- Stateful with resumability: `src/examples/server/simpleStreamableHttp.ts`
46+
- Stateless Streamable HTTP: [`simpleStatelessStreamableHttp.ts`](../src/examples/server/simpleStatelessStreamableHttp.ts)
47+
- Stateful with resumability: [`simpleStreamableHttp.ts`](../src/examples/server/simpleStreamableHttp.ts)
4848

4949
### Deprecated HTTP + SSE
5050

5151
The older HTTP+SSE transport (protocol version 2024‑11‑05) is supported only for backwards compatibility. New implementations should prefer Streamable HTTP.
5252

5353
Examples:
5454

55-
- Legacy SSE server: `src/examples/server/simpleSseServer.ts`
55+
- Legacy SSE server: [`simpleSseServer.ts`](../src/examples/server/simpleSseServer.ts)
5656
- Backwards‑compatible server (Streamable HTTP + SSE):
57-
`src/examples/server/sseAndStreamableHttpCompatibleServer.ts`
57+
[`sseAndStreamableHttpCompatibleServer.ts`](../src/examples/server/sseAndStreamableHttpCompatibleServer.ts)
5858

5959
## Running your server
6060

6161
For a minimal “getting started” experience:
6262

63-
1. Start from `src/examples/server/simpleStreamableHttp.ts`.
63+
1. Start from [`simpleStreamableHttp.ts`](../src/examples/server/simpleStreamableHttp.ts).
6464
2. Remove features you do not need (tasks, advanced logging, OAuth, etc.).
6565
3. Register your own tools, resources and prompts.
6666

6767
For more detailed patterns (stateless vs stateful, JSON response mode, CORS, DNS rebind protection), see the examples above and the MCP spec sections on transports.
6868

69+
## Tools, resources, and prompts
70+
71+
### Tools
72+
73+
Tools let MCP clients ask your server to take actions. They are usually the main way that LLMs call into your application.
74+
75+
A typical registration with `registerTool` looks like this:
76+
77+
```typescript
78+
server.registerTool(
79+
'calculate-bmi',
80+
{
81+
title: 'BMI Calculator',
82+
description: 'Calculate Body Mass Index',
83+
inputSchema: {
84+
weightKg: z.number(),
85+
heightM: z.number()
86+
},
87+
outputSchema: { bmi: z.number() }
88+
},
89+
async ({ weightKg, heightM }) => {
90+
const output = { bmi: weightKg / (heightM * heightM) };
91+
return {
92+
content: [{ type: 'text', text: JSON.stringify(output) }],
93+
structuredContent: output
94+
};
95+
}
96+
);
97+
```
98+
99+
This snippet is illustrative only; for runnable servers that expose tools, see:
100+
101+
- [`simpleStreamableHttp.ts`](../src/examples/server/simpleStreamableHttp.ts)
102+
- [`toolWithSampleServer.ts`](../src/examples/server/toolWithSampleServer.ts)
103+
104+
#### ResourceLink outputs
105+
106+
Tools can return `resource_link` content items to reference large resources without embedding them directly, allowing clients to fetch only what they need.
107+
108+
The README’s `list-files` example shows the pattern conceptually; for concrete usage, see the Streamable HTTP examples in `src/examples/server`.
109+
110+
### Resources
111+
112+
Resources expose data to clients, but should not perform heavy computation or side‑effects. They are ideal for configuration, documents, or other reference data.
113+
114+
Conceptually, you might register resources like:
115+
116+
```typescript
117+
server.registerResource(
118+
'config',
119+
'config://app',
120+
{
121+
title: 'Application Config',
122+
description: 'Application configuration data',
123+
mimeType: 'text/plain'
124+
},
125+
async uri => ({
126+
contents: [{ uri: uri.href, text: 'App configuration here' }]
127+
})
128+
);
129+
```
130+
131+
Dynamic resources use `ResourceTemplate` and can support completions on path parameters. For full runnable examples of resources:
132+
133+
- [`simpleStreamableHttp.ts`](../src/examples/server/simpleStreamableHttp.ts)
134+
135+
### Prompts
136+
137+
Prompts are reusable templates that help humans (or client UIs) talk to models in a consistent way. They are declared on the server and listed through MCP.
138+
139+
A minimal prompt:
140+
141+
```typescript
142+
server.registerPrompt(
143+
'review-code',
144+
{
145+
title: 'Code Review',
146+
description: 'Review code for best practices and potential issues',
147+
argsSchema: { code: z.string() }
148+
},
149+
({ code }) => ({
150+
messages: [
151+
{
152+
role: 'user',
153+
content: {
154+
type: 'text',
155+
text: `Please review this code:\n\n${code}`
156+
}
157+
}
158+
]
159+
})
160+
);
161+
```
162+
163+
For prompts integrated into a full server, see:
164+
165+
- [`simpleStreamableHttp.ts`](../src/examples/server/simpleStreamableHttp.ts)
166+
167+
### Completions
168+
169+
Both prompts and resources can support argument completions. On the client side, you use `client.complete()` with a reference to the prompt or resource and the partially‑typed argument.
170+
171+
See the MCP spec sections on prompts and resources for complete details, and [`simpleStreamableHttp.ts`](../src/examples/client/simpleStreamableHttp.ts) for client‑side usage patterns.
172+
173+
### Display names and metadata
174+
175+
Tools, resources and prompts support a `title` field for human‑readable names. Older APIs can also attach `annotations.title`. To compute the correct display name on the client, use:
176+
177+
- `getDisplayName` from `@modelcontextprotocol/sdk/shared/metadataUtils.js`
178+
69179
## Multi‑node deployment patterns
70180

71-
The SDK supports multi‑node deployments using Streamable HTTP. The high‑level patterns are documented in `src/examples/README.md`:
181+
The SDK supports multi‑node deployments using Streamable HTTP. The high‑level patterns are documented in [`README.md`](../src/examples/README.md):
72182

73183
- Stateless mode (any node can handle any request)
74184
- Persistent storage mode (shared database for session state)
75185
- Local state with message routing (message queue + pub/sub)
76186

77-
Those deployment diagrams are kept in `src/examples/README.md` so the examples and documentation stay aligned.
187+
Those deployment diagrams are kept in [`README.md`](../src/examples/README.md) so the examples and documentation stay aligned.
78188

79189
## Backwards compatibility
80190

81191
To handle both modern and legacy clients:
82192

83193
- Run a backwards‑compatible server:
84-
- `src/examples/server/sseAndStreamableHttpCompatibleServer.ts`
194+
- [`sseAndStreamableHttpCompatibleServer.ts`](../src/examples/server/sseAndStreamableHttpCompatibleServer.ts)
85195
- Use a client that falls back from Streamable HTTP to SSE:
86-
- `src/examples/client/streamableHttpWithSseFallbackClient.ts`
196+
- [`streamableHttpWithSseFallbackClient.ts`](../src/examples/client/streamableHttpWithSseFallbackClient.ts)
87197

88198
For the detailed protocol rules, see the “Backwards compatibility” section of the MCP spec.

0 commit comments

Comments
 (0)