Skip to main content
Glama

execute

Run Babashka (bb) code with configurable timeouts and integrated script management. Designed for efficient execution and control of scripting workflows using the Model Context Protocol.

Instructions

Execute Babashka (bb) code

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesBabashka code to execute
timeoutNoTimeout in milliseconds (default: 30000)

Implementation Reference

  • Handler for CallToolRequestSchema that implements the 'execute' tool: validates tool name and arguments, executes Babashka code via child_process.execAsync, handles errors, caches recent results.
    this.server.setRequestHandler(
      CallToolRequestSchema,
      async (request) => {
        if (request.params.name !== "execute") {
          throw new McpError(
            ErrorCode.MethodNotFound,
            `Unknown tool: ${request.params.name}`
          );
        }
    
        if (!isValidBabashkaCommandArgs(request.params.arguments)) {
          throw new McpError(
            ErrorCode.InvalidParams,
            "Invalid Babashka command arguments"
          );
        }
    
        try {
          const timeout = request.params.arguments.timeout || CONFIG.DEFAULT_TIMEOUT;
          const { stdout, stderr } = await execAsync(
            `${CONFIG.BABASHKA_PATH} -e "${request.params.arguments.code.replace(/"/g, '\\"')}"`,
            { timeout }
          );
    
          const result: BabashkaCommandResult = {
            stdout: stdout.trim(),
            stderr: stderr.trim(),
            exitCode: 0
          };
    
          // Cache the command result
          this.recentCommands.unshift({
            code: request.params.arguments.code,
            result,
            timestamp: new Date().toISOString()
          });
    
          // Keep only recent commands
          if (this.recentCommands.length > CONFIG.MAX_CACHED_COMMANDS) {
            this.recentCommands.pop();
          }
    
          return {
            content: [{
              type: "text",
              text: JSON.stringify(result, null, 2)
            }]
          };
        } catch (error: any) {
          const result: BabashkaCommandResult = {
            stdout: "",
            stderr: error.message || "Unknown error",
            exitCode: error.code || 1
          };
    
          return {
            content: [{
              type: "text",
              text: JSON.stringify(result, null, 2)
            }],
            isError: true
          };
        }
      }
    );
  • src/index.ts:108-132 (registration)
    Registers the 'execute' tool metadata and input schema in the ListToolsRequestSchema handler.
    this.server.setRequestHandler(
      ListToolsRequestSchema,
      async () => ({
        tools: [{
          name: "execute",
          description: "Execute Babashka (bb) code",
          inputSchema: {
            type: "object",
            properties: {
              code: {
                type: "string",
                description: "Babashka code to execute"
              },
              timeout: {
                type: "number",
                description: "Timeout in milliseconds (default: 30000)",
                minimum: 1000,
                maximum: 300000
              }
            },
            required: ["code"]
          }
        }]
      })
    );
  • JSON Schema defining the input for the 'execute' tool: required 'code' string and optional 'timeout' number.
    inputSchema: {
      type: "object",
      properties: {
        code: {
          type: "string",
          description: "Babashka code to execute"
        },
        timeout: {
          type: "number",
          description: "Timeout in milliseconds (default: 30000)",
          minimum: 1000,
          maximum: 300000
        }
      },
      required: ["code"]
    }
  • Helper function to validate Babashka command arguments used in the 'execute' handler.
    export const isValidBabashkaCommandArgs = (
      args: any
    ): args is BabashkaCommandArgs =>
      typeof args === "object" &&
      args !== null &&
      typeof args.code === "string" &&
      (args.timeout === undefined || typeof args.timeout === "number");
  • Configuration constants used in the 'execute' handler: default timeout, max cached commands, Babashka executable path.
    export const CONFIG = {
      DEFAULT_TIMEOUT: 30000, // 30 seconds
      MAX_CACHED_COMMANDS: 10,
      BABASHKA_PATH: process.env.BABASHKA_PATH || "bb" // Allow custom bb path
    } as const;
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 the action ('execute') but doesn't describe key behaviors like execution environment, security implications, error handling, or output format. This is a significant gap for a tool that runs arbitrary code.

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 with zero waste. It's appropriately sized and front-loaded, clearly stating the tool's purpose without unnecessary elaboration.

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 complexity of executing code and the lack of annotations and output schema, the description is incomplete. It doesn't address critical aspects like what the execution returns, error conditions, or safety considerations, leaving the agent with insufficient context for reliable 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?

Schema description coverage is 100%, so the schema fully documents both parameters (code and timeout). The description adds no additional meaning beyond what the schema provides, such as examples of valid Babashka code or timeout implications. Baseline 3 is appropriate when the schema does 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 verb ('execute') and resource ('Babashka (bb) code'), making the purpose immediately understandable. It doesn't need sibling differentiation since there are no sibling tools, but it could be slightly more specific about what 'execute' entails (e.g., running code in a Babashka environment).

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, such as typical use cases, prerequisites, or alternatives. With no sibling tools, it doesn't need to distinguish from others, but it lacks any context about appropriate scenarios for executing Babashka code.

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

Related 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/bmorphism/babashka-mcp-server'

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