SEP-1036: URL Elicitation (#1105)

This commit is contained in:
Nate Barbettini 2025-11-18 02:53:15 -08:00 • committed by GitHub
commit 4debc740a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,7 +15,9 @@ import {
LoggingMessageNotificationSchema,
type Notification,
ReadResourceResultSchema,
type TextContent
type TextContent,
UrlElicitationRequiredError,
ErrorCode
} from '../types.js';
import { completable } from './completable.js';
import { McpServer, ResourceTemplate } from './mcp.js';
@ -1618,6 +1620,60 @@ describe('tool()', () => {
);
});
/***
* Test: URL Elicitation Required Error Propagation
*/
test('should propagate UrlElicitationRequiredError to client callers', async () => {
const mcpServer = new McpServer({
name: 'test server',
version: '1.0'
});
const client = new Client(
{
name: 'test client',
version: '1.0'
},
{
capabilities: {
elicitation: {
url: {}
}
}
}
);
const elicitationParams = {
mode: 'url' as const,
elicitationId: 'elicitation-123',
url: 'https://mcp.example.com/connect',
message: 'Authorization required'
};
mcpServer.tool('needs-authorization', async () => {
throw new UrlElicitationRequiredError([elicitationParams], 'Confirmation required');
});
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);
await client
.callTool({
name: 'needs-authorization'
})
.then(() => {
throw new Error('Expected callTool to throw UrlElicitationRequiredError');
})
.catch(error => {
expect(error).toBeInstanceOf(UrlElicitationRequiredError);
if (error instanceof UrlElicitationRequiredError) {
expect(error.code).toBe(ErrorCode.UrlElicitationRequired);
expect(error.elicitations).toEqual([elicitationParams]);
}
});
});
/***
* Test: Tool Registration with _meta field
*/
@ -4098,6 +4154,7 @@ describe('elicitInput()', () => {
if (!available) {
// Ask user if they want to try alternative dates
const result = await mcpServer.server.elicitInput({
mode: 'form',
message: `No tables available at ${restaurant} on ${date}. Would you like to check alternative dates?`,
requestedSchema: {
type: 'object',