Contoso MCP基准测试
基准a “坏”vs“好”MCP服务器 在跨多个LLM的Power BI语义模型(Microsoft Fabric上的Contoso)之上,测量令牌使用、工具调用和每次运行的成本。
这显示了什么
| 服务器 | 设计 |
|---|---|
| 糟糕的 | 2个原始工具,没有限制,没有语义上下文——LLM必须处理数据 |
| 好 | 重点语义工具、TOP50限制、日期过滤器执行、KPI描述 |
该基准测试针对GPT-4o、Claude Sonnet和Gemini Pro的两台服务器运行了8个业务问题。结果揭示了糟糕的MCP服务器设计的实际成本。
数据集
先决条件
- Python 3.10+
- 具有F2+容量的Microsoft Fabric工作区
- 服务负责人
Contributor工作空间中的角色 - 用于OpenAI、Anthropic、Google的API密钥
设置
1.安装依赖项
pip install -r requirements.txt
pip install -r requirements-setup.txt # fabric-cli, one-time setup only
cp .env.example .env # fill in credentials2.使用Fabric进行身份验证
fab auth login
# or service principal: fab auth login -u -p --tenant 3.提供织物资源(一次性)
./setup/01_setup_workspace.sh # creates workspace + Lakehouse
./setup/02_upload_data.sh # downloads Contoso 1M + uploads Delta tables
./setup/03_deploy_model.sh # deploys TMDL semantic model4.将部署模型的数据集ID复制到 .env
fab ls /contoso-benchmark | grep ContosoModel
# copy the ID into FABRIC_DATASET_ID in .env运行基准测试
python -m benchmark.runner结果已写入 results/benchmark_.csv 并且将摘要打印到控制台。
结果
在运行实时结构数据后填写。
| 服务器 | 型号 | 平均总令牌数 | 平均工具调用数 | 总成本(8个提示) |
|---|---|---|---|---|
| 坏 | gpt-4o | - | - | - |
| 良好 | gpt-4o | - | - | - |
| 坏 | claude-sonnet-4-6 | - | - | - |
| 好 | claude-sonnet-4-6 | - | - | - |
| 坏 | gemini-1.5-pro | - | - | - |
| 好 | 双子座-1.5-pro | - | - | - |
项目结构
contoso-mcp-benchmark/
├── setup/ # One-time Fabric provisioning scripts
├── semantic_model/ # TMDL semantic model definition
├── fabric_client/ # Fabric auth + DAX query client
├── mcp_bad/ # Naive MCP server (anti-patterns)
├── mcp_good/ # Guardrailed semantic MCP server
├── benchmark/ # Prompts, LLM clients, runner, cost calculator
├── tests/ # Unit tests
└── results/ # Benchmark output (gitignored)延伸
- 添加措施: 编辑
mcp_good/tool_config.json--无需更改代码 - 添加LLM: 向添加条目
LLM_RUNNERS在benchmark/runner.py - 添加提示: 附加
benchmark/prompts.json
