Skip to main content
Glama
elias-michaias

Onyx Documentation MCP Server

build_onyx_code

Compile Onyx programming code into executable files by running the build command in a specified directory. This tool processes source code to generate working programs.

Instructions

Build Onyx code file using "onyx build" in a specified directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesOnyx code to build
filenameNoFilename for the Onyx filemain.onyx
directoryNoDirectory to build in (defaults to current working directory).
timeoutNoBuild timeout in seconds

Implementation Reference

  • The core handler function for the 'build_onyx_code' tool. It writes the provided Onyx code to a file in the specified directory, executes 'onyx build' command, captures output and errors, and returns formatted results.
    async buildOnyxCode(code, filename = 'main.onyx', directory = '.', timeout = 30) {
      const toolMessage = `Building Onyx code using "onyx build" in directory: ${directory}`;
      
      try {
        // Resolve the target directory
        const targetDir = path.resolve(directory);
        
        // Check if directory exists
        try {
          await fs.access(targetDir);
        } catch (error) {
          throw new Error(`Directory does not exist: ${targetDir}`);
        }
        
        // Write the code to the specified file in target directory
        const filePath = path.join(targetDir, filename);
        await fs.writeFile(filePath, code, 'utf8');
        
        // Build the Onyx code in target directory
        const result = await this.executeOnyxCommand(['build', filename], timeout, targetDir);
        
        // Format the response with build results
        const response = {
          success: result.success,
          exitCode: result.exitCode,
          stdout: result.stdout,
          stderr: result.stderr,
          executionTime: result.executionTime,
          command: `onyx build ${filename}`,
          filename: filename,
          codeLength: code.length,
          workingDirectory: targetDir
        };
        
        return this.formatResponse(JSON.stringify(response, null, 2), toolMessage);
        
      } catch (error) {
        const errorResponse = {
          success: false,
          error: error.message,
          command: `onyx build ${filename}`,
          filename: filename,
          codeLength: code.length,
          workingDirectory: directory
        };
        
        return this.formatResponse(JSON.stringify(errorResponse, null, 2), toolMessage);
      }
    }
  • The input schema and metadata definition for the 'build_onyx_code' tool, including name, description, and parameter specifications. This is part of the TOOL_DEFINITIONS array used for tool registration.
    {
      name: 'build_onyx_code',
      description: 'Build Onyx code file using "onyx build" in a specified directory',
      inputSchema: {
        type: 'object',
        properties: {
          code: { type: 'string', description: 'Onyx code to build' },
          filename: { type: 'string', description: 'Filename for the Onyx file', default: 'main.onyx' },
          directory: { type: 'string', description: 'Directory to build in (defaults to current working directory)', default: '.' },
          timeout: { type: 'number', description: 'Build timeout in seconds', default: 30 }
        },
        required: ['code']
      }
    },
  • The dispatch/registration point in the executeTool switch statement that routes calls to the buildOnyxCode handler function.
    case 'build_onyx_code':
      return await this.buildOnyxCode(args.code, args.filename, args.directory, args.timeout);
  • Helper function used by the build_onyx_code handler to spawn and manage the 'onyx' process, handling stdout/stderr capture, timeouts, and errors.
    // Helper method to execute Onyx commands (for build operations)
    async executeOnyxCommand(args, timeoutSeconds = 30, workingDirectory = null) {
      return new Promise((resolve) => {
        const startTime = Date.now();
        let stdout = '';
        let stderr = '';
        let finished = false;
        
        // Use specified directory or current working directory
        const cwd = workingDirectory || process.cwd();
        
        // Execute onyx command in specified directory
        const child = spawn('onyx', args, {
          stdio: ['pipe', 'pipe', 'pipe'],
          cwd: cwd
        });
        
        // Set up timeout
        const timer = setTimeout(() => {
          if (!finished) {
            finished = true;
            child.kill('SIGTERM');
            resolve({
              success: false,
              exitCode: -1,
              stdout: stdout,
              stderr: stderr + '\n[TIMEOUT] Build/command 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?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the build command and directory specification but lacks details on permissions needed, whether it modifies files or creates outputs, error handling, or rate limits. For a tool with 4 parameters and no 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 front-loads the core purpose without unnecessary details. Every word earns its place, making it highly concise and well-structured for quick understanding.

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?

Given the tool's complexity (4 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain what the build output entails (e.g., compiled files, errors), behavioral traits like side effects, or how it differs from sibling tools. This leaves gaps for an AI agent to correctly invoke and interpret results.

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 description coverage is 100%, so the schema fully documents all parameters. The description adds minimal value beyond the schema by implying the build occurs in a specified directory, but it doesn't provide additional context like parameter interactions or usage examples. Baseline 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 ('build') and resource ('Onyx code file'), specifying the command 'onyx build' and location context. It distinguishes from siblings like 'run_onyx_code' by focusing on compilation rather than execution, though it doesn't explicitly contrast with 'onyx_pkg_build' which might have overlapping functionality.

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 explicit guidance on when to use this tool versus alternatives is provided. The description implies usage for building Onyx code, but it doesn't mention when to choose this over 'run_onyx_code' (for execution) or 'onyx_pkg_build' (for package builds), leaving the agent to infer context without clear exclusions or prerequisites.

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