LangSmith MCP服务器
    
MCP服务器 朗匠 可观测性集成。提供用于检索对话历史记录、管理提示、分析跟踪和跟踪使用情况的工具。
特性
| 类别 | 工具 | 目的 |
|---|---|---|
| 对话历史 | get_thread_history | 使用基于字符的分页检索线程消息历史记录 |
| 提示管理 | list_prompts, get_prompt, push_prompt | 使用版本控制管理LangSmith提示 |
| 痕迹与奔跑 | fetch_runs, list_projects | 调试LLM调用,分析执行跟踪 |
| 数据集 | list_datasets, get_dataset, list_examples, create_dataset, create_examples | 评估数据集管理 |
| 实验 | list_experiments, get_experiment | A/B测试和评估结果 |
| 计费 | get_billing_usage | 成本跟踪和使用指标 |
| 健康 | health_check | 服务器运行状况和连接状态 |
安装
# Using uv (recommended)
uv pip install -e .
# Or with pip
pip install -e .配置
环境变量
# Required
export LANGSMITH_API_KEY="your-api-key-here"
# Optional
export LANGSMITH_WORKSPACE_ID="your-workspace-id"
export LANGSMITH_API_ENDPOINT="https://api.smith.langchain.com"配置文件
编辑 settings/langsmith.yaml 对于持久配置:
server_name: "LangSmith MCP Server"
api_endpoint: "https://api.smith.langchain.com"
pagination:
max_chars_per_page: 25000
features_enabled:
- conversation
- prompts
- traces
- datasets
- experiments
- billing用法
启动MCP服务器
# Using the CLI
langsmith-mcp start
# Or directly
python -m langsmith_mcpMCP工具
获取线程历史记录
# Retrieve conversation history with pagination
result = await get_thread_history({
"thread_id": "thread_abc123",
"project_name": "my-project",
"page_number": 1,
"max_chars_per_page": 25000
})管理提示
# List all prompts
prompts = await list_prompts(limit=100)
# Get specific prompt
prompt = await get_prompt({
"prompt_identifier": "my-prompt",
"version": "v1.0.0" # Optional
})
# Push new prompt version
result = await push_prompt({
"prompt_identifier": "my-prompt",
"content": "You are a helpful assistant...",
"metadata": {"category": "system"}
})分析痕迹
# List projects
projects = await list_projects()
# Fetch runs/traces
runs = await fetch_runs({
"project_id": "proj_abc123",
"limit": 100
})管理数据集
# List datasets
datasets = await list_datasets()
# Create dataset
dataset = await create_dataset({
"name": "Test Dataset",
"description": "Evaluation dataset",
"data_type": "kv"
})
# Add examples
examples = await create_examples({
"dataset_id": "ds_abc123",
"examples": [
{"input": "Hello", "output": "Hi there!"},
{"input": "Goodbye", "output": "See you later!"}
]
})轨道使用情况
# Get billing usage
usage = await get_billing_usage({
"start_date": "2024-01-01",
"end_date": "2024-01-31"
})与Mahavishnu生态系统的整合
LangSmith MCP与博大生态系统整合:
| 组件 | 集成 |
|---|---|
| 马哈维什努 | 成本跟踪→ 路由指标预算警报 |
| 阿科沙 | 痕迹分析→ LLM调用中的模式检测 |
| 会话伙伴 | 线程历史记录→ 会话关联 |
示例:与Mahavishnu的成本整合
# In Mahavishnu's CostOptimizer
async def aggregate_costs(self) -> dict:
"""Combine routing costs + LangSmith billing."""
routing_costs = await self.get_routing_costs()
# Call LangSmith MCP for billing data
langsmith_result = await langsmith_mcp.get_billing_usage({})
langsmith_costs = langsmith_result.get("data", {})
return self._merge_cost_reports(routing_costs, langsmith_costs)发展
运行测试
pytest
pytest --cov=langsmith_mcp代码质量
ruff check langsmith_mcp/
ruff format langsmith_mcp/
pyright langsmith_mcp/建筑
langsmith-mcp/
├── langsmith_mcp/
│ ├── __init__.py # Package exports
│ ├── __main__.py # Oneiric CLI entry point
│ ├── config.py # LangSmithSettings (mcp-common)
│ ├── client.py # LangSmith API client
│ └── main.py # FastMCP server + tools
├── settings/
│ └── langsmith.yaml # Oneiric configuration
├── pyproject.toml
└── README.md许可证
BSD-3条款
