当 Claude Code、Cursor 和 OpenCode 等编码代理可以在网络上搜索当前文档、API 参考和错误解决方案时,它们会更加有效。如果没有网络搜索,他们依赖的培训数据对于快速发展的图书馆来说可能已经过时。本教程添加了 Scavio 通过 MCP 搜索基于 IDE 的代理以及通过 REST API 搜索自定义代理的功能。
前置条件
- 编码代理(Claude Code、Cursor 或自定义)
- 来自 scavio.dev 的 Scavio API 密钥
操作指南
步骤 1: 为 Claude 代码配置 MCP
将 Scavio 的 MCP 服务器添加到 Claude Code 的项目配置中。
JSON
// .claude/mcp.json (project-level config):
{
"mcpServers": {
"scavio": {
"url": "https://mcp.scavio.dev/mcp",
"headers": {
"x-api-key": "your_scavio_api_key"
}
}
}
}步骤 2: 为光标配置 MCP
将 Scavio 添加到 Cursor 的 MCP 配置中。
JSON
// .cursor/mcp.json:
{
"mcpServers": {
"scavio": {
"url": "https://mcp.scavio.dev/mcp",
"headers": {
"x-api-key": "your_scavio_api_key"
}
}
}
}步骤 3: 对于自定义编码代理,添加搜索工具
如果您正在构建自定义编码代理,请添加搜索功能作为工具。
Python
import requests, os
def web_search(query: str) -> str:
"""Search the web for documentation, API references, and error solutions."""
resp = requests.post('https://api.scavio.dev/api/v1/search',
headers={'x-api-key': os.environ['SCAVIO_API_KEY']},
json={'platform': 'google', 'query': query}, timeout=10)
results = resp.json().get('organic', [])[:5]
return '\n'.join(f'{r["title"]}: {r["snippet"]} ({r["link"]})' for r in results)步骤 4: 使用常见编码查询进行测试
验证搜索是否适用于典型的编码代理查询。
Python
# Test queries:
print(web_search('Next.js 15 app router migration guide'))
print(web_search('Python requests timeout error handling'))
print(web_search('React useEffect cleanup function'))Python 示例
Python
import requests, os
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}
def search_docs(query):
data = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
json={'platform': 'google', 'query': query}, timeout=10).json()
return [(r['title'], r['link']) for r in data.get('organic', [])[:5]]JavaScript 示例
JavaScript
async function searchDocs(query) {
const data = await fetch('https://api.scavio.dev/api/v1/search', {
method: 'POST', headers: {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'},
body: JSON.stringify({platform: 'google', query})
}).then(r => r.json());
return (data.organic || []).slice(0, 5).map(r => ({title: r.title, url: r.link}));
}预期输出
JSON
A coding agent with live web search for documentation, API references, and error solutions via MCP or REST API.