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
Copy file name to clipboardExpand all lines: README.md
+20-24Lines changed: 20 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@
11
11
-[Resources](#resources)
12
12
-[Tools](#tools)
13
13
-[Prompts](#prompts)
14
-
-[Completions](#completions)
14
+
-[Completions](#argument-completions)
15
15
-[Sampling](#sampling)
16
16
-[Running Your Server](#running-your-server)
17
17
-[stdio](#stdio)
@@ -32,7 +32,7 @@
32
32
33
33
## Overview
34
34
35
-
The Model Context Protocol allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. This TypeScript SDK implements the full MCP specification, making it easy to:
35
+
The Model Context Protocol (MCP) allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. This TypeScript SDK implements the full MCP specification, making it easy to:
36
36
37
37
- Build MCP clients that can connect to any MCP server
38
38
- Create MCP servers that expose resources, prompts and tools
@@ -45,7 +45,7 @@ The Model Context Protocol allows applications to provide context for LLMs in a
45
45
npm install @modelcontextprotocol/sdk
46
46
```
47
47
48
-
> ⚠️ MCP requires Node.js v18.x or higher to work fine.
48
+
> ⚠️ MCP requires Node.js v18.x or higher for maximum compatibility.
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io) lets you build servers that expose data and functionality to LLM applications in a secure, standardized way. Think of it like a web API, but specifically designed for LLM interactions. MCP servers can:
100
+
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io) lets you build servers that expose data and functionality to LLM applications in a secure, standardized way. Think of it like a web API, but specifically designed for LLM interactions.
101
+
MCP servers can:
101
102
102
103
- Expose data through **Resources** (think of these sort of like GET endpoints; they are used to load information into the LLM's context)
103
104
- Provide functionality through **Tools** (sort of like POST endpoints; they are used to execute code or otherwise produce a side effect)
@@ -185,7 +186,7 @@ server.registerResource(
185
186
186
187
### Tools
187
188
188
-
Tools let LLMs take actions through your server. Unlike resources, tools are expected to perform computation and have side effects:
189
+
Tools let LLMs take actions through your server. Unlike resources, tools are expected to perform computations and have side effects:
189
190
190
191
```typescript
191
192
// Simple tool with parameters
@@ -257,7 +258,7 @@ server.registerTool(
257
258
258
259
#### ResourceLinks
259
260
260
-
Tools can return `ResourceLink` objects to reference resources without embedding their full content. This is essential for performance when dealing with large files or many resources - clients can then selectively read only the resources they need using the provided URIs.
261
+
Tools can return `ResourceLink` objects to reference resources without embedding their full content. This is essential for performance when dealing with large files or many resources - clients can selectively read only the resources they need using the provided URIs.
261
262
262
263
### Prompts
263
264
@@ -321,11 +322,10 @@ server.registerPrompt(
321
322
);
322
323
```
323
324
324
-
### Completions
325
+
### Argument Completions
325
326
326
-
MCP supports argument completions to help users fill in prompt arguments and resource template parameters. See the examples above for [resource completions](#resources) and [prompt completions](#prompts).
327
-
328
-
#### Client Usage
327
+
See the examples above for [resource completions](#resources) and [prompt completions](#prompts).
328
+
MCP supports argument completions to help users fill in prompt arguments and resource template parameters:
329
329
330
330
```typescript
331
331
// Request completions for any argument
@@ -349,7 +349,7 @@ const result = await client.complete({
349
349
350
350
### Display Names and Metadata
351
351
352
-
All resources, tools, and prompts support an optional `title` field for better UI presentation. The `title` is used as a display name, while `name` remains the unique identifier.
352
+
All resources, tools, and prompts support an optional `title` field for better UI presentation. `title` is used as a display name, while `name` remains the unique identifier.
353
353
354
354
**Note:** The `register*` methods (`registerTool`, `registerPrompt`, `registerResource`) are the recommended approach for new code. The older methods (`tool`, `prompt`, `resource`) remain available for backwards compatibility.
355
355
@@ -359,7 +359,7 @@ For tools specifically, there are two ways to specify a title:
359
359
-`title` field in the tool configuration
360
360
-`annotations.title` field (when using the older `tool()` method with annotations)
361
361
362
-
The precedence order is: `title` → `annotations.title` → `name`
362
+
The precedence order is: `title` → `annotations.title` → `name`:
@@ -476,7 +476,7 @@ For remote servers, set up a Streamable HTTP transport that handles both client
476
476
477
477
#### With Session Management
478
478
479
-
In some cases, servers need to be stateful. This is achieved by[session management](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#session-management).
479
+
In some cases, servers need to be stateful. This is achieved with[session management](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#session-management):
480
480
481
481
```typescript
482
482
importexpressfrom"express";
@@ -570,7 +570,7 @@ app.listen(3000);
570
570
```
571
571
572
572
> [!TIP]
573
-
> When using this in a remote environment, make sure to allow the header parameter `mcp-session-id` in CORS. Otherwise, it may result in a `Bad Request: No valid session ID provided` error. Read the following section for examples.
573
+
> When using this in a remote environment, make sure to allow the header parameter `mcp-session-id` in CORS. Otherwise, it may result in a `Bad Request: No valid session ID provided` error. Read this following section for examples.
574
574
575
575
576
576
#### CORS Configuration for Browser-Based Clients
@@ -854,7 +854,7 @@ server.registerTool(
854
854
855
855
If you want to offer an initial set of tools/prompts/resources, but later add additional ones based on user action or external state change, you can add/update/remove them _after_ the Server is connected. This will automatically emit the corresponding `listChanged` notifications:
@@ -921,7 +921,7 @@ This feature coalesces multiple, rapid calls for the same notification type into
921
921
> [!IMPORTANT]
922
922
> This feature is designed for "simple" notifications that do not carry unique data in their parameters. To prevent silent data loss, debouncing is **automatically bypassed** for any notification that contains a `params` object or a `relatedRequestId`. Such notifications will always be sent immediately.
923
923
924
-
This is an opt-in feature configured during server initialization.
924
+
This is an opt-in feature configured during server initialization:
For more control, you can use the low-level Server class directly:
954
+
For more control, you can use the low-level `Server` class directly:
955
955
956
956
```typescript
957
957
import { Server } from"@modelcontextprotocol/sdk/server/index.js";
@@ -1211,11 +1211,7 @@ This setup allows you to:
1211
1211
1212
1212
### Backwards Compatibility
1213
1213
1214
-
Clients and servers with StreamableHttp transport can maintain [backwards compatibility](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#backwards-compatibility) with the deprecated HTTP+SSE transport (from protocol version 2024-11-05) as follows
1215
-
1216
-
#### Client-Side Compatibility
1217
-
1218
-
For clients that need to work with both Streamable HTTP and older SSE servers:
1214
+
Clients and servers with Streamable HTTP transport can maintain [backwards compatibility](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#backwards-compatibility) with the deprecated HTTP+SSE transport (from protocol version 2024-11-05) as follows:
0 commit comments