run_go_code
Execute Go code in the Go Playground sandbox and receive execution results, with optional go vet analysis for code quality checks.
Instructions
Run Go code in the Go Playground and return execution results
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The Go code to execute | |
| withVet | No | Whether to run go vet on the code (default: true) |
Implementation Reference
- src/mcp-server.ts:216-228 (handler)MCP server handler function for the 'run_go_code' tool. It extracts arguments, calls the Go playground client to run the code, formats the response, and handles errors.const createRunGoCodeHandler = (client: ReturnType<typeof createGoPlaygroundClient>) => async (args: RunGoCodeArgs): Promise<MCPToolResponse> => { try { const { code, withVet = true } = args; const result = await client.runCode(code, withVet); const responseText = formatRunResponse(result); return createSuccessResponse(responseText); } catch (error) { console.error('Error in handleRunGoCode:', error); return createErrorResponse(error); } };
- src/go-playground-client.ts:113-159 (handler)Core implementation that validates Go code, sends it to the Go Playground API (/compile), processes the response including events and errors, and returns the execution result.export const runGoCode = (config: Partial<GoPlaygroundConfig> = {}) => async ( code: string, withVet: boolean = true ): Promise<MCPGoPlaygroundResult> => { // Validate input const validationResult = validateGoCode(code); if (!validationResult.success) { return { success: false, errors: validationResult.error.message, }; } const finalConfig = { ...createDefaultConfig(), ...config }; const client = createHttpClient(finalConfig); try { const request: GoPlaygroundRunRequest = { version: 2, body: validationResult.data, withVet, }; const response = await client.post<GoPlaygroundResponse>( '/compile', request, { headers: { 'Content-Type': 'application/json', }, } ); // Debug logging console.error( 'Go Playground API Response:', JSON.stringify(response.data, null, 2) ); return processRunResponse(response.data); } catch (error) { console.error('Go Playground API Error:', error); return handleApiError(error); } };
- src/mcp-server.ts:49-67 (schema)MCP tool schema definition for 'run_go_code', including name, description, input schema with properties for code and withVet.{ name: TOOL_NAMES.RUN_GO_CODE, description: 'Run Go code in the Go Playground and return execution results', inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'The Go code to execute', }, withVet: { type: 'boolean', description: 'Whether to run go vet on the code (default: true)', default: true, }, }, required: ['code'], },
- src/mcp-server.ts:300-306 (registration)Registration of all tool handlers, including 'run_go_code', in the handlers object used by the tool router.const handlers = { [TOOL_NAMES.RUN_GO_CODE]: createRunGoCodeHandler(client), [TOOL_NAMES.SHARE_GO_CODE]: createShareGoCodeHandler(client), [TOOL_NAMES.RUN_AND_SHARE_GO_CODE]: createRunAndShareGoCodeHandler(client), [TOOL_NAMES.READ_GO_PLAYGROUND_URL]: createReadGoPlaygroundUrlHandler(client), [TOOL_NAMES.EXECUTE_GO_PLAYGROUND_URL]: createExecuteGoPlaygroundUrlHandler(client), } as const;
- src/types.ts:70-73 (schema)TypeScript type definition for the input arguments of the 'run_go_code' tool.export type RunGoCodeArgs = { readonly code: GoCode; readonly withVet?: boolean; };