ai icon indicating copy to clipboard operation
ai copied to clipboard

feat(mcp): adding elicitation spec to 'MCPClient'

Open aayush-kapoor opened this issue 1 month ago • 2 comments

Background

As requested in #7978

For elicitation specs, refer here

Summary

Updated the spec so that createMCPClient has a elicitation handler. It now supports requests that the server might make to the client.

Manual Verification

  • [x] e2e example for testing, with a UI modal for sending user's preferences
  • [x] console example
  • [x] unit tests

Checklist

  • [x] Tests have been added / updated (for bug fixes / features)
  • [ ] Documentation has been added / updated (for bug fixes / features)
  • [x] A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)

Related Issues

Fixes #7978

aayush-kapoor avatar Nov 12 '25 18:11 aayush-kapoor

Is there any way to share what format things like date/time/duration should be provided

=== Elicitation Request ===
Step 1: Enter basic event information
Schema: {
  "type": "object",
  "properties": {
    "title": {
      "type": "string",
      "title": "Event Title",
      "description": "Name of the event",
      "minLength": 1
    },
    "description": {
      "type": "string",
      "title": "Description",
      "description": "Event description (optional)"
    }
  },
  "required": [
    "title"
  ]
}
Action (accept/decline/cancel) [accept]: accept
Event Title (required): test title
Description (optional): 

=== Elicitation Request ===
Step 2: Enter date and time
Schema: {
  "type": "object",
  "properties": {
    "date": {
      "type": "string",
      "title": "Date",
      "description": "Event date"
    },
    "startTime": {
      "type": "string",
      "title": "Start Time",
      "description": "Event start time (HH:MM)"
    },
    "duration": {
      "type": "integer",
      "title": "Duration",
      "description": "Duration in minutes",
      "minimum": 15,
      "maximum": 480
    }
  },
  "required": [
    "date",
    "startTime",
    "duration"
  ]
}
Action (accept/decline/cancel) [accept]: accept
Date (required): 2025-12-12
Start Time (required): 12:00:00
Duration (required): 0
TOOL RESULTS: [
  {
    "type": "tool-result",
    "toolCallId": "call_02yIVAMEQWCTA5QIfKhUdF6M",
    "toolName": "create_event",
    "input": {},
    "output": {
      "content": [
        {
          "type": "text",
          "text": "Event creation failed: MCP error -32602: Elicitation response content does not match requested schema: data.duration should be >= 15"
        }
      ],
      "isError": true
    },
    "dynamic": true
  }
]

gr2m avatar Nov 14 '25 16:11 gr2m

I tried the next-openai demo but nothing happens? I don't see any errors in the logs

image
GET /mcp-elicitation 200 in 496ms
 ○ Compiling /api/mcp-elicitation ...
 ✓ Compiled /api/mcp-elicitation in 1480ms (2799 modules)
 POST /api/mcp-elicitation 200 in 1630ms

gr2m avatar Nov 14 '25 16:11 gr2m

updated the PR to address all comments and added docs.

--

I tried the next-openai demo but nothing happens? I don't see any errors in the logs

@gr2m you will need to start the MCP server in another terminal to run the UI example. Apologies for unclear instructions before, you can refer the README.md on how to run the example

aayush-kapoor avatar Nov 24 '25 15:11 aayush-kapoor

✅ Backport PR created: https://github.com/vercel/ai/pull/10555

vercel-ai-sdk[bot] avatar Nov 24 '25 19:11 vercel-ai-sdk[bot]