> ## Documentation Index
> Fetch the complete documentation index at: https://docs.themcp.company/llms.txt
> Use this file to discover all available pages before exploring further.

# Server-side instrumentation

> Log every incoming tool call on your MCP server

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

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    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" });
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from mcp.server import Server
    import mcp_tap

    app = Server("weather-server")

    @app.call_tool()
    async def handle_tool(name, arguments):
        ...

    mcp_tap.instrument_server(app, api_key="tap_abc123")
    ```
  </Tab>
</Tabs>

See the full `instrumentServer` API in the [TypeScript API reference](/api-reference/typescript#instrumentserver) or [Python API reference](/api-reference/python#instrument_server).
