Skip to main content
Glama
samber

Go Playground MCP Server

by samber

run_go_code

Execute Go code in the Go Playground sandbox and return results, with optional go vet analysis for code quality.

Instructions

Run Go code in the Go Playground and return execution results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesThe Go code to execute
withVetNoWhether to run go vet on the code (default: true)

Implementation Reference

  • MCP tool handler for 'run_go_code'. Creates a handler that destructures args (code, withVet), calls client.runCode(), 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);
        }
      };
  • Core execution function for running Go code. Validates input via validateGoCode, constructs a request to the Go Playground /compile API, processes the response via processRunResponse, and returns a typed 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);
        }
      };
  • Helper function that processes the Go Playground API response, checking for compilation errors, runtime errors (stderr), and extracting stdout output.
    const processRunResponse = (
      result: GoPlaygroundResponse
    ): MCPGoPlaygroundResult => {
      // Validate response structure
      if (!result || typeof result !== 'object') {
        return {
          success: false,
          errors: 'Invalid response from Go Playground API',
        };
      }
    
      // Check for compilation errors (Errors field contains compilation errors)
      if (result.Errors && result.Errors.trim() !== '') {
        return {
          success: false,
          errors: result.Errors,
          exitCode: result.Status,
        };
      }
    
      // Check for runtime errors (runtime errors appear in Events with Kind: 'stderr')
      const stderrEvents =
        result.Events?.filter(event => event.Kind === 'stderr') ?? [];
      if (stderrEvents.length > 0) {
        const errorMessages = stderrEvents.map(event => event.Message).join('');
        return {
          success: false,
          errors: errorMessages,
          exitCode: result.Status,
        };
      }
    
      // Process output using functional approach
      const processedOutput = processEvents(result.Events ?? []);
    
      return {
        success: true,
        output: processedOutput.output,
        exitCode: result.Status,
      };
    };
  • Type definition for run_go_code arguments: code (branded GoCode string) and optional withVet boolean.
    export type RunGoCodeArgs = {
      readonly code: GoCode;
      readonly withVet?: boolean;
    };
  • Tool definition/schema registration for 'run_go_code' with name, description, and inputSchema (code as required string, withVet as optional boolean).
    const createToolDefinitions = (): readonly Tool[] =>
      [
        {
          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'],
          },
        },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description should disclose behaviors like sandbox limitations, error handling, or side effects, but only states 'return execution results'—failing to mention that the code runs in a restricted environment or what happens on failure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, front-loaded sentence with no redundancy. However, it could incorporate brief parameter or behavior details without sacrificing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite low complexity and no output schema, the description fails to specify output format (e.g., stdout, stderr) or mention sibling differentiation, leaving the agent with incomplete information for safe invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the description adds no extra meaning beyond the parameter names and defaults. It aligns with the code parameter but offers no additional context like the effect of 'withVet'.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Run Go code in the Go Playground' with a specific verb and resource, and distinguishes this tool from siblings like 'execute_go_playground_url' and 'run_and_share_go_code' by focusing on execution alone.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives from the sibling list (e.g., 'run_and_share_go_code' or 'execute_go_playground_url'), leaving the agent to infer usage without comparison.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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