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
Add server instructions, structured output, and more to docs/client.md
Expand the client guide with four new topics and their companion
`.examples.ts` snippets:
- Server instructions: retrieving `getInstructions()` and folding it
into a system prompt
- Pagination: `listTools()`, `listResources()`, and `listPrompts()`
examples now loop on `nextCursor` to collect all pages
- Structured tool output: `structuredContent` for machine-readable
results alongside LLM-facing `content`
- Progress tracking: `onprogress`, `resetTimeoutOnProgress`, and
`maxTotalTimeout` options for long-running tool calls
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
For stdio, `client.close()` handles graceful process shutdown (closes stdin, then SIGTERM, then SIGKILL if needed).
99
100
101
+
### Server instructions
102
+
103
+
Servers can provide an `instructions` string during initialization that describes how to use them — cross-tool relationships, workflow patterns, and constraints (see [Instructions](https://modelcontextprotocol.io/specification/latest/basic/lifecycle#instructions) in the MCP specification). Retrieve it after connecting and include it in the model's system prompt:
const systemPrompt = ['You are a helpful assistant.', instructions].filter(Boolean).join('\n\n');
109
+
110
+
console.log(systemPrompt);
111
+
```
112
+
100
113
## Authentication
101
114
102
115
MCP servers can require OAuth 2.0 authentication before accepting client connections (see [Authorization](https://modelcontextprotocol.io/specification/latest/basic/authorization) in the MCP specification). Pass an `authProvider` to {@linkcode@modelcontextprotocol/client!client/streamableHttp.StreamableHTTPClientTransport | StreamableHTTPClientTransport} to enable this — the SDK provides built-in providers for common machine-to-machine flows, or you can implement the full {@linkcode@modelcontextprotocol/client!client/auth.OAuthClientProvider | OAuthClientProvider} interface for user-facing OAuth.
@@ -144,13 +157,19 @@ For a complete working OAuth flow, see [`simpleOAuthClient.ts`](https://github.c
144
157
145
158
Tools are callable actions offered by servers — discovering and invoking them is usually how your client enables an LLM to take action (see [Tools](https://modelcontextprotocol.io/docs/learn/server-concepts#tools) in the MCP overview).
146
159
147
-
Use {@linkcode@modelcontextprotocol/client!client/client.Client#listTools | listTools()} to discover available tools, and {@linkcode@modelcontextprotocol/client!client/client.Client#callTool | callTool()} to invoke one:
160
+
Use {@linkcode@modelcontextprotocol/client!client/client.Client#listTools | listTools()} to discover available tools, and {@linkcode@modelcontextprotocol/client!client/client.Client#callTool | callTool()} to invoke one. Results may be paginated — loop on `nextCursor` to collect all pages:
@@ -160,17 +179,52 @@ const result = await client.callTool({
160
179
console.log(result.content);
161
180
```
162
181
182
+
Tool results may include a `structuredContent` field — a machine-readable JSON object for programmatic use by the client application, complementing `content` which is for the LLM:
// Machine-readable output for the client application
191
+
if (result.structuredContent) {
192
+
console.log(result.structuredContent); // e.g. { bmi: 22.86 }
193
+
}
194
+
```
195
+
196
+
### Tracking progress
197
+
198
+
Pass `onprogress` to receive incremental progress notifications from long-running tools. Use `resetTimeoutOnProgress` to keep the request alive while the server is actively reporting, and `maxTotalTimeout` as an absolute cap:
Resources are read-only data — files, database schemas, configuration — that your application can retrieve from a server and attach as context for the model (see [Resources](https://modelcontextprotocol.io/docs/learn/server-concepts#resources) in the MCP overview).
166
214
167
-
Use {@linkcode@modelcontextprotocol/client!client/client.Client#listResources | listResources()} and {@linkcode@modelcontextprotocol/client!client/client.Client#readResource | readResource()} to discover and read server-provided data:
215
+
Use {@linkcode@modelcontextprotocol/client!client/client.Client#listResources | listResources()} and {@linkcode@modelcontextprotocol/client!client/client.Client#readResource | readResource()} to discover and read server-provided data. Results may be paginated — loop on `nextCursor` to collect all pages:
Prompts are reusable message templates that servers offer to help structure interactions with models (see [Prompts](https://modelcontextprotocol.io/docs/learn/server-concepts#prompts) in the MCP overview).
205
259
206
-
Use {@linkcode@modelcontextprotocol/client!client/client.Client#listPrompts | listPrompts()} and {@linkcode@modelcontextprotocol/client!client/client.Client#getPrompt | getPrompt()} to list available prompts and retrieve them with arguments:
260
+
Use {@linkcode@modelcontextprotocol/client!client/client.Client#listPrompts | listPrompts()} and {@linkcode@modelcontextprotocol/client!client/client.Client#getPrompt | getPrompt()} to list available prompts and retrieve them with arguments. Results may be paginated — loop on `nextCursor` to collect all pages:
0 commit comments