使用说明
MCP符号编辑
状态:开发中。
符号级代码编辑MCP服务器。使用Tree-sitter解析技术而非基于文本的字符串匹配,浏览、读取、编辑、添加和删除代码符号(函数、类、变量)。
为何存在这一现象
Claude Code及其他代理编码工具采用基于文本的编辑方式,要求你必须提供精确的文本以进行替换,包括所有的空格和缩进。这种方式既脆弱又低效。而MCP Symbol Edit则是基于解析后的符号进行操作,使得编辑更加可靠且上下文高效。
安装
确保已安装UV。
uv --version
如果你还没有安装uv,请进行安装。
-
Linux
curl -LsSf https://astral.sh/uv/install.sh | sh -
macOS
brew install uv -
Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
添加到你的 mcp_config.json:
{
"mcpServers": {
"symbol-edit": {
"command": "uvx",
"args": ["mcp-symbol-edit"]
}
}
}
API
工具
-
浏览符号
- 列出文件中的所有顶级符号
- 输入:
file_path(字符串):源文件路径regex(字符串,可选):使用正则表达式模式过滤符号substring(字符串,可选):通过子字符串匹配过滤符号
- 返回格式化的字符串,列出符号签名:
def calculate_total(items: list) -> float class UserManager(BaseManager) class Product def validate_email(email: str) -> bool API_VERSION = "2.1.0" MAX_RETRIES = 3 -
读取符号
- 读取一个或多个符号的完整代码
- 输入:
file_path(字符串):源文件的路径symbol_names(字符串):用逗号分隔的符号名称(例如,“calculate_total,validate_email”)
- 返回每个符号的代码,各代码之间用空行分隔:
def calculate_total(items: list) -> float: return sum(item.price for item in items) def validate_email(email: str) -> bool: return "@" in email and "." in email -
编辑符号
- 替换一个符号的实现
- 输入:
file_path(字符串):源文件路径symbol_name(字符串):要编辑的符号的名称updated_code(字符串):要替换的新代码
- 返回值:
OK或者ERROR: Symbol 'foo' not found
-
添加符号
- 向文件中添加一个新符号
- 输入:
file_path(字符串):源文件的路径code(字符串):要插入的代码position(字符串):插入位置 - “之前”、“之后”、“顶部”、“底部”symbol(字符串,可选):对于“之前”和“之后”位置是必需的
- 返回值:
OK或者ERROR: Symbol 'foo' not found
-
删除符号
- 从文件中移除一个符号
- 输入:
file_path(字符串):源文件路径symbol_name(字符串):要删除的符号的名称
- 返回值:
OK或者ERROR: Symbol 'foo' not found
示例
浏览并阅读符号
Show me all functions in app.py that contain "user" in the name.
Read the calculate_total and validate_email functions from app.py.
编辑一个函数
Update the calculate_total function in app.py to use a more efficient implementation:
def calculate_total(items: list) -> float:
return sum(item.price * item.quantity for item in items)
添加一个新功能
Add this new function after calculate_total in app.py:
def calculate_discount(total: float, percent: float) -> float:
return total * (1 - percent / 100)
删除一个符号
Delete the deprecated_method function from app.py.
支持的语言
目前支持Python。计划增加对其他语言(JavaScript、TypeScript、Go、Rust等)的支持。
开发中
克隆仓库并安装依赖项:
git clone git@github.com:username/mcp-symbol-edit.git
cd mcp-symbol-edit
uv sync
然后将这个设置为 mcp_config.json:
{
"mcpServers": {
"symbol-edit": {
"command": "uv",
"args": ["run", "--directory", "/path/to/mcp-symbol-edit", "-m", "mcp_symbol_edit.server"]
}
}
}
做出贡献
欢迎贡献。开放问题用于报告错误或功能需求。提交拉取请求以进行改进。
许可证
版权所有 © 2025 Rune Kaagaard。保留所有权利。
获得使用和派生此软件的许可。 未经明确许可,禁止发布修改后的版本(包括发布到PyPI或其他包仓库)。