Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c6fc36c
SEP-1036: URL Elicitation
nbarbettini Nov 12, 2025
d2d2863
Update examples
nbarbettini Nov 12, 2025
469d804
Add elicitation utilities
nbarbettini Nov 11, 2025
05fb331
Rename elicitInput, split into form and URL methods
nbarbettini Nov 11, 2025
71af07b
New tests: Backwards compat for elicitation client capabilities obj
nbarbettini Nov 12, 2025
d9dff46
Small helper to build completion notifications
nbarbettini Nov 12, 2025
3794d45
Finish updating examples, rename
nbarbettini Nov 12, 2025
27e55b7
New test: UrlElicitationRequiredError thrown from tool is returned ve…
nbarbettini Nov 12, 2025
fd5b26e
New tests: client and server capability checks
nbarbettini Nov 12, 2025
1a02a6f
Bonus tests: ensure applyDefaults works
nbarbettini Nov 12, 2025
b057aac
Bonus tests: form elicitation schema validation safety
nbarbettini Nov 12, 2025
237f84c
Add examples to README
nbarbettini Nov 13, 2025
2c52cf1
Update official schema & schema tests
nbarbettini Nov 13, 2025
e4c28be
Restore elicitInput() as a deprecated method
nbarbettini Nov 13, 2025
eb9301d
Move getSupportedElicitationModes into client (not shared)
nbarbettini Nov 13, 2025
0bda0c0
Simplify Zod declaration and supported modes logic
nbarbettini Nov 13, 2025
4b4516f
Merge branch 'main' into feat/url-elicitation-final
nbarbettini Nov 13, 2025
f9de71f
Clean up syntax
nbarbettini Nov 14, 2025
62e7760
Move applyDefaults inside form
nbarbettini Nov 14, 2025
96f6434
Merge branch 'main' into feat/url-elicitation-final
nbarbettini Nov 14, 2025
383c596
jest -> vi for new tests
nbarbettini Nov 14, 2025
5603883
Merge branch 'main' into feat/url-elicitation-final
nbarbettini Nov 14, 2025
cf87350
Simplify preprocess
nbarbettini Nov 17, 2025
3159d99
Fix missing params in readme
nbarbettini Nov 17, 2025
cdaa754
Rebuild elicitInput() with overloads
nbarbettini Nov 17, 2025
7de4a7b
Merge branch 'main' into feat/url-elicitation-final
nbarbettini Nov 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 82 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ await server.connect(transport);

### Eliciting User Input

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:
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:

```typescript
// Server-side: Restaurant booking tool that asks for alternatives
Expand Down Expand Up @@ -1208,6 +1208,7 @@ server.registerTool(
if (!available) {
// Ask user if they want to try alternative dates
const result = await server.server.elicitInput({
mode: 'form',
message: `No tables available at ${restaurant} on ${date}. Would you like to check alternative dates?`,
requestedSchema: {
type: 'object',
Expand Down Expand Up @@ -1274,7 +1275,7 @@ server.registerTool(
);
```

Client-side: Handle elicitation requests
On the client side, handle form elicitation requests:

```typescript
// This is a placeholder - implement based on your UI framework
Expand All @@ -1299,7 +1300,85 @@ client.setRequestHandler(ElicitRequestSchema, async request => {
});
```

**Note**: Elicitation requires client support. Clients must declare the `elicitation` capability during initialization.
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.

Elicitation is a client capability. Clients must declare the `elicitation` capability during initialization:

```typescript
const client = new Client(
{
name: 'example-client',
version: '1.0.0'
},
{
capabilities: {
elicitation: {
form: {}
}
}
}
);
```

**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.

### Eliciting URL Actions

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.

```typescript
// Server-side: Prompt the user to navigate to a URL
const result = await server.server.elicitInput({
mode: 'url',
message: 'Please enter your API key',
elicitationId: '550e8400-e29b-41d4-a716-446655440000',
url: 'http://localhost:3000/api-key'
});

// Alternative, return an error from within a tool:
throw new UrlElicitationRequiredError([
{
mode: 'url',
message: 'This tool requires a payment confirmation. Open the link to confirm payment!',
url: `http://localhost:${MCP_PORT}/confirm-payment?session=${sessionId}&elicitation=${elicitationId}&cartId=${encodeURIComponent(cartId)}`,
elicitationId: '550e8400-e29b-41d4-a716-446655440000'
}
]);
```

On the client side, handle URL elicitation requests:

```typescript
client.setRequestHandler(ElicitRequestSchema, async request => {
if (request.params.mode !== 'url') {
throw new McpError(ErrorCode.InvalidParams, `Unsupported elicitation mode: ${request.params.mode}`);
}

// At a minimum, implement a UI that:
// - Display the full URL and server reason to prevent phishing
// - Explicitly ask the user for consent, with clear decline/cancel options
// - Open the URL in the system (not embedded) browser
// Optionally, listen for a `nofifications/elicitation/complete` message from the server
});
```

Elicitation is a client capability. Clients must declare the `elicitation` capability during initialization:

```typescript
const client = new Client(
{
name: 'example-client',
version: '1.0.0'
},
{
capabilities: {
elicitation: {
url: {}
}
}
}
);
```

### Writing MCP Clients

Expand Down
Loading
Loading