Skip to main content
Glama
elias-michaias

Onyx Documentation MCP Server

run_wasm

Execute WebAssembly files with the Onyx runtime by specifying file paths and execution parameters for running WASM code.

Instructions

Execute a WebAssembly (WASM) file using "onyx run file.wasm" command

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
wasmPathYesPath to the WASM file to execute
directoryNoDirectory to run the command from (defaults to current working directory).
timeoutNoExecution timeout in seconds

Implementation Reference

  • Main handler function that executes the specified WASM file using the 'onyx run' command. Validates paths, handles timeouts, captures stdout/stderr, and formats the MCP response.
    async runWasm(wasmPath, directory = '.', timeout = 10) {
      const toolMessage = `Executing WebAssembly file: ${wasmPath} using "onyx run" command`;
      
      try {
        // Resolve the target directory and WASM file path
        const targetDir = path.resolve(directory);
        let fullWasmPath;
        
        // If wasmPath is absolute, use it directly; otherwise, resolve relative to target directory
        if (path.isAbsolute(wasmPath)) {
          fullWasmPath = wasmPath;
        } else {
          fullWasmPath = path.resolve(targetDir, wasmPath);
        }
        
        // Check if directory exists
        try {
          await fs.access(targetDir);
        } catch (error) {
          throw new Error(`Directory does not exist: ${targetDir}`);
        }
        
        // Check if WASM file exists
        try {
          await fs.access(fullWasmPath);
        } catch (error) {
          throw new Error(`WASM file does not exist: ${fullWasmPath}`);
        }
        
        // Execute the WASM file using onyx run
        const result = await this.executeOnyxCommand(['run', fullWasmPath], timeout, targetDir);
        
        // Format the response with execution results
        const response = {
          success: result.success,
          exitCode: result.exitCode,
          stdout: result.stdout,
          stderr: result.stderr,
          executionTime: result.executionTime,
          command: `onyx run ${fullWasmPath}`,
          wasmPath: fullWasmPath,
          workingDirectory: targetDir
        };
        
        return this.formatResponse(JSON.stringify(response, null, 2), toolMessage);
        
      } catch (error) {
        const errorResponse = {
          success: false,
          error: error.message,
          command: `onyx run ${wasmPath}`,
          wasmPath: wasmPath,
          workingDirectory: directory
        };
        
        return this.formatResponse(JSON.stringify(errorResponse, null, 2), toolMessage);
      }
    }
  • Tool registration in the TOOL_DEFINITIONS array, defining the tool name, description, and input schema.
    {
      name: 'run_wasm',
      description: 'Execute a WebAssembly (WASM) file using "onyx run file.wasm" command',
      inputSchema: {
        type: 'object',
        properties: {
          wasmPath: { type: 'string', description: 'Path to the WASM file to execute' },
          directory: { type: 'string', description: 'Directory to run the command from (defaults to current working directory)', default: '.' },
          timeout: { type: 'number', description: 'Execution timeout in seconds', default: 10 }
        },
        required: ['wasmPath']
      }
    },
  • Input schema defining parameters for the run_wasm tool: wasmPath (required), directory, and timeout.
    inputSchema: {
      type: 'object',
      properties: {
        wasmPath: { type: 'string', description: 'Path to the WASM file to execute' },
        directory: { type: 'string', description: 'Directory to run the command from (defaults to current working directory)', default: '.' },
        timeout: { type: 'number', description: 'Execution timeout in seconds', default: 10 }
      },
      required: ['wasmPath']
    }
  • Dispatch case in the executeTool method that routes calls to the runWasm handler.
    case 'run_wasm':
      return await this.runWasm(args.wasmPath, args.directory, args.timeout);
  • Helper function used by runWasm to execute the 'onyx run' command process, handling spawn, timeout, and output capture.
    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 full burden but only states the action without disclosing behavioral traits. It doesn't mention execution environment, permissions needed, side effects, error handling, or output format. For a tool that executes code, this lack of transparency is a significant gap.

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 action and includes the command syntax. There's zero waste—every word contributes directly to understanding the tool's purpose and usage.

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?

For a code execution tool with no annotations and no output schema, the description is incomplete. It lacks details on execution behavior, safety, output, or error handling. Given the complexity of running WASM files, more context is needed to help an agent use this tool effectively.

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 three parameters. The description adds no parameter-specific information beyond implying 'wasmPath' in the command example. This meets the baseline of 3 since the schema does the heavy lifting, but the description doesn't enhance understanding of parameters.

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') and resource ('a WebAssembly (WASM) file'), specifying the exact command used ('onyx run file.wasm'). It distinguishes from siblings like 'run_onyx_code' by focusing on WASM files rather than general Onyx code. However, it doesn't explicitly contrast with all siblings, so it's not a perfect 5.

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 provides no guidance on when to use this tool versus alternatives like 'run_onyx_code' or other siblings. It mentions the command syntax but doesn't explain use cases, prerequisites, or exclusions, leaving the agent to infer usage from context alone.

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