Emacs MCP Server

Emacs MCP Server

site icon
2025.04.17 0
JavaScriptEmacs 集成语言模型接口开发效率
Emacs MCP Server 是一个简单的 MCP(Model Context Protocol)服务器,允许语言模型通过 `emacsclient --eval` 命令与 Emacs 交互,并查看 Emacs 的当前状态。
View on GitHub

Overview

基本能力

产品定位

Emacs MCP Server 是一个用于连接语言模型(如 Claude)与 Emacs 的桥梁,使得语言模型可以查询和操作 Emacs 的状态。

核心功能

  • emacs_eval: 评估 Emacs Lisp 表达式并返回结果
  • emacs_get_visible_text: 获取当前 Emacs 窗口中可见的文本
  • emacs_get_context: 获取当前 Emacs 状态的上下文信息(缓冲区、模式、点位置等)

适用场景

  • 语言模型辅助 Emacs 用户进行代码编辑
  • 查询 Emacs 当前状态(如缓冲区列表、当前文件等)
  • 自动化 Emacs 操作

工具列表

  1. emacs_eval: 执行任意 Emacs Lisp 代码
  2. emacs_get_visible_text: 获取当前窗口可见文本
  3. emacs_get_context: 获取 Emacs 上下文信息

常见问题解答

  • 安全性:该服务器可以执行任意 Emacs Lisp 代码,具有完全访问权限,请谨慎使用
  • 兼容性:需要 Emacs 服务器已启动(M-x server-start

使用教程

使用依赖

  • Node.js
  • 已启动 Emacs 服务器(在 Emacs 中执行 M-x server-start

安装教程

无需安装,直接使用 npx 运行:

npx -y @keegancsmith/emacs-mcp-server

配置 Claude for Desktop

  1. 确保 Emacs 服务器已启动
  2. 修改 Claude 配置文件(位置取决于操作系统)
  3. 添加如下配置并重启 Claude:
{
  "mcpServers": {
    "emacs-mcp": {
      "command": "npx",
      "args": [
        "-y", "@keegancsmith/emacs-mcp-server"
      ]
    }
  }
}

调试方式

  • 测试 emacs_eval: 让 Claude 执行:(buffer-list)
  • 测试 emacs_get_visible_text: 让 Claude 获取当前窗口文本
  • 测试 emacs_get_context: 让 Claude 查询当前编辑的文件

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。