Skip to main content
Glama

call-tool

Execute tools from any MCP server to bypass tool limits and reduce AI errors by accessing specific functionality when needed.

Instructions

Call a specific tool from a specific server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serverNameYesName of the MCP server to call tool from
toolNameYesName of the tool to call
toolArgsYesArguments to pass to the tool

Implementation Reference

  • Handler function that executes the 'call-tool' logic: parses arguments, calls serverManager.callTool on the specified server and tool, and returns the result as JSON or an error message.
    async (args, extra) => {
      try {
        const { serverName, toolName, toolArgs } = args;
        const result = await serverManager.callTool(
          serverName,
          toolName,
          toolArgs
        );
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Tool call failed: ${
                (error as Error).message
              }`,
            },
          ],
          isError: true,
        };
      }
    }
  • Zod schema defining the input parameters for the 'call-tool' tool: serverName (string), toolName (string), toolArgs (record of unknown).
    export const CallToolParamsSchema = z.object({
      serverName: z
        .string()
        .describe("Name of the MCP server to call tool from"),
      toolName: z.string().describe("Name of the tool to call"),
      toolArgs: z
        .record(z.unknown())
        .describe("Arguments to pass to the tool"),
    });
  • src/index.ts:83-122 (registration)
    Registration of the 'call-tool' tool on the MCP server using server.tool(), specifying name, description, schema (referencing CallToolParamsSchema), and handler function.
    server.tool(
      "call-tool",
      "Call a specific tool from a specific server",
      {
        serverName: CallToolParamsSchema.shape.serverName,
        toolName: CallToolParamsSchema.shape.toolName,
        toolArgs: CallToolParamsSchema.shape.toolArgs,
      },
      async (args, extra) => {
        try {
          const { serverName, toolName, toolArgs } = args;
          const result = await serverManager.callTool(
            serverName,
            toolName,
            toolArgs
          );
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(result, null, 2),
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Tool call failed: ${
                  (error as Error).message
                }`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • Supporting method in McpServerManager that proxies the tool call to the underlying MCP Client instance for the given server.
    async callTool(
      serverName: string,
      toolName: string,
      args: Record<string, unknown>
    ): Promise<any> {
      const client = this.getClient(serverName);
      return await client.callTool({
        name: toolName,
        arguments: args,
      });
    }
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/tpavelek/mcp-hub-mcp'

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