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' ;
44import { Tool } from '@modelcontextprotocol/sdk/types.js' ;
55import { 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