Skip to main content
Glama
tesla0225

MCP Create Server

by tesla0225

execute-tool

Run a specific tool on an MCP server by providing the server ID, tool name, and required arguments to automate tasks or processes.

Instructions

Execute a tool on a server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsNoThe arguments to pass to the tool
serverIdYesThe ID of the server
toolNameYesThe name of the tool to execute

Implementation Reference

  • Main handler implementation in ServerManager class. Retrieves the connected server by ID and proxies the tool call to it using the MCP client.callTool method.
    async executeToolOnServer(
      serverId: string,
      toolName: string,
      args: Record<string, any>
    ): Promise<any> {
      const server = this.servers.get(serverId);
      if (!server) {
        throw new Error(`Server ${serverId} not found`);
      }
    
      try {
        // Call the tool on the server using the MCP client
        const result = await server.client.callTool({
          name: toolName,
          arguments: args,
        });
    
        return result;
      } catch (error) {
        console.error(`Error executing tool on server ${serverId}:`, error);
        throw error;
      }
    }
  • Dispatcher handler in the main CallToolRequest handler. Validates arguments and calls ServerManager.executeToolOnServer.
    case "execute-tool": {
      const args = request.params
        .arguments as unknown as ExecuteToolArgs;
      if (!args.serverId || !args.toolName) {
        throw new Error(
          "Missing required arguments: serverId and toolName"
        );
      }
    
      const result = await serverManager.executeToolOnServer(
        args.serverId,
        args.toolName,
        args.args || {}
      );
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(result),
          },
        ],
      };
    }
  • Tool object definition including name, description, and input schema for 'execute-tool'.
    const executeToolTool: Tool = {
      name: "execute-tool",
      description: "Execute a tool on a server",
      inputSchema: {
        type: "object",
        properties: {
          serverId: {
            type: "string",
            description: "The ID of the server",
          },
          toolName: {
            type: "string",
            description: "The name of the tool to execute",
          },
          args: {
            type: "object",
            description: "The arguments to pass to the tool",
          },
        },
        required: ["serverId", "toolName"],
      },
    };
  • TypeScript interface defining the input arguments for the execute-tool.
    interface ExecuteToolArgs {
      serverId: string;
      toolName: string;
      args: Record<string, any>;
    }
  • index.ts:1011-1022 (registration)
    Registration of the tool in the ListToolsRequest handler, where executeToolTool is included in the returned tools list.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      console.error("Received ListToolsRequest");
      return {
        tools: [
          createServerFromTemplateTool,
          executeToolTool,
          getServerToolsTool,
          deleteServerTool,
          listServersTool,
        ],
      };
    });
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/tesla0225/mcp-create'

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