Skip to main content
Glama

execute

Execute commands in MCP, RPC, or RUN contexts to analyze Node.js applications via Chrome Debug Protocol for runtime type validation.

Instructions

Execute a command in the specified context (MCP, RPC, or RUN)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contextYesExecution context: MCP (local), RPC (remote/CDP), or RUN (VS Code HTTP)
commandYesCommand name to execute
messageYesCommand Message or string of arguments, or empty string

Implementation Reference

  • This function handles the execution logic for commands, either by requiring them (if they export a 'run' function) or by evaluating them as an IIFE within a context.
    async function executeCommand (
    	filePath: string,
    	args: unknown
    ): Promise<unknown> {
    	if (!fs.existsSync(filePath)) {
    		throw new Error(`Command file not found: ${filePath}`);
    	}
    
    	// Read the code first to check pattern
    	const code = fs.readFileSync(filePath, 'utf-8');
    
    	// Build context - passed to command
    	// eslint-disable-next-line @typescript-eslint/no-explicit-any
    	const g = global as Record<string, any>;
    	const ctx: any = {
    		require,
    		store: g.StrategyMCP,
    		args,
    	} as unknown;
    
    	// If it has module.exports with run function, use require
    	if (isLocalCommand(code)) {
    		// Clear require cache to allow reloading
    		delete require.cache[require.resolve(filePath)];
    
    		// Require the module
    		// eslint-disable-next-line @typescript-eslint/no-var-requires
    		const commandModule = require(filePath);
    
    		if (typeof commandModule.run === 'function') {
    			return await commandModule.run(ctx);
    		}
    
    		throw new Error(`Command does not export a 'run' function`);
    	}
    
    	// Otherwise, treat as remote-style IIFE command
    	// Wrap it to capture the result - always wrap in async IIFE
    	const wrappedBody = `
    		return (async function() {
    			${code}
    		})();
    	`;
    
    	// Execute in a sandbox-like way using Function with ctx parameter
    	// eslint-disable-next-line @typescript-eslint/no-var-requires
    	const fn = new Function('ctx', wrappedBody);
    	const result = fn(ctx);
    
    	// Always await the result since we wrap in async IIFE
    	return await result;
    }
  • src/server.ts:125-147 (registration)
    Registration of the 'execute' tool within the MCP server.
    {
    	name: 'execute',
    	description: 'Execute a command in the specified context (MCP, RPC, or RUN)',
    	inputSchema: {
    		type: 'object',
    		properties: {
    			context: {
    				type: 'string',
    				enum: ['MCP', 'RPC', 'RUN'],
    				description: 'Execution context: MCP (local), RPC (remote/CDP), or RUN (VS Code HTTP)',
    			},
    			command: {
    				type: 'string',
    				description: 'Command name to execute',
    			},
    			message: {
    				type: 'string',
    				description: 'Command Message or string of arguments, or empty string',
    			},
    		},
    		required: ['context', 'command', 'message'],
    	},
    },
  • The handler logic for the 'execute' tool inside the CallToolRequest switch statement.
    case 'execute': {
    	console.error('[SERVER DEBUG] request.params:', JSON.stringify(request.params));
    	const { context, command } = args as {
    		context: CommandContext;
    		command: string;
    	} & unknown;
    
    	if (!context || !command) {
    		return {
    			content: [{ type: 'text', text: 'Error: context and command are required' }],
    			isError: true,
    		};
    	}
    
    	// Get command file path
    	const filePath = getCommandPath(context, command);
    
    	if (!filePath) {
    		return {
    			content: [{ type: 'text', text: `Error: Command '${command}' not found in context '${context}'` }],
    			isError: true,
    		};
    	}
    
    	// Execute command
    	try {
    		const result = await executeCommand(filePath, args);
    		const text = result !== undefined ? JSON.stringify(result, null, 2) : 'Command executed (no return value)';
    		return {
    			content: [{ type: 'text', text }],
    		};
    	} catch (e) {
    		return {
    			content: [{ type: 'text', text: `Error executing command: ${e instanceof Error ? e.message : String(e)}` }],
    			isError: true,
    		};
    	}
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions execution contexts but doesn't reveal critical behavioral traits: whether this is a read-only or destructive operation, what permissions are required, whether commands are synchronous or asynchronous, what happens on failure, or any rate limits. The description is operationally opaque beyond the basic action.

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, efficient sentence that states the core purpose. There's no wasted verbiage or unnecessary elaboration. However, it could be more front-loaded with critical behavioral information given the lack of annotations.

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 command execution tool with 3 required parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what types of commands can be executed, what the expected output format might be, error conditions, or security implications. The agent would struggle to use this tool correctly without significant trial and error.

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 schema description coverage is 100%, so all parameters are documented in the schema. The description adds minimal value beyond the schema - it mentions the three contexts but doesn't elaborate on their differences or provide additional semantic context about how parameters interact. The baseline of 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.

Purpose3/5

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

The description states the tool 'Execute[s] a command in the specified context' which provides a basic verb+resource combination. However, it's vague about what types of commands are executed and what 'execute' means operationally. It doesn't distinguish this tool from its siblings (help, list) beyond the general action of execution.

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. It mentions three contexts (MCP, RPC, RUN) but doesn't explain when each context is appropriate or what distinguishes this execution tool from other potential command-execution tools. No prerequisites, exclusions, or sibling tool comparisons are provided.

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/mythographica/strategy'

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