Skip to content

Commit cdaa754

Browse files
committed
Rebuild elicitInput() with overloads
1 parent 3159d99 commit cdaa754

File tree

9 files changed

+258
-119
lines changed

9 files changed

+258
-119
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,8 @@ server.registerTool(
12071207

12081208
if (!available) {
12091209
// Ask user if they want to try alternative dates
1210-
const result = await server.server.elicitFormInput({
1210+
const result = await server.server.elicitInput({
1211+
mode: 'form',
12111212
message: `No tables available at ${restaurant} on ${date}. Would you like to check alternative dates?`,
12121213
requestedSchema: {
12131214
type: 'object',
@@ -1299,6 +1300,8 @@ client.setRequestHandler(ElicitRequestSchema, async request => {
12991300
});
13001301
```
13011302

1303+
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.
1304+
13021305
Elicitation is a client capability. Clients must declare the `elicitation` capability during initialization:
13031306

13041307
```typescript
@@ -1325,7 +1328,8 @@ MCP servers can prompt the user to perform a URL-based action through URL elicit
13251328

13261329
```typescript
13271330
// Server-side: Prompt the user to navigate to a URL
1328-
const result = await server.server.elicitURLInput({
1331+
const result = await server.server.elicitInput({
1332+
mode: 'url',
13291333
message: 'Please enter your API key',
13301334
elicitationId: '550e8400-e29b-41d4-a716-446655440000',
13311335
url: 'http://localhost:3000/api-key'

src/client/index.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,8 @@ test('should accept form-mode elicitation request when client advertises empty e
643643
// Server should be able to send form-mode elicitation request
644644
// This works because getSupportedElicitationModes defaults to form mode
645645
// when neither form nor url are explicitly declared
646-
const result = await server.elicitFormInput({
646+
const result = await server.elicitInput({
647+
mode: 'form',
647648
message: 'Please provide your username',
648649
requestedSchema: {
649650
type: 'object',
@@ -883,7 +884,8 @@ test('should apply defaults for form-mode elicitation when applyDefaults is enab
883884

884885
await Promise.all([client.connect(clientTransport), server.connect(serverTransport)]);
885886

886-
const result = await server.elicitFormInput({
887+
const result = await server.elicitInput({
888+
mode: 'form',
887889
message: 'Please confirm your preferences',
888890
requestedSchema: {
889891
type: 'object',

src/examples/server/elicitationFormExample.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ mcpServer.registerTool(
3939
async () => {
4040
try {
4141
// Request user information through form elicitation
42-
const result = await mcpServer.server.elicitFormInput({
42+
const result = await mcpServer.server.elicitInput({
43+
mode: 'form',
4344
message: 'Please provide your registration information:',
4445
requestedSchema: {
4546
type: 'object',
@@ -137,7 +138,8 @@ mcpServer.registerTool(
137138
async () => {
138139
try {
139140
// Step 1: Collect basic event information
140-
const basicInfo = await mcpServer.server.elicitFormInput({
141+
const basicInfo = await mcpServer.server.elicitInput({
142+
mode: 'form',
141143
message: 'Step 1: Enter basic event information',
142144
requestedSchema: {
143145
type: 'object',
@@ -165,7 +167,8 @@ mcpServer.registerTool(
165167
}
166168

167169
// Step 2: Collect date and time
168-
const dateTime = await mcpServer.server.elicitFormInput({
170+
const dateTime = await mcpServer.server.elicitInput({
171+
mode: 'form',
169172
message: 'Step 2: Enter date and time',
170173
requestedSchema: {
171174
type: 'object',
@@ -239,7 +242,8 @@ mcpServer.registerTool(
239242
},
240243
async () => {
241244
try {
242-
const result = await mcpServer.server.elicitFormInput({
245+
const result = await mcpServer.server.elicitInput({
246+
mode: 'form',
243247
message: 'Please provide your shipping address:',
244248
requestedSchema: {
245249
type: 'object',

src/examples/server/elicitationUrlExample.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ const mcpPostHandler = async (req: Request, res: Response) => {
623623
console.log(`Session initialized with ID: ${sessionId}`);
624624
transports[sessionId] = transport;
625625
sessionsNeedingElicitation[sessionId] = {
626-
elicitationSender: server.server.elicitUrl.bind(server.server),
626+
elicitationSender: params => server.server.elicitInput(params),
627627
createCompletionNotifier: elicitationId => server.server.createElicitationCompletionNotifier(elicitationId)
628628
};
629629
}

src/examples/server/simpleStreamableHttp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ const getServer = () => {
215215

216216
try {
217217
// Use the underlying server instance to elicit input from the client
218-
const result = await server.server.elicitFormInput({
218+
const result = await server.server.elicitInput({
219+
mode: 'form',
219220
message,
220221
requestedSchema
221222
});

0 commit comments

Comments
 (0)