MCP Emacs
Emacs的模型上下文协议(MCP)工具作为单个Node.js MCP服务器包交付。
运行MCP服务器,使克劳德桌面/代码可以使用这些操作。 服务器自动引导Emacs Lisp负载。
特性
工具
| 工具 | 说明 |
|---|---|
get_buffer_content | 获取当前Emacs缓冲区的内容 |
get_current_clocked_task | 获取当前已登录的组织任务 |
get_current_task_at_point | 获取当前组织任务 |
get_buffer_filename | 获取与当前Emacs缓冲区关联的文件名 |
get_selection | 在Emacs中获取当前选择(地区) |
open_file | 在当前Emacs窗口中打开文件 |
edit_file_region | 通过指定开始/结束行和列坐标替换文件中的文本(可选保存) |
insert_at_point | 在点处插入文本或替换活动缓冲区中的当前选择 |
goto_line | 跳转到特定的行/列,或通过imenu直接导航到指定的函数 |
toggle_org_todo | 在当前组织标题上切换TODO关键字(或设置特定状态) |
describe_flycheck_info_at_point | 在光标处获取飞行检查诊断 |
get_error_context | 总结错误相关缓冲区的内容(*消息*, *警告*,编译日志) |
资源
| 资源 | 描述 |
|---|---|
org-tasks://all | 组织模式议程文件中的所有TODO项目,包括状态、优先级、计划/截止日期 |
buffer://messages | Emacs的实时内容 *Messages* 缓冲器 |
buffer://warnings | Emacs的实时内容 *Warnings* 缓冲器 |
先决条件
- Node.js 20+
- 运行服务器模式的Emacs(
M-x server-start或通过您的init文件) emacsclient在PATH中可用- 服务器自动引导Emacs Lisp帮助程序
配置 emacsclient 二进制
如果您的MCP主机进程没有继承相同的 PATH 作为shell,使用以下命令将服务器指向特定的二进制文件 MCP_EMACSCLIENT_PATH 环境变量(或旁路 { executable: "/full/path/to/emacsclient" } 实例化时 EmacsClient). 对于直接运行CLI时的ad-hoc覆盖,请提供 --emacsclient-executable /full/path/to/emacsclient 服务器将把该值传递给客户端。 当二进制文件存在但无法发现时,这些选项避免了“加载mcp-emacs引导负载失败”错误。
安装
1.安装/构建Node MCP服务器
你可以直接从npm使用服务器,也可以从这个仓库构建:
- 从npm安装 (出版后推荐)
npm install --global mcp-emacs-server
# or add to a specific project
npm install --save-dev mcp-emacs-server- 从源代码构建
npm install
npm run build这两种方法产生相同的CLI(mcp-emacs)以及 dist/index.js 入口点。
通过npx运行
直接使用已发布的包:
npx --yes mcp-emacs-serverCLI入口点仍然存在 mcp-emacs; npx 下载 mcp-emacs-server 打包并运行该二进制文件。
使用Claude代码
{
"emacs": {
"command": "node",
"args": ["/path/to/mcp-emacs/dist/index.js"]
}
}发展
npm run build # Single build
npm run watch # Rebuild on change
npm test # TypeScript unit testsEmacs Lisp帮助程序位于 elisp/mcp-emacs.el. 构建步骤将该文件嵌入到服务器引导负载中。
建筑
- Types/Node.js:MCP服务器实现(
mcp-emacs-server) - Emacs Lisp:嵌入式引导助手程序(从生成
elisp/mcp-emacs.el) - 消瘦症:通信桥(始终通过
--eval) - STDIO传输:标准MCP通信信道
流程图
源PlantUML定义位于 docs/architecture.puml 如果需要编辑或重新渲染图表。
需求
服务器仍然要求Emacs已经在启用服务器模式的情况下运行。 如果需要,请将此添加到您的init文件中:
(server-start)或者跑 M-x server-start 在启动MCP服务器之前手动。
