Skip to content

Commit c72ec30

Browse files
author
User
committed
fix: remove trailing whitespace in send() method
1 parent 5bfe860 commit c72ec30

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

packages/server/src/server/mcp.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,16 @@ export class McpServer {
166166
);
167167

168168
this.server.setRequestHandler('tools/call', async (request, ctx): Promise<CallToolResult | CreateTaskResult> => {
169+
// Tool lookup errors are JSON-RPC errors, not tool errors
170+
const tool = this._registeredTools[request.params.name];
171+
if (!tool) {
172+
throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Tool ${request.params.name} not found`);
173+
}
174+
if (!tool.enabled) {
175+
throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Tool ${request.params.name} disabled`);
176+
}
177+
169178
try {
170-
const tool = this._registeredTools[request.params.name];
171-
if (!tool) {
172-
throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Tool ${request.params.name} not found`);
173-
}
174-
if (!tool.enabled) {
175-
throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Tool ${request.params.name} disabled`);
176-
}
177179

178180
const isTaskRequest = !!request.params.task;
179181
const taskSupport = tool.execution?.taskSupport;
@@ -213,9 +215,8 @@ export class McpServer {
213215
await this.validateToolOutput(tool, result, request.params.name);
214216
return result;
215217
} catch (error) {
216-
if (error instanceof ProtocolError) {
217-
// Protocol errors should be returned as JSON-RPC errors, not wrapped in CallToolResult
218-
throw error;
218+
if (error instanceof ProtocolError && error.code === ProtocolErrorCode.UrlElicitationRequired) {
219+
throw error; // Return the error to the caller without wrapping in CallToolResult
219220
}
220221
return this.createToolError(error instanceof Error ? error.message : String(error));
221222
}

packages/server/src/server/stdio.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ export class StdioServerTransport implements Transport {
9999
send(message: JSONRPCMessage): Promise<void> {
100100
return new Promise((resolve, reject) => {
101101
const json = serializeMessage(message);
102-
102+
103103
// Handle write errors (e.g., EPIPE when client disconnects)
104104
const onError = (error: Error) => {
105105
this._stdout.off('error', onError);
106106
reject(error);
107107
};
108-
108+
109109
this._stdout.once('error', onError);
110-
110+
111111
if (this._stdout.write(json)) {
112112
this._stdout.off('error', onError);
113113
resolve();

0 commit comments

Comments
 (0)