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
+92-11Lines changed: 92 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,9 +47,11 @@ The Model Context Protocol allows applications to provide context for LLMs in a
47
47
## Installation
48
48
49
49
```bash
50
-
npm install @modelcontextprotocol/sdk
50
+
npm install @modelcontextprotocol/sdk zod
51
51
```
52
52
53
+
This SDK has a **required peer dependency** on `zod` for schema validation. The SDK internally imports from `zod/v4`, but maintains backwards compatibility with projects using Zod v3.25 or later. You can use either API in your code by importing from `zod/v3` or `zod/v4`:
54
+
53
55
## Quick Start
54
56
55
57
Let's create a simple MCP server that exposes a calculator tool and some data. Save the following as `server.ts`:
@@ -58,7 +60,7 @@ Let's create a simple MCP server that exposes a calculator tool and some data. S
MCP servers can request additional information from users through the elicitation feature. This is useful for interactive workflows where the server needs user input or confirmation:
1180
+
MCP servers can request non-sensitive information from users through the form elicitation capability. This is useful for interactive workflows where the server needs user input or confirmation:
1179
1181
1180
1182
```typescript
1181
1183
// Server-side: Restaurant booking tool that asks for alternatives
@@ -1208,6 +1210,7 @@ server.registerTool(
1208
1210
if (!available) {
1209
1211
// Ask user if they want to try alternative dates
1210
1212
const result =awaitserver.server.elicitInput({
1213
+
mode: 'form',
1211
1214
message: `No tables available at ${restaurant} on ${date}. Would you like to check alternative dates?`,
1212
1215
requestedSchema: {
1213
1216
type: 'object',
@@ -1274,7 +1277,7 @@ server.registerTool(
1274
1277
);
1275
1278
```
1276
1279
1277
-
Client-side: Handle elicitation requests
1280
+
On the client side, handle form elicitation requests:
1278
1281
1279
1282
```typescript
1280
1283
// This is a placeholder - implement based on your UI framework
**Note**: Elicitation requires client support. Clients must declare the `elicitation` capability during initialization.
1305
+
When calling `server.elicitInput`, prefer to explicitly set `mode: 'form'` for new code. Omitting the mode continues to work for backwards compatibility and defaults to form elicitation.
1306
+
1307
+
Elicitation is a client capability. Clients must declare the `elicitation` capability during initialization:
1308
+
1309
+
```typescript
1310
+
const client =newClient(
1311
+
{
1312
+
name: 'example-client',
1313
+
version: '1.0.0'
1314
+
},
1315
+
{
1316
+
capabilities: {
1317
+
elicitation: {
1318
+
form: {}
1319
+
}
1320
+
}
1321
+
}
1322
+
);
1323
+
```
1324
+
1325
+
**Note**: Form elicitation **must** only be used to gather non-sensitive information. For sensitive information such as API keys or secrets, use URL elicitation instead.
1326
+
1327
+
### Eliciting URL Actions
1328
+
1329
+
MCP servers can prompt the user to perform a URL-based action through URL elicitation. This is useful for securely gathering sensitive information such as API keys or secrets, or for redirecting users to secure web-based flows.
1330
+
1331
+
```typescript
1332
+
// Server-side: Prompt the user to navigate to a URL
0 commit comments