Relace MCP Server
非官方 Relace MCP 服务器
非官方 — 个人项目,与 Relace 无关联。
AI 构建 — 完全在 AI 辅助下开发(Antigravity、Codex、Cursor、Github Copilot、Windsurf)。
MCP 服务器,提供 AI 驱动的代码编辑和智能代码库探索工具。
无此工具 | 使用 |
手动 grep,容易遗漏相关文件 | 自然语言提问,获取精确位置 |
编辑导致其他地方导入错误 | 追踪导入和调用链 |
全量重写消耗大量 tokens | 描述变更,无需行号 |
行号错误导致代码损坏 | 10,000+ tokens/秒合并 |
功能特性
快速应用 (Fast Apply) — 通过 Relace API 以 10,000+ tokens/秒的速度应用代码编辑
智能搜索 (Agentic Search) — 基于自然语言查询的智能代码库探索
智能检索 (Agentic Retrieval) — 混合语义提示 + 实时代码探索,支持陈旧提示和显式云端维护(通过
MCP_SEARCH_RETRIEVAL=1启用;使用MCP_RETRIEVAL_BACKEND选择后端)云端搜索 (Cloud Search) — 对云端同步仓库进行语义代码搜索
Related MCP server: code-context
快速开始
使用 relace 后端(默认):从 Relace 控制台 获取 API 密钥,然后添加到您的 MCP 客户端:
~/.cursor/mcp.json
{
"mcpServers": {
"relace": {
"command": "uv",
"args": ["tool", "run", "relace-mcp"],
"env": {
"RELACE_API_KEY": "rlc-your-api-key",
"MCP_BASE_DIR": "/absolute/path/to/your/project"
}
}
}
}claude mcp add relace \
--env RELACE_API_KEY=rlc-your-api-key \
--env MCP_BASE_DIR=/absolute/path/to/your/project \
-- uv tool run relace-mcp~/.codeium/windsurf/mcp_config.json
{
"mcpServers": {
"relace": {
"command": "uv",
"args": ["tool", "run", "relace-mcp"],
"env": {
"RELACE_API_KEY": "rlc-your-api-key",
"MCP_BASE_DIR": "/absolute/path/to/your/project"
}
}
}
}.vscode/mcp.json
{
"mcp": {
"servers": {
"relace": {
"type": "stdio",
"command": "uv",
"args": ["tool", "run", "relace-mcp"],
"env": {
"RELACE_API_KEY": "rlc-your-api-key",
"MCP_BASE_DIR": "${workspaceFolder}"
}
}
}
}
}~/.codex/config.toml
[mcp_servers.relace]
command = "uv"
args = ["tool", "run", "relace-mcp"]
[mcp_servers.relace.env]
RELACE_API_KEY = "rlc-your-api-key"
MCP_BASE_DIR = "/absolute/path/to/your/project"配置
变量 | 必需 | 描述 |
| ✅* | 来自 Relace 控制台 的 API 密钥;Relace 提供商和云端工具必需 |
| ❌ | 设置为 |
| ❌ | 语义检索后端: |
| ❌ | 检索提示策略: |
| ❌ | 本地索引定期刷新监控(可选);需要固定的 |
| ❌ | 本地索引定期监控间隔(秒,默认: |
| ❌ | 首次定期本地索引检查前的初始延迟(秒,默认: |
| ❌ | 轮次状态用户消息策略: |
| ❌ | 在搜索运行期间启用 |
| ❌ | 启用 LSP 辅助搜索: |
| ❌ | 项目根目录覆盖(通过 MCP Roots → Git → 工作区存储 → CWD 自动检测) |
| ❌ | 文件日志记录: |
| ❌ | 用于集中配置的 |
* 如果满足以下两者,则可选:(1) APPLY_PROVIDER 和 SEARCH_PROVIDER 为非 Relace 提供商,且 (2) MCP_RETRIEVAL_BACKEND 为 codanna、chunkhound 或 none。
有关 .env 使用、编码设置、自定义 LLM 提供商等更多信息,请参阅 docs/advanced.md。
工具
始终可用:fast_apply、agentic_search。agentic_retrieval 需要 MCP_SEARCH_RETRIEVAL=1。云端工具仅在 MCP_RETRIEVAL_BACKEND=relace 时可用。index_status 适用于 relace、codanna 和 chunkhound,在 MCP_RETRIEVAL_BACKEND=none 时隐藏。
使用 MCP 原生发现界面:list_tools() 获取工具,list_resources() 获取资源。
有关详细参数,请参阅 docs/tools.md。
语言支持
LSP 工具使用您系统上安装的外部语言服务器。
语言 | 语言服务器 | 安装命令 |
Python | basedpyright | (已捆绑) |
TypeScript/JS | typescript-language-server |
|
Go | gopls |
|
Rust | rust-analyzer |
|
仪表盘
用于监控操作的实时终端 UI。
pip install relace-mcp[tools]
relogs有关详细用法,请参阅 docs/dashboard.md。
基准测试
使用 Loc-Bench 代码定位数据集评估 agentic_search 性能。
git clone https://github.com/possible055/relace-mcp.git
cd relace-mcp
uv sync --extra benchmark
# Build dataset from Hugging Face
uv run --extra benchmark python -m benchmark.cli.build_locbench --output artifacts/data/raw/locbench_v1.jsonl
# Run evaluation
uv run --extra benchmark python -m benchmark.cli.run --dataset artifacts/data/raw/locbench_v1.jsonl --limit 20所有基准测试产物均写入 benchmark/.data/ 下。
有关网格搜索、分析工具和指标解读,请参阅 docs/benchmark.md。
平台支持
平台 | 状态 | 备注 |
Linux | ✅ 完全支持 | 主要开发平台 |
macOS | ✅ 完全支持 | 所有功能可用 |
Windows | ⚠️ 部分支持 |
|
故障排除
错误或消息 | 解决方案 |
| 使用 Relace 提供商或云端工具时设置 |
| 在目标块附近包含 1-3 个唯一的锚点行 |
| 验证路径是否存在且位于 |
| 文件超过 10MB;将更改拆分为更小的文件或编辑 |
| 为非 UTF-8 项目显式设置 |
| 验证 API 密钥和提供商配置 |
| 稍后重试或减少请求量 |
| 检查网络访问并重试 |
| 添加更具体的锚点或具体的行,以便合并能产生差异 |
| 确保占位符标记仅用作占位符,而非预期的字面输出 |
| 拆分大型删除密集型编辑或使用显式的删除指令 |
| 将更改拆分为更小、更局部的编辑 |
开发
git clone https://github.com/possible055/relace-mcp.git
cd relace-mcp
uv sync --extra dev --extra benchmark
uv run pytest
uv run --extra dev --extra benchmark pytest benchmark/tests -q许可证
MIT
Available Tools
7 toolsagentic_searchARead-onlyIdempotent
Search codebase for code locations matching a query.
Use when you know the name or structure you're looking for — function names, class names, modules, or how components connect. For conceptual/behavioral queries without known identifiers, use agentic_retrieval instead.
Returns file paths with line ranges and an explanation of findings. Keys: explanation (str), files (dict[path → {lines, snippet}]), turns_used (int).
Inputs: query (required). Returns: object
cloud_clearADestructive
Delete cloud repository and local sync state. IRREVERSIBLE.
Removes all indexed data from Relace Cloud. Use cloud_list to find repo IDs.
Inputs: confirm, repo_id. Returns: object
cloud_listARead-onlyIdempotent
[ADMIN] List all repositories in your Relace Cloud account.
Use to find repo_id for cloud_clear. Not needed for normal search/sync workflow. Returns repository IDs, names, and indexing status.
Inputs: no named parameters. Returns: object
cloud_searchARead-onlyIdempotent
Search for code by meaning using AI embeddings. Requires cloud_sync first.
Use for conceptual queries where you don't know the exact file, class, or function name. Prefer agentic_search when you know the exact identifier or symbol name.
Prerequisite: cloud_sync must have been run at least once. Fails if RELACE_API_KEY is not set or no sync state exists.
Returns: {results (list), result_count (int), warnings (list[str]), query (str), branch (str), repo_id (str)}. Check warnings[] for stale index alerts (e.g., uncommitted local changes).
Inputs: query (required), branch. Returns: object
cloud_syncAIdempotent
Upload or refresh codebase to Relace Cloud for semantic search.
Check index_status() first—skip this if cloud freshness is already 'fresh'. Syncs git-tracked files to enable cloud_search. Incremental by default.
Advanced (Relace-specific): force=True Re-upload all files; use after large refactors. force=True+mirror=True Delete cloud files absent locally; use after branch switch.
Returns: {sync_mode (str), files_created (int), files_updated (int), files_deleted (int), files_unchanged (int), warnings (list[str]), repo_id (str), repo_head (str)}. Check warnings[] for truncation or suppressed deletes. Fails if not in a git repo or RELACE_API_KEY is not set.
Inputs: force, mirror. Returns: object
fast_applyADestructive
Edit or create a file using intelligent merging.
For new files: writes content directly. For existing files: merges edit_snippet with current content using anchor lines. Anchor lines are verbatim lines copied from the existing file that help locate the exact edit target. Include 1-2 unique lines adjacent to the change. Truncation markers are recommended for larger scoped edits but not required. Markdown files keep fenced code blocks verbatim; outer fence stripping is skipped for .md/.mdx targets.
On error, the response includes a code field:
NEEDS_MORE_CONTEXT: merge model could not locate the target - add 1-2 unique anchor lines from immediately around the edit location.
APPLY_NOOP: merge returned an identical file even though the snippet contained explicit remove directives or concrete new lines not present in the original.
BLAST_RADIUS_EXCEEDED: edit scope too large - split into smaller edits.
MARKER_LEAKAGE: placeholder marker text leaked into merged output (treated as literal text).
TRUNCATION_DETECTED: merged output shrank drastically and no explicit remove directive was provided.
On success: {status: "ok", diff: str | None (unified diff, None for new files or no-op)}.
Do NOT use this tool to delete files or clear file contents. Use a dedicated file management tool for those operations.
Inputs: path (required), edit_snippet (required), instruction. Returns: object
index_statusARead-onlyIdempotent
Inspect the single active indexing backend in read-only mode.
Use this before retrieval when you need to know whether the active backend is fresh and
whether semantic hints are usable. Returns active_backend, a single backend status
object with freshness and hints_usable, and background_monitor (state, reason).
This tool never refreshes indexes; if active_backend is relace and
backend.status.needs_sync is true, run cloud_sync().
Inputs: no named parameters. Returns: trace_id, active_backend, base_dir, base_dir_source, +3 more
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool has a clearly distinct purpose with descriptions that explicitly differentiate similar tools (e.g., agentic_search vs cloud_search based on query type). There is no functional overlap.
Cloud operations use a consistent 'cloud_' prefix, but 'agentic_search', 'fast_apply', and 'index_status' break the pattern. Mix of verb_noun and adjective_noun styles reduces predictability.
Seven tools is well-scoped for a code search and editing server. Each tool addresses a specific need without redundancy or excessive complexity.
Covers search (local and cloud) and file editing, but lacks tools for reading full file content, deleting files, or managing local files beyond edits. Users may need to rely on external tools for basic operations.
Maintenance
Related MCP Connectors
Codebase intelligence for AI agents — dead code, blast radius, ownership.
Discover, compare, and monitor 1,400+ APIs directly from your AI coding agent.
Code intelligence for LLMs. Analyze, search, and retrieve code from any public git repository.
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Related MCP Servers
- AlicenseNot gradedqualityFmaintenanceProvides AI-powered code intelligence for any codebase using local LLMs and vector search, enabling semantic code search, pattern analysis, and context-optimized code generation with 90% token savings.2MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI coding assistants to automatically scan, store, and query API endpoints from codebases, providing instant lookup and semantic search to reduce context switching and token consumption.1MIT
- AlicenseNot gradedqualityNot gradedmaintenanceMake any LLM a codebase expert instantly. Provides deep code intelligence through semantic search, architecture mapping, security analysis, and smart context that fits perfectly in token windows.MIT
- AlicenseNot gradedqualityCmaintenanceProvides structured, token-efficient code context for AI assistants by indexing codebases with AST-level analysis, supporting 17+ languages, enabling semantic search, call-site tracking, and PR attribution.70 PyPI52MIT