ScavioScavio
产品定价文档
登录开始使用
  1. 首页
  2. 教程
  3. 如何设置 MCP 预编码搜索例程
教程

如何设置 MCP 预编码搜索例程

在 Claude Code 中配置 MCP 搜索,以便代理在编写代码之前自动搜索文档和 API。通过实时查找防止使用过时的 API。

获取免费API密钥API文档

设置 MCP 预编码搜索例程意味着配置您的 Claude Code 环境,以便代理在生成代码之前搜索文档和 API 参考,从而防止幻觉导入和过时的 API 调用。通过添加 Scavio MCP 服务器和 CLAUDE.md 指令,您可以创建一个工作流程,其中 Claude Code 在写入一行之前验证软件包版本、读取更改日志并根据实时搜索数据检查 API 签名。

前置条件

  • 克劳德代码安装和配置
  • 来自 scavio.dev 的 Scavio API 密钥
  • 带有 CLAUDE.md 的项目目录

操作指南

步骤 1: 配置 Scavio MCP 服务器

将 Scadio MCP 服务器添加到您的项目中,以便 Claude Code 可以调用搜索工具。

Bash
cat > .mcp.json << 'MCPEOF'
{
  "mcpServers": {
    "scavio": {
      "url": "https://mcp.scavio.dev/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_SCAVIO_API_KEY"
      }
    }
  }
}
MCPEOF

步骤 2: 将预编码搜索指令添加到 CLAUDE.md

在 CLAUDE.md 中编写指令,告诉 Claude Code 在编码之前进行搜索。这将创建自动预编码搜索例程。

Bash
cat >> CLAUDE.md << 'EOF'

## Pre-Coding Search Routine

Before writing code that uses an external library or API:
1. Search for the current version: "[library name] latest version 2026"
2. Search for the API signature: "[library name] [function] API reference"
3. If the library was updated in the last 6 months, search for migration guides
4. Verify import paths match the current version

Do NOT rely on training data for:
- Package versions or install commands
- API endpoint URLs or authentication methods
- Configuration file formats
- CLI flag syntax
EOF

步骤 3: 添加特定于域的搜索规则

使用针对您团队使用的框架和 API 的特定于项目的规则来扩展例程。

Bash
cat >> CLAUDE.md << 'EOF'

## Project-Specific Search Rules

Always verify before using:
- Next.js: search "next.js [feature] app router" (not pages router)
- Stripe: search "stripe api [endpoint] 2026" (API changes frequently)
- Prisma: search "prisma [method] latest" (ORM syntax varies by version)
- AWS SDK: search "aws sdk v3 [service]" (v2 is deprecated)
EOF

步骤 4: 测试常规

打开 Claude Code 并给它一个需要外部 API 知识的任务。在编码之前验证其搜索。

Bash
# In Claude Code, try:
# 'Add Stripe checkout to this Next.js app'
#
# Expected behavior:
# 1. Claude searches 'stripe checkout api next.js 2026'
# 2. Claude searches 'next.js server actions stripe'
# 3. Claude writes code using verified API signatures
#
# Without the routine, Claude might use:
# - Deprecated Stripe API methods
# - Pages router patterns instead of App Router
# - Wrong import paths from outdated training data

Python 示例

Python
# Generate the MCP config and CLAUDE.md programmatically
import json, os

def setup_pre_coding_routine(project_dir, api_key, frameworks=None):
    # Write MCP config
    mcp_config = {
        'mcpServers': {
            'scavio': {
                'url': 'https://mcp.scavio.dev/mcp',
                'headers': {'Authorization': f'Bearer {api_key}'}
            }
        }
    }
    mcp_path = os.path.join(project_dir, '.mcp.json')
    with open(mcp_path, 'w') as f:
        json.dump(mcp_config, f, indent=2)

    # Append search routine to CLAUDE.md
    routine = '''
## Pre-Coding Search Routine
Before writing code that uses an external library or API:
1. Search for the current version
2. Search for the API signature or reference docs
3. Check for recent breaking changes or migration guides
4. Verify import paths match the current version
'''
    if frameworks:
        routine += '\n## Framework-Specific Rules\n'
        for fw in frameworks:
            routine += f'- {fw}: always search "{fw} latest API" before using\n'

    claude_md_path = os.path.join(project_dir, 'CLAUDE.md')
    with open(claude_md_path, 'a') as f:
        f.write(routine)
    print(f'MCP config written to {mcp_path}')
    print(f'Search routine appended to {claude_md_path}')

setup_pre_coding_routine('.', 'YOUR_API_KEY', ['Next.js', 'Stripe', 'Prisma'])

JavaScript 示例

JavaScript
const fs = require('fs');

function setupPreCodingRoutine(projectDir, apiKey, frameworks = []) {
  const mcpConfig = {
    mcpServers: {
      scavio: {
        url: 'https://mcp.scavio.dev/mcp',
        headers: {Authorization: \`Bearer \${apiKey}\`}
      }
    }
  };
  fs.writeFileSync(\`\${projectDir}/.mcp.json\`, JSON.stringify(mcpConfig, null, 2));

  let routine = \`
## Pre-Coding Search Routine
Before writing code that uses an external library or API:
1. Search for the current version
2. Search for the API signature or reference docs
3. Check for recent breaking changes
4. Verify import paths match the current version
\`;
  if (frameworks.length) {
    routine += '\n## Framework-Specific Rules\n';
    frameworks.forEach(fw => {
      routine += \`- \${fw}: always search "\${fw} latest API" before using\n\`;
    });
  }
  fs.appendFileSync(\`\${projectDir}/CLAUDE.md\`, routine);
  console.log('MCP config and search routine configured');
}

setupPreCodingRoutine('.', 'YOUR_API_KEY', ['Next.js', 'Stripe', 'Prisma']);

预期输出

JSON
MCP config written to .mcp.json
Search routine appended to CLAUDE.md
Claude Code now searches docs and API references before writing code.

相关教程

  • 如何将 MCP 搜索添加到 Claude 代码
  • 如何通过结构化搜索奠定本地法学硕士的基础
  • 如何将 MCP 搜索添加到 Cursor IDE

常见问题

大多数开发者在15到30分钟内完成本教程。您需要一个Scavio API密钥(免费套餐即可)和可用的Python或JavaScript环境。

克劳德代码安装和配置. 来自 scavio.dev 的 Scavio API 密钥. 带有 CLAUDE.md 的项目目录. Scavio API密钥注册即送50个免费积分。

可以。免费套餐注册即送50个积分,完全足够完成本教程并构建一个可运行的原型解决方案。

Scavio提供原生LangChain包(langchain-scavio)、MCP服务器以及适用于任何HTTP客户端的REST API。本教程使用 the raw REST API, 但您可以根据需要适配您选择的框架。

相关资源

Comparison

MCP Search Integration vs Direct API Integration

Read more
Best Of

Google I/O 2026 AI模式变化后最佳搜索API

Read more
Glossary

搜索 API 供应商格局(2026)

Read more
Best Of

2026 年 MCP 服务器最佳搜索 API

Read more
Use Case

MCP 自定义搜索服务器

Read more
Use Case

用于业务运营的 MCP 自定义 API 集成

Read more

开始构建

在 Claude Code 中配置 MCP 搜索,以便代理在编写代码之前自动搜索文档和 API。通过实时查找防止使用过时的 API。

获取免费API密钥阅读文档
ScavioScavio

面向AI智能体的实时搜索API。搜索所有平台,不仅仅是Google。

产品

  • 功能
  • 定价
  • 控制台
  • 联盟计划

开发者

  • 文档
  • API参考
  • 快速开始
  • MCP集成
  • Python SDK

替代方案

  • Tavily替代方案
  • SerpAPI替代方案
  • Firecrawl替代方案
  • Exa替代方案

工具

  • JSON格式化
  • cURL转代码
  • Token计数器
  • 全部工具

© 2026 Scavio. 保留所有权利。

Featured on TAAFT
服务条款隐私政策