Skip to main content
When init() is called, mcp-tap monkey-patches each supported SDK. If a library isn’t installed, its patch is silently skipped. Patches never raise exceptions or affect application behavior.

Supported SDKs

SDKTypeScriptPythonWhat’s patched
Anthropic@anthropic-ai/sdkanthropicMessages.create (sync + async in Python)
OpenAIopenaiopenaiChat.Completions.create (sync + async in Python)
MCP Client@modelcontextprotocol/sdkmcpClient.callTool / ClientSession.call_tool
Composiocomposio-corecomposioComposioToolSet.executeAction / execute_action
HTTP (catch-all)globalThis.fetchhttpxRequests to known AI API hosts

What gets captured

For LLM requests (Anthropic, OpenAI, HTTP), mcp-tap emits an llm_request parent event with:
  • Model name, system prompt, request messages, response content
  • Token usage (input/output/cache tokens)
  • Thinking/reasoning blocks (if present)
  • Stop reason
  • Latency
For each tool call in the response, a child tool_call event is emitted with the tool name and input arguments, linked to the parent via parent_event_id. For MCP and Composio calls, a tool_call event is emitted with tool name, inputs, output, error (if any), and latency.

Individual patch functions

Each patch can be applied independently if you don’t want init() to patch everything:
import { patchAnthropic, patchOpenAI, patchMCP, patchComposio, patchHTTP } from "mcp-tap";

patchAnthropic();  // Patches @anthropic-ai/sdk Messages.create
patchOpenAI();     // Patches openai Chat.Completions.create
patchMCP();        // Patches @modelcontextprotocol/sdk Client.callTool
patchComposio();   // Patches composio-core ComposioToolSet.executeAction
patchHTTP();       // Patches globalThis.fetch for known AI hosts

Double-counting prevention

When both an SDK patch and the HTTP patch are active, the SDK patch marks a flag (_inSdkPatch in TypeScript, mark_sdk_patch() in Python) during execution. The HTTP patch checks this flag and skips interception when it’s set, preventing the same call from being logged twice.