Get $25 in credits by signing up today! Sign up now

Agent Developers

Code snippets to get started with the Tollbit Dynamic Toolbox and invoke tools.

The dynamic toolbox is available publicly as a streamable HTTP server available at https://mcp.tollbit.dev/mcp. You can integrate it into your app according to the MCP docs + SDKs.

Below are examples of how to integrate it using the official MCP SDKs, but you can also use any HTTP client to make requests to the server if it meets the MCP spec.

  1. Install the official ModelContextProtocol SDK

    npm i @modelcontextprotocol/sdk
    
  2. Initialize the client + transport. Note: your api key must be sent in the x-api-key header.

    import { Client } from "@modelcontextprotocol/sdk/client/index.js";
    import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
    import {
      CallToolRequestSchema,
      ListToolsRequestSchema,
    } from "@modelcontextprotocol/sdk/types.js";
    
    const client = new Client({
      name: "local-mcp-bridge",
      version: "1.0.0",
    });
    
    const transport = new StreamableHTTPClientTransport(
      new URL("https://mcp.tollbit.dev/mcp"),
      {
        requestInit: {
          headers: {
            "x-api-key": `${YOUR_API_KEY_HERE}`,
          },
        },
      }
    );
    
    await client.connect(transport);
    
  3. List tools in the catalog + invoke tools (HackerNews' get_stories used as an example)

    const tools = await client.listTools();
    
    const tool = tools.find((tool) => tool.name === "hacker-news");
    if (!tool) {
      throw new Error("Tool not found");
    }
    const request = CallToolRequestSchema.parse({
      tool_name: "hacker-news",
      tool_input: {
        type: "get_stories",
        input: {
          story_type: "top",
          page_size: 10,
        },
      },
    });
    const response = await client.callTool(request);
    console.log(response.tool_response);
    

Was this page helpful?