您连接的每个 MCP 服务器都会将工具描述添加到您的 LLM 上下文窗口中。具有 10 台服务器的全局设置可能会向每个请求添加 5,000 多个工具描述标记,即使代理只需要搜索也是如此。项目范围的 MCP 配置仅加载每个项目所需的工具。本教程介绍如何为每个项目配置 Scavio MCP 服务器 (mcp.scavio.dev/mcp),以便您只需为实际使用的上下文令牌付费。
前置条件
- 兼容 MCP 的客户端(Claude Desktop、Cursor 或 Cline)
- 来自 scavio.dev 的 Scavio API 密钥
- 基础 JSON 配置知识
- 至少两个需要不同工具集的项目
操作指南
步骤 1: 审核您当前的 MCP 令牌使用情况
检查您全局配置了多少个 MCP 服务器。每个服务器都会添加在每个请求上使用上下文令牌的工具描述。
# Check your current MCP configuration
import json, os
# Common MCP config locations
config_paths = [
os.path.expanduser('~/.config/claude/claude_desktop_config.json'),
os.path.expanduser('~/.cursor/mcp.json'),
'.mcp.json', # Project-level
]
for path in config_paths:
if os.path.exists(path):
with open(path) as f:
config = json.load(f)
servers = config.get('mcpServers', {})
print(f'{path}:')
print(f' Servers: {len(servers)}')
for name, cfg in servers.items():
print(f' - {name}')
# Estimate token cost (rough: ~200 tokens per tool description)
est_tools = len(servers) * 5 # ~5 tools per server average
est_tokens = est_tools * 200
print(f' Estimated tool description tokens: ~{est_tokens}')
else:
print(f'{path}: not found')步骤 2: 创建项目范围的 MCP 配置
创建仅包含每个项目所需的服务器的每个项目 .mcp.json 文件,而不是一个全局配置。
import json
def create_project_mcp(project_path: str, servers: dict, description: str = ''):
"""Create a project-scoped MCP configuration."""
config = {'mcpServers': servers}
config_path = os.path.join(project_path, '.mcp.json')
with open(config_path, 'w') as f:
json.dump(config, f, indent=2)
tool_count = len(servers)
est_tokens = tool_count * 5 * 200
print(f'Created {config_path}')
print(f' Servers: {tool_count}')
print(f' Est. token overhead: ~{est_tokens}')
if description:
print(f' Purpose: {description}')
# Project 1: E-commerce research - needs search only
create_project_mcp('/projects/ecommerce-research', {
'scavio': {
'url': 'https://mcp.scavio.dev/mcp',
'headers': {'Authorization': 'Bearer ${SCAVIO_API_KEY}'}
}
}, 'E-commerce product research with multi-platform search')
# Project 2: Content pipeline - needs search + file tools
create_project_mcp('/projects/content-pipeline', {
'scavio': {
'url': 'https://mcp.scavio.dev/mcp',
'headers': {'Authorization': 'Bearer ${SCAVIO_API_KEY}'}
},
'filesystem': {
'command': 'npx',
'args': ['-y', '@modelcontextprotocol/server-filesystem', '/projects/content-pipeline/output']
}
}, 'Content generation with search grounding')步骤 3: 比较全局代币成本与范围代币成本
计算范围界定所节省的代币。与具有 10 台服务器的全局配置相比,仅需要搜索的项目每个请求可以节省数千个令牌。
def compare_token_costs(global_servers: int, scoped_servers: int,
avg_tools_per_server: int = 5,
tokens_per_tool: int = 200,
requests_per_day: int = 100) -> dict:
global_tokens = global_servers * avg_tools_per_server * tokens_per_tool
scoped_tokens = scoped_servers * avg_tools_per_server * tokens_per_tool
savings_per_request = global_tokens - scoped_tokens
daily_savings = savings_per_request * requests_per_day
# At ~$3/1M input tokens (GPT-4o rate)
cost_per_token = 3.0 / 1_000_000
monthly_savings = daily_savings * 30 * cost_per_token
return {
'global_tokens_per_request': global_tokens,
'scoped_tokens_per_request': scoped_tokens,
'savings_per_request': savings_per_request,
'daily_token_savings': daily_savings,
'monthly_cost_savings': monthly_savings,
}
# Scenario: global has 10 servers, project only needs 1 (Scavio)
result = compare_token_costs(global_servers=10, scoped_servers=1)
print('Token Savings Analysis')
print('=' * 40)
print(f'Global config: {result["global_tokens_per_request"]:,} tokens/request')
print(f'Scoped config: {result["scoped_tokens_per_request"]:,} tokens/request')
print(f'Savings: {result["savings_per_request"]:,} tokens/request')
print(f'Daily savings: {result["daily_token_savings"]:,} tokens')
print(f'Monthly cost savings: ${result["monthly_cost_savings"]:.2f}')步骤 4: 为项目设置 Scavio MCP 服务器
创建仅配置 Scavio 搜索 MCP 服务器的最小 .mcp.json。这使得该项目能够以最小的代币开销访问 6 个平台。
# Minimal Scavio-only MCP config for any project
scavio_only_config = {
'mcpServers': {
'scavio': {
'url': 'https://mcp.scavio.dev/mcp',
'headers': {
'Authorization': 'Bearer ${SCAVIO_API_KEY}'
}
}
}
}
def setup_scavio_mcp(project_dir: str):
config_path = os.path.join(project_dir, '.mcp.json')
with open(config_path, 'w') as f:
json.dump(scavio_only_config, f, indent=2)
print(f'Scavio MCP configured at {config_path}')
print(f'Platforms available: Google, Amazon, YouTube, Walmart, Reddit, TikTok')
print(f'Endpoint: mcp.scavio.dev/mcp')
print(f'Cost: $0.005 per search credit')
print(f'Token overhead: ~1,000 tokens (vs ~10,000 with 10 global servers)')
# Setup for multiple projects
for project in ['ecommerce-tool', 'content-agent', 'research-bot']:
project_path = f'/projects/{project}'
if os.path.isdir(project_path):
setup_scavio_mcp(project_path)
else:
print(f'Would configure: {project_path}/.mcp.json')Python 示例
import json, os
def create_scavio_mcp(project_dir):
config = {'mcpServers': {'scavio': {
'url': 'https://mcp.scavio.dev/mcp',
'headers': {'Authorization': 'Bearer ${SCAVIO_API_KEY}'}
}}}
path = os.path.join(project_dir, '.mcp.json')
with open(path, 'w') as f:
json.dump(config, f, indent=2)
print(f'Created {path}')
print(f' 1 server, ~1,000 token overhead')
print(f' 6 platforms: Google, Amazon, YouTube, Walmart, Reddit, TikTok')
create_scavio_mcp('.')JavaScript 示例
const fs = require('fs');
const path = require('path');
function createScavioMcp(projectDir) {
const config = { mcpServers: { scavio: {
url: 'https://mcp.scavio.dev/mcp',
headers: { Authorization: 'Bearer ${SCAVIO_API_KEY}' }
}}};
const configPath = path.join(projectDir, '.mcp.json');
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
console.log(`Created ${configPath}`);
console.log(' 1 server, ~1,000 token overhead');
console.log(' 6 platforms: Google, Amazon, YouTube, Walmart, Reddit, TikTok');
}
createScavioMcp('.');预期输出
Token Savings Analysis
========================================
Global config: 10,000 tokens/request
Scoped config: 1,000 tokens/request
Savings: 9,000 tokens/request
Daily savings: 900,000 tokens
Monthly cost savings: $81.00
Scavio MCP configured at /projects/ecommerce-tool/.mcp.json
Platforms available: Google, Amazon, YouTube, Walmart, Reddit, TikTok
Endpoint: mcp.scavio.dev/mcp
Cost: $0.005 per search credit
Token overhead: ~1,000 tokens (vs ~10,000 with 10 global servers)