Skip to content

Commit 96ff857

Browse files
Merge branch 'main' into request-propagation-in-tools
2 parents 71abccb + ebf8e2d commit 96ff857

37 files changed

+2180
-134
lines changed

.git-blame-ignore-revs

Whitespace-only changes.

README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,109 @@ const transport = new StdioServerTransport();
849849
await server.connect(transport);
850850
```
851851

852+
### Eliciting User Input
853+
854+
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:
855+
856+
```typescript
857+
// Server-side: Restaurant booking tool that asks for alternatives
858+
server.tool(
859+
"book-restaurant",
860+
{
861+
restaurant: z.string(),
862+
date: z.string(),
863+
partySize: z.number()
864+
},
865+
async ({ restaurant, date, partySize }) => {
866+
// Check availability
867+
const available = await checkAvailability(restaurant, date, partySize);
868+
869+
if (!available) {
870+
// Ask user if they want to try alternative dates
871+
const result = await server.server.elicitInput({
872+
message: `No tables available at ${restaurant} on ${date}. Would you like to check alternative dates?`,
873+
requestedSchema: {
874+
type: "object",
875+
properties: {
876+
checkAlternatives: {
877+
type: "boolean",
878+
title: "Check alternative dates",
879+
description: "Would you like me to check other dates?"
880+
},
881+
flexibleDates: {
882+
type: "string",
883+
title: "Date flexibility",
884+
description: "How flexible are your dates?",
885+
enum: ["next_day", "same_week", "next_week"],
886+
enumNames: ["Next day", "Same week", "Next week"]
887+
}
888+
},
889+
required: ["checkAlternatives"]
890+
}
891+
});
892+
893+
if (result.action === "accept" && result.content?.checkAlternatives) {
894+
const alternatives = await findAlternatives(
895+
restaurant,
896+
date,
897+
partySize,
898+
result.content.flexibleDates as string
899+
);
900+
return {
901+
content: [{
902+
type: "text",
903+
text: `Found these alternatives: ${alternatives.join(", ")}`
904+
}]
905+
};
906+
}
907+
908+
return {
909+
content: [{
910+
type: "text",
911+
text: "No booking made. Original date not available."
912+
}]
913+
};
914+
}
915+
916+
// Book the table
917+
await makeBooking(restaurant, date, partySize);
918+
return {
919+
content: [{
920+
type: "text",
921+
text: `Booked table for ${partySize} at ${restaurant} on ${date}`
922+
}]
923+
};
924+
}
925+
);
926+
```
927+
928+
Client-side: Handle elicitation requests
929+
930+
```typescript
931+
// This is a placeholder - implement based on your UI framework
932+
async function getInputFromUser(message: string, schema: any): Promise<{
933+
action: "accept" | "reject" | "cancel";
934+
data?: Record<string, any>;
935+
}> {
936+
// This should be implemented depending on the app
937+
throw new Error("getInputFromUser must be implemented for your platform");
938+
}
939+
940+
client.setRequestHandler(ElicitRequestSchema, async (request) => {
941+
const userResponse = await getInputFromUser(
942+
request.params.message,
943+
request.params.requestedSchema
944+
);
945+
946+
return {
947+
action: userResponse.action,
948+
content: userResponse.action === "accept" ? userResponse.data : undefined
949+
};
950+
});
951+
```
952+
953+
**Note**: Elicitation requires client support. Clients must declare the `elicitation` capability during initialization.
954+
852955
### Writing MCP Clients
853956

854957
The SDK provides a high-level client interface:

eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,12 @@ export default tseslint.config(
1515
{ "argsIgnorePattern": "^_" }
1616
]
1717
}
18+
},
19+
{
20+
files: ["src/client/**/*.ts", "src/server/**/*.ts"],
21+
ignores: ["**/*.test.ts"],
22+
rules: {
23+
"no-console": "error"
24+
}
1825
}
1926
);

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@modelcontextprotocol/sdk",
3-
"version": "1.12.3",
3+
"version": "1.13.1",
44
"description": "Model Context Protocol implementation for TypeScript",
55
"license": "MIT",
66
"author": "Anthropic, PBC (https://anthropic.com)",
@@ -36,8 +36,11 @@
3636
],
3737
"scripts": {
3838
"build": "npm run build:esm && npm run build:cjs",
39-
"build:esm": "tsc -p tsconfig.prod.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
40-
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
39+
"build:esm": "mkdir -p dist/esm && echo '{\"type\": \"module\"}' > dist/esm/package.json && tsc -p tsconfig.prod.json",
40+
"build:esm:w": "npm run build:esm -- -w",
41+
"build:cjs": "mkdir -p dist/cjs && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json && tsc -p tsconfig.cjs.json",
42+
"build:cjs:w": "npm run build:cjs -- -w",
43+
"examples:simple-server:w": "tsx --watch src/examples/server/simpleStreamableHttp.ts --oauth",
4144
"prepack": "npm run build:esm && npm run build:cjs",
4245
"lint": "eslint src/",
4346
"test": "jest",

0 commit comments

Comments
 (0)