chore: add instructions docs (#1778)

This commit is contained in:
Konstantin Konstantinov 2026-03-27 14:19:32 +02:00 • committed by GitHub
commit 5516c1ba66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 0 deletions

View file

@ -330,6 +330,26 @@ server.registerTool(
>
> For protocol details, see [Logging](https://modelcontextprotocol.io/specification/latest/server/utilities/logging) in the MCP specification.
## Instructions
Pass an `instructions` string in the server options to describe how to use the server and its features. This can be used by clients to improve the LLM's understanding of available tools, resources, and prompts. It can be thought of like a "hint" to the model — for example, a client MAY add it to the system prompt. See [Instructions](https://modelcontextprotocol.io/specification/latest/basic/lifecycle#instructions) in the MCP specification.
```ts source="../examples/server/src/serverGuide.examples.ts#instructions_basic"
const server = new McpServer(
{
name: 'multi-tool-server',
version: '1.0.0'
},
{
instructions: `This server provides data-pipeline tools. Always call "validate-schema"
before calling "transform-data" to avoid runtime errors.`
}
);
```
> [!TIP]
> Use instructions for cross-tool relationships, workflow ordering, and constraints that individual tool descriptions cannot express on their own.
## Server‑initiated requests
MCP is bidirectional — servers can also send requests *to* the client during tool execution, as long as the client declares matching capabilities.

View file

@ -15,6 +15,27 @@ import type { CallToolResult, ResourceLink } from '@modelcontextprotocol/server'
import { completable, McpServer, ResourceTemplate, StdioServerTransport } from '@modelcontextprotocol/server';
import * as z from 'zod/v4';
// ---------------------------------------------------------------------------
// Instructions
// ---------------------------------------------------------------------------
/** Example: Providing server instructions to guide LLM usage. */
function instructions_basic() {
//#region instructions_basic
const server = new McpServer(
{
name: 'multi-tool-server',
version: '1.0.0'
},
{
instructions: `This server provides data-pipeline tools. Always call "validate-schema"
before calling "transform-data" to avoid runtime errors.`
}
);
//#endregion instructions_basic
return server;
}
// ---------------------------------------------------------------------------
// Tools, resources, and prompts
// ---------------------------------------------------------------------------
@ -373,6 +394,7 @@ function dnsRebinding_allowedHosts() {
}
// Suppress unused-function warnings (functions exist solely for type-checking)
void instructions_basic;
void registerTool_basic;
void registerTool_resourceLink;
void registerTool_logging;