Skip to main content
Glama

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
NameRequiredDescriptionDefault
codeYesThe Go code to execute and share
withVetNoWhether to run go vet on the code (default: true)

Implementation Reference

  • 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); } };
  • 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; } };
  • 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;
  • 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'], }, },
  • TypeScript type definition for tool arguments.
    export type RunAndShareGoCodeArgs = { readonly code: GoCode; readonly withVet?: boolean; };
  • 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') ); };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/samber/go-playground-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server