Skip to content

Commit 1a412ec

Browse files
fix(mcp): correct code tool api output types
1 parent 72c2bdd commit 1a412ec

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 '@tryfinch/finch-api';
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
*
@@ -45,9 +45,9 @@ export function codeTool(): McpTool {
4545
},
4646
body: JSON.stringify({
4747
project_name: 'finch',
48-
client_opts: { accessToken: readEnv('FINCH_ACCESS_TOKEN') },
4948
code,
50-
}),
49+
client_opts: { accessToken: readEnv('FINCH_ACCESS_TOKEN') },
50+
} satisfies WorkerInput),
5151
});
5252

5353
if (!res.ok) {
@@ -58,7 +58,17 @@ export function codeTool(): McpTool {
5858
);
5959
}
6060

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

6474
return { metadata, tool, handler };

0 commit comments

Comments
 (0)