Skip to content

Commit 0371082

Browse files
fix(mcp): correct code tool api output types
1 parent 80ce57e commit 0371082

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

packages/mcp-server/src/code-tool-types.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
import { ClientOptions } from '@imagekit/nodejs';
44

55
export type WorkerInput = {
6-
opts: ClientOptions;
6+
project_name: string;
77
code: string;
8+
client_opts: ClientOptions;
89
};
9-
export type WorkerSuccess = {
10+
export type WorkerOutput = {
11+
is_error: boolean;
1012
result: unknown | null;
11-
logLines: string[];
12-
errLines: string[];
13-
};
14-
export type WorkerError = {
15-
message: string | undefined;
16-
logLines: string[];
17-
errLines: string[];
13+
log_lines: string[];
14+
err_lines: string[];
1815
};

packages/mcp-server/src/code-tool.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
import { McpTool, Metadata, ToolCallResult, asTextContentResult } from './types';
3+
import { McpTool, Metadata, ToolCallResult, asErrorResult, asTextContentResult } from './types';
44
import { Tool } from '@modelcontextprotocol/sdk/types.js';
55
import { readEnv } from './server';
6-
import { WorkerSuccess } from './code-tool-types';
6+
import { WorkerInput, WorkerOutput } from './code-tool-types';
77
/**
88
* A tool that runs code against a copy of the SDK.
99
*
@@ -44,9 +44,9 @@ export function codeTool(): McpTool {
4444
},
4545
body: JSON.stringify({
4646
project_name: 'imagekit',
47-
client_opts: {},
4847
code,
49-
}),
48+
client_opts: {},
49+
} satisfies WorkerInput),
5050
});
5151

5252
if (!res.ok) {
@@ -57,7 +57,17 @@ export function codeTool(): McpTool {
5757
);
5858
}
5959

60-
return asTextContentResult((await res.json()) as WorkerSuccess);
60+
const { is_error, result, log_lines, err_lines } = (await res.json()) as WorkerOutput;
61+
const hasLogs = log_lines.length > 0 || err_lines.length > 0;
62+
const output = {
63+
result,
64+
...(log_lines.length > 0 && { log_lines }),
65+
...(err_lines.length > 0 && { err_lines }),
66+
};
67+
if (is_error) {
68+
return asErrorResult(typeof result === 'string' && !hasLogs ? result : JSON.stringify(output, null, 2));
69+
}
70+
return asTextContentResult(output);
6171
};
6272

6373
return { metadata, tool, handler };

0 commit comments

Comments
 (0)