run_and_share_go_code
Execute Go code in a sandbox environment and generate a shareable URL to distribute your code snippets with execution results.
Instructions
Run Go code and get both execution results and a shareable URL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The Go code to execute and share | |
| withVet | No | Whether to run go vet on the code (default: true) |
Implementation Reference
- src/mcp-server.ts:248-260 (handler)MCP handler for the 'run_and_share_go_code' tool. Validates arguments using isRunAndShareGoCodeArgs (in switch), executes via client.runAndShare, formats success/failure response.const createRunAndShareGoCodeHandler = (client: ReturnType<typeof createGoPlaygroundClient>) => async (args: RunAndShareGoCodeArgs): Promise<MCPToolResponse> => { try { const { code, withVet = true } = args; const result = await client.runAndShare(code, withVet); const responseText = formatRunAndShareResponse(result); return createSuccessResponse(responseText); } catch (error) { console.error('Error in handleRunAndShareGoCode:', error); return createErrorResponse(error); } };
- src/go-playground-client.ts:201-238 (handler)Core implementation logic for running Go code and generating share URL. Validates code, calls runGoCode and shareGoCode concurrently, merges results into MCPGoPlaygroundResult.export const runAndShareGoCode = (config: Partial<GoPlaygroundConfig> = {}) => async ( code: string, withVet: boolean = true ): Promise<MCPGoPlaygroundResult> => { // Validate input once const validationResult = validateGoCode(code); if (!validationResult.success) { return { success: false, errors: validationResult.error.message, }; } const validatedCode = validationResult.data; // Create functions with config const runCode = runGoCode(config); const shareCode = shareGoCode(config); // Execute both operations const runResult = await runCode(validatedCode, withVet); const shareUrl = await shareCode(validatedCode); // Merge results based on discriminated union if (runResult.success) { return { ...runResult, shareUrl: shareUrl ?? undefined, } satisfies MCPGoPlaygroundSuccess; } else { return { ...runResult, shareUrl: shareUrl ?? undefined, } satisfies MCPGoPlaygroundFailure; } };
- src/mcp-server.ts:300-306 (registration)Registration of the run_and_share_go_code handler in the tool router's handlers map.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/mcp-server.ts:83-102 (schema)Tool registration block including JSON inputSchema for run_and_share_go_code.{ name: TOOL_NAMES.RUN_AND_SHARE_GO_CODE, description: 'Run Go code and get both execution results and a shareable URL', inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'The Go code to execute and share', }, withVet: { type: 'boolean', description: 'Whether to run go vet on the code (default: true)', default: true, }, }, required: ['code'], }, },
- src/types.ts:79-82 (schema)TypeScript type definition for tool arguments.export type RunAndShareGoCodeArgs = { readonly code: GoCode; readonly withVet?: boolean; };
- src/types.ts:180-191 (helper)Type guard for validating run_and_share_go_code arguments.export const isRunAndShareGoCodeArgs = ( args: unknown ): args is RunAndShareGoCodeArgs => { return ( typeof args === 'object' && args !== null && 'code' in args && isGoCode((args as Record<string, unknown>).code) && (!('withVet' in args) || typeof (args as Record<string, unknown>).withVet === 'boolean') ); };