Model Context Protocol (MCP) servers let AI assistants inspect files, query databases, and run workflows. Yet once multiple stdio MCP servers run locally, you have zero visibility into which tool call took 8 seconds, how many tokens bloated responses consume, or whether credentials leaked into LLM context.
MCP Client (Cursor / Claude / Agent)
│ stdin / stdout (JSON-RPC 2.0)
▼
mcp-otel-guard (Transparent Proxy)
├──► Secret & PII Scanner (redact / block / audit)
├──► Latency + Token Estimator
└──► OTLP/HTTP POST /v1/traces ──► SigNoz / OTel Collector
│ stdin / stdout (JSON-RPC 2.0)
▼
Upstream MCP Server (e.g. server-filesystem, server-postgres)
stdout. Keep stdout strictly for newline-delimited JSON-RPC 2.0 frames and send telemetry over OTLP/HTTP or stderr.
Using Node.js (>=20) native fetch, you can construct standard OTLP/HTTP JSON trace payloads and send them straight to SigNoz on port 4318:
export async function exportToSigNoz(endpoint, serviceName, spans) {
const payload = {
resourceSpans: [{
resource: { attributes: [{ key: 'service.name', value: { stringValue: serviceName } }] },
scopeSpans: [{
scope: { name: 'mcp-otel-guard', version: '0.1.0' },
spans: spans.map((s) => ({
traceId: s.traceId,
spanId: s.spanId,
name: s.name,
kind: 3,
startTimeUnixNano: (BigInt(s.startMs) * 1_000_000n).toString(),
endTimeUnixNano: (BigInt(s.endMs) * 1_000_000n).toString(),
attributes: Object.entries(s.attributes).map(([key, val]) => ({
key,
value: typeof val === 'number' ? { intValue: String(val) } : { stringValue: String(val) },
})),
status: { code: s.isError ? 2 : 1 },
})),
}],
}],
};
await fetch(`${endpoint.replace(/\/+$/, '')}/v1/traces`, {
method: 'POST',
headers: { 'content-type': 'application/json', connection: 'close' },
body: JSON.stringify(payload),
});
}
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y", "github:gyozomongo/mcp-otel-guard",
"--mode", "redact",
"--otlp", "http://localhost:4318",
"--service", "mcp-filesystem",
"--",
"npx", "-y", "@modelcontextprotocol/server-filesystem", "."
]
}
}
}
mcp-filesystem.mcp.tool.name or hasError = true.mcp.guard.findings != "" to detect leaked tokens immediately.Full MIT source & E2E tests: github.com/gyozomongo/mcp-otel-guard · Need pre-built SigNoz v4 dashboards, 20+ enterprise rules, and a CI trace gate? Check out the Pro Production Kit ($15).