SEP-1036: URL Elicitation (#1105)
This commit is contained in:
parent
df56e35322
commit
4debc740a5
1 changed files with 3532 additions and 226 deletions
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Reference in a new issue