Skip to main content
Use instrumentServer() when you’re building an MCP server and want to log every incoming tool call without client-side setup.

How it works

The function finds the CallTool / call_tool request handler in the server’s requestHandlers map and wraps it. Every tool invocation is timed, its inputs/outputs captured, and an event emitted with source: "mcp_server".

Setup

import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { instrumentServer } from "mcp-tap";

const server = new Server({ name: "weather-server", version: "1.0.0" });

server.setRequestHandler(CallToolRequestSchema, async (req) => {
  // your handler logic
});

instrumentServer(server, { apiKey: "tap_abc123" });
See the full instrumentServer API in the TypeScript API reference or Python API reference.