Skip to main content
Glama
elias-michaias

Onyx Documentation MCP Server

run_onyx_code

Execute Onyx code to test and debug programs by running code snippets and returning output or errors.

Instructions

Execute Onyx code and return the output/errors for testing and debugging

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesOnyx code to execute
filenameNoOptional filename (defaults to temp.onyx)temp.onyx
timeoutNoExecution timeout in seconds

Implementation Reference

  • Main handler function that implements the 'run_onyx_code' tool logic: writes Onyx code to temp file, executes with 'onyx run', captures stdout/stderr/execution time, handles timeout and errors, formats MCP response.
    async runOnyxCode(code, filename = 'temp.onyx', timeout = 10) {
      const toolMessage = `Executing Onyx code to test and validate functionality`;
      
      try {
        // Create a temporary directory for code execution
        const tempDir = path.join(this.dataDir, 'temp');
        await fs.mkdir(tempDir, { recursive: true });
        
        // Write the code to a temporary file
        const filePath = path.join(tempDir, filename);
        await fs.writeFile(filePath, code, 'utf8');
        
        // Execute the Onyx code
        const result = await this.executeOnyxFile(filePath, timeout);
        
        // Clean up the temporary file
        try {
          await fs.unlink(filePath);
        } catch (cleanupError) {
          // Ignore cleanup errors
        }
        
        // Format the response with execution results
        const response = {
          success: result.success,
          exitCode: result.exitCode,
          stdout: result.stdout,
          stderr: result.stderr,
          executionTime: result.executionTime,
          filename: filename,
          codeLength: code.length
        };
        
        return this.formatResponse(JSON.stringify(response, null, 2), toolMessage);
        
      } catch (error) {
        const errorResponse = {
          success: false,
          error: error.message,
          filename: filename,
          codeLength: code.length
        };
        
        return this.formatResponse(JSON.stringify(errorResponse, null, 2), toolMessage);
      }
    }
  • Input schema definition for the 'run_onyx_code' tool, specifying parameters: code (required string), filename (optional string), timeout (optional number).
    inputSchema: {
      type: 'object',
      properties: {
        code: { type: 'string', description: 'Onyx code to execute' },
        filename: { type: 'string', description: 'Optional filename (defaults to temp.onyx)', default: 'temp.onyx' },
        timeout: { type: 'number', description: 'Execution timeout in seconds', default: 10 }
      },
      required: ['code']
    }
  • Tool registration in TOOL_DEFINITIONS array, including name, description, and input schema.
    {
      name: 'run_onyx_code',
      description: 'Execute Onyx code and return the output/errors for testing and debugging',
      inputSchema: {
        type: 'object',
        properties: {
          code: { type: 'string', description: 'Onyx code to execute' },
          filename: { type: 'string', description: 'Optional filename (defaults to temp.onyx)', default: 'temp.onyx' },
          timeout: { type: 'number', description: 'Execution timeout in seconds', default: 10 }
        },
        required: ['code']
      }
    },
  • Dispatcher switch case in executeTool method that routes 'run_onyx_code' calls to the runOnyxCode handler.
    case 'run_onyx_code':
      return await this.runOnyxCode(args.code, args.filename, args.timeout);
  • Helper function executeOnyxFile used by runOnyxCode to spawn 'onyx run' process, handle stdout/stderr, timeout, errors, and resolve with execution results.
    async executeOnyxFile(filePath, timeoutSeconds = 10) {
      return new Promise((resolve) => {
        const startTime = Date.now();
        let stdout = '';
        let stderr = '';
        let finished = false;
        
        // Try to run with 'onyx run' first
        const child = spawn('onyx', ['run', filePath], {
          stdio: ['pipe', 'pipe', 'pipe'],
          cwd: path.dirname(filePath)
        });
        
        // Set up timeout
        const timer = setTimeout(() => {
          if (!finished) {
            finished = true;
            child.kill('SIGTERM');
            resolve({
              success: false,
              exitCode: -1,
              stdout: stdout,
              stderr: stderr + '\n[TIMEOUT] Execution exceeded ' + timeoutSeconds + ' seconds',
              executionTime: Date.now() - startTime
            });
          }
        }, timeoutSeconds * 1000);
        
        // Collect stdout
        child.stdout.on('data', (data) => {
          stdout += data.toString();
        });
        
        // Collect stderr
        child.stderr.on('data', (data) => {
          stderr += data.toString();
        });
        
        // Handle process completion
        child.on('close', (code) => {
          if (!finished) {
            finished = true;
            clearTimeout(timer);
            
            resolve({
              success: code === 0,
              exitCode: code,
              stdout: stdout,
              stderr: stderr,
              executionTime: Date.now() - startTime
            });
          }
        });
        
        // Handle process errors (e.g., 'onyx' command not found)
        child.on('error', (error) => {
          if (!finished) {
            finished = true;
            clearTimeout(timer);
            
            resolve({
              success: false,
              exitCode: -1,
              stdout: stdout,
              stderr: `Error executing Onyx: ${error.message}\n\nNote: Make sure 'onyx' is installed and available in PATH.\nInstall from: https://onyxlang.io/install`,
              executionTime: Date.now() - startTime
            });
          }
        });
      });
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states that the tool executes code and returns output/errors, but it lacks details on execution environment, security implications, error handling, or performance characteristics. For a code execution tool without annotations, this is a significant gap in transparency.

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

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's function and purpose without unnecessary words. It is front-loaded with the core action and outcome, making it easy to understand quickly. Every part of the sentence earns its place by conveying essential information.

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

Completeness3/5

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

Given the tool's complexity (code execution with potential side effects), lack of annotations, and no output schema, the description is minimally adequate. It covers the basic purpose but fails to address critical aspects like execution safety, error formats, or output structure. For a tool in this context, more completeness is needed to guide effective use.

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?

The input schema has 100% description coverage, clearly documenting the parameters (code, filename, timeout) with their types and defaults. The description does not add any additional semantic meaning beyond what the schema provides, such as explaining parameter interactions or constraints. Baseline score of 3 is appropriate as the schema handles the heavy lifting.

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

Purpose4/5

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

The description clearly states the action ('Execute Onyx code') and the outcome ('return the output/errors for testing and debugging'), making the purpose evident. However, it does not explicitly differentiate this tool from its sibling 'build_onyx_code', which might also involve code execution or compilation, leaving some ambiguity in sibling distinction.

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?

The description mentions 'for testing and debugging', which provides a general context for usage, but it does not specify when to use this tool versus alternatives like 'build_onyx_code' or 'run_wasm'. No explicit guidance on prerequisites, exclusions, or comparisons with siblings is provided, limiting its utility for decision-making.

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/elias-michaias/onyx_mcp'

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