Skip to content

MCP SDK

@lookspan/mcp is Lookspan’s MCP-native SDK. It wraps any McpClient and emits a tool_call span per MCP tool invocation, without changing your agent code. It’s also the foundation the OpenAI and Anthropic observers are built on, so it re-exports the shared HttpSpanExporter and span types.

Install

Terminal window
npm install @lookspan/mcp

Usage

import { wrapMcpClient, HttpSpanExporter } from '@lookspan/mcp';
const exporter = new HttpSpanExporter({ endpoint: 'http://127.0.0.1:3100/api/ingest' });
const { client } = wrapMcpClient(mcpClient, { exporter, agentId: 'my-agent' });
// Use it exactly as before — every callTool emits a tool_call span.
await client.callTool({ name: 'read_file', arguments: { path: '/tmp/foo.txt' } });
await exporter.flush();

wrapMcpClient returns { client, traceId, flush }: the wrapped client, the trace id all its tool calls share, and a flush() helper.

wrapMcpClient options

OptionTypeDefaultWhat it does
exporterSpanExporter(required)Where spans are sent (e.g. an HttpSpanExporter).
agentIdstringAttribution label for the dashboard.
sessionIdstringGroup related agents into a session.
traceIdstringautoReuse a trace id (e.g. to join an existing trace).
rootSpanIdstringParent span for the tool calls (nests them under a step).
attributesRecord<string, unknown>Extra attributes stamped on every span.

Each tool call becomes a span named mcp.tool.<toolName> of type tool_call, with the call arguments captured as input and the result as output.

HttpSpanExporter options

OptionTypeDefaultWhat it does
endpointstring(required)Ingest URL.
flushIntervalMsnumberAuto-flush interval.
maxBatchSizenumberSpans per POST before flushing.
maxRetriesnumber2Extra POST attempts on transient failure.
retryBackoffMsnumber200Base backoff, doubled each retry.
sourcestringLabel for the exporter source.

Spans are buffered and sent in batches; call flush() before your process exits to drain anything still buffered.