SM

synqedai/mcp-trace-js

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

22 stars 1 forks 质量 49 趋势 10

在TypeScript中追踪MCP服务器的中间件。记录所有请求、工具调用及对文件、数据库或云的响应,使用OTLP、Supabase、PostgreSQL和Contexa的适配器。

概览

记录每一个请求、工具调用和对本地文件、PostgreSQL、Supabase、Contexa、控制台、OTLP或你自己的后端的响应——并完全控制记录的内容。 - 📦 : 可在几秒钟内向任意MCP服务器添加追踪 - 🗃️ : 日志到文件、PostgreSQL、Supabase、Contexa、控制台、OTLP或您自己的 - 🛠️ : 启用/禁用字段(工具arg、响应、客户端ID等) - 🧩 : 同时使用多个适配器 - 📝 : 所有痕迹以JSON存储以便查询 - 🔒 : 控制具体记录内容 - ⚡ : 全类型安全和IntelliSense - 🛡️ : 全面的错误处理和内存管理 - 🔧 : 配置验证及描述性错误消息 - 🧹 : 通过超时管理防止内存泄漏 - 🌐 : 为可观测平台提供原生OTLP集成 参见示例/streamable-http-server.ts,了解使用带追踪的可流式HTTP传输的完整MCP服务器。

概述(AI 翻译)

灵活、可插拔的 JavaScript/TypeScript 模型上下文协议(MCP)服务器追踪中间件。 记录对本地文件、PostgreSQL、Supabase、Contexa、控制台、OTLP 或你自己的后端的每一个请求、工具调用和响应——并完全控制记录的内容。


目录

  • 特色
  • 快速启动
  • 基本用法
  • 功能使用
  • 可配置日志
  • 请求级控制
  • 个人信息信息编辑
  • 用户识别
  • 生产准备功能
  • Contexa 适配器
  • 其他适配器
  • 文件适配器
  • 控制台适配器
  • PostgreSQL 适配器
  • Supabase 适配器
  • OTLP适配器
  • 多适配器示例
  • 要求
  • 贡献
  • 许可证
  • 链接与致谢

特色

  • 📦 即插即用:几秒钟内将追踪添加到任何MCP服务器
  • 🗃️ 可插拔适配器:日志文件、PostgreSQL、Supabase、Contexa、控制台、OTLP或您自己的适配器
  • 🛠️ 可配置日志:启用/禁用字段(工具 args、响应、客户端 ID 等)
  • 🧩 可组合适配器:同时使用多个适配器
  • 📝 模式优先:所有跟踪都存储为JSON,便于查询
  • 🔒 隐私意识:精确控制记录内容

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

mcp-trace

Flexible, pluggable tracing middleware for Model Context Protocol (MCP) servers in JavaScript/TypeScript. Log every request, tool call, and response to local files, PostgreSQL, Supabase, Contexa, console, OTLP, or your own backend—with full control over what gets logged.


Table of Contents


Features

  • 📦 Plug-and-play: Add tracing to any MCP server in seconds
  • 🗃️ Pluggable adapters: Log to file, PostgreSQL, Supabase, Contexa, console, OTLP, or your own
  • 🛠️ Configurable logging: Enable/disable fields (tool args, responses, client ID, etc.)
  • 🧩 Composable: Use multiple adapters at once
  • 📝 Schema-first: All traces stored as JSON for easy querying
  • 🔒 Privacy-aware: Control exactly what gets logged
  • ⚡ TypeScript support: Full type safety and IntelliSense
  • 🛡️ Production-ready: Comprehensive error handling and memory management
  • 🔧 Robust validation: Configuration validation with descriptive error messages
  • 🧹 Automatic cleanup: Prevents memory leaks with timeout management
  • 🌐 OpenTelemetry support: Native OTLP integration for observability platforms

Quickstart

Installation

npm install mcp-trace

Minimal Example

import { TraceMiddleware, FileAdapter } from "mcp-trace-js";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";

// Create your MCP server
const server = new McpServer({ name: "my-server", version: "1.0.0" });

// Set up tracing
const traceAdapter = new FileAdapter("trace.log");
const traceMiddleware = new TraceMiddleware({ adapter: traceAdapter });

// Initialize tracing with your server
traceMiddleware.init(server);

// Your server is now fully traced!

Basic Usage

Streamable HTTP Server

在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →