Skip to content

Commit aa577f3

Browse files
committed
fixup working example
1 parent ba17b3e commit aa577f3

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/server/mcp.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ export class McpServer {
178178
}
179179
} catch (error) {
180180
if (error instanceof McpError) {
181-
throw error; // Let the error bubble up to the caller
181+
if (error.code === ErrorCode.UrlElicitationRequired) {
182+
throw error; // Return the error to the caller without wrapping in CallToolResult
183+
}
182184
}
183185
return this.createToolError(error instanceof Error ? error.message : String(error));
184186
}

src/shared/protocol.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export abstract class Protocol<SendRequestT extends Request, SendNotificationT e
250250
const totalElapsed = Date.now() - info.startTime;
251251
if (info.maxTotalTimeout && totalElapsed >= info.maxTotalTimeout) {
252252
this._timeoutInfo.delete(messageId);
253-
throw new McpError(ErrorCode.RequestTimeout, 'Maximum total timeout exceeded', {
253+
throw McpError.fromError(ErrorCode.RequestTimeout, 'Maximum total timeout exceeded', {
254254
maxTotalTimeout: info.maxTotalTimeout,
255255
totalElapsed
256256
});
@@ -313,7 +313,7 @@ export abstract class Protocol<SendRequestT extends Request, SendNotificationT e
313313
this._transport = undefined;
314314
this.onclose?.();
315315

316-
const error = new McpError(ErrorCode.ConnectionClosed, 'Connection closed');
316+
const error = McpError.fromError(ErrorCode.ConnectionClosed, 'Connection closed');
317317
for (const handler of responseHandlers.values()) {
318318
handler(error);
319319
}
@@ -567,7 +567,7 @@ export abstract class Protocol<SendRequestT extends Request, SendNotificationT e
567567
});
568568

569569
const timeout = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
570-
const timeoutHandler = () => cancel(new McpError(ErrorCode.RequestTimeout, 'Request timed out', { timeout }));
570+
const timeoutHandler = () => cancel(McpError.fromError(ErrorCode.RequestTimeout, 'Request timed out', { timeout }));
571571

572572
this._setupTimeout(messageId, timeout, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
573573

0 commit comments

Comments
 (0)