
Emacs Lisp 对模型上下文协议的实现
概览
[https://github.com/laurynas-biveinis/mcp-server-lib.el/actions/workflows/elisp-test.yml] https://github.com/laurynas-biveinis/mcp-server-lib.el/actions/workflows/linter.yml] [https://melpa.org/#/mcp-server-lib] https://stable.melpa.org/#/mcp-server-lib] =mcp-server-lib.el= 是一个用于在 Emacs Lisp 中构建 [https://modelcontextprotocol.io/](MCP)服务器的库。它为 Emacs 包提供了基础设施,使其作为工具和资源的功能能够暴露给大型语言模型。 - 用于注册工具(Elisp函数)和资源的简单API——多服务器支持——带URI模式匹配的资源模板(RFC 6570子集)——处理MCP协议通信和JSON-RPC消息——通过emacsclient封装脚本实现Stdio传输——内置使用指标和调试支持 - Emacs 27.1 或更高版本 - 运行 Emacs 守护进程(用于 stdio 传输) - [https://github.com/laurynas-biveinis/elisp-dev-mcp] - Elisp 开发支持工具 - [https://github.
概述(AI 翻译)
#+标题:mcp-server-lib.el - Emacs Lisp 模型上下文协议服务器库
[[https://github.com/laurynas-biveinis/mcp-server-lib.el/actions/workflows/elisp-test.yml][https://github.com/laurynas-biveinis/mcp-server-lib.el/actions/workflows/elisp-test.yml/badge.svg]] [[https://github.com/laurynas-biveinis/mcp-server-lib.el/actions/workflows/linter.yml][https://github.com/laurynas-biveinis/mcp-server-lib.el/actions/workflows/linter.yml/badge.svg]] [[https://melpa.org/#/mcp-server-lib][https://melpa.org/packages/mcp-server-lib-badge.svg]] [[https://stable.melpa.org/#/mcp-server-lib][file:https://stable.melpa.org/packages/mcp-server-lib-badge.svg]]
- 概述
=mcp-server-lib.el= 是一个用于在 Emacs Lisp 中构建 [[https://modelcontextprotocol.io/][Model 上下文协议(MCP)服务器的库。它为 Emacs 包提供了基础设施,使其能够向大型语言模型展示其作为工具和资源的功能。
- 功能特征
- 用于注册工具(Elisp函数)和资源的简单API。
- 多服务器支持
- 带URI模式匹配的资源模板(RFC 6570子集)
- 处理MCP协议通信和JSON-RPC消息
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
#+TITLE: mcp-server-lib.el - Model Context Protocol Server Library for Emacs Lisp
[[https://github.com/laurynas-biveinis/mcp-server-lib.el/actions/workflows/elisp-test.yml][https://github.com/laurynas-biveinis/mcp-server-lib.el/actions/workflows/elisp-test.yml/badge.svg]] [[https://github.com/laurynas-biveinis/mcp-server-lib.el/actions/workflows/linter.yml][https://github.com/laurynas-biveinis/mcp-server-lib.el/actions/workflows/linter.yml/badge.svg]] [[https://melpa.org/#/mcp-server-lib][https://melpa.org/packages/mcp-server-lib-badge.svg]] [[https://stable.melpa.org/#/mcp-server-lib][file:https://stable.melpa.org/packages/mcp-server-lib-badge.svg]]
- Overview
=mcp-server-lib.el= is a library for building [[https://modelcontextprotocol.io/][Model Context Protocol]] (MCP) servers in Emacs Lisp. It provides the infrastructure for Emacs packages to expose their functionality as tools and resources to Large Language Models.
- Features
- Simple API for registering tools (Elisp functions) and resources
- Multi-server support
- Resource templates with URI pattern matching (RFC 6570 subset)
- Handles MCP protocol communication and JSON-RPC messages
- Stdio transport via emacsclient wrapper script
- Built-in usage metrics and debugging support
- Requirements
- Emacs 27.1 or later
- Running Emacs daemon (for stdio transport)
- MCP servers built on this library
- [[https://github.com/laurynas-biveinis/elisp-dev-mcp][elisp-dev-mcp]] - Elisp development support tools
- [[https://github.com/laurynas-biveinis/org-mcp][org-mcp]] - read and write Org content
- Installation
From [[https://melpa.org/#/mcp-server-lib][MELPA]] or [[https://stable.melpa.org/#/mcp-server-lib][MELPA Stable]]:
=M-x package-install RET mcp-server-lib RET=
- For Users
If you’re using an MCP server built with this library:
- Run =M-x mcp-server-lib-install= to install the stdio script
- The script will be at =~/.emacs.d/emacs-mcp-stdio.sh=
- Follow your MCP server’s documentation for client registration
Available commands:
- =M-x mcp-server-lib-start= - Start the MCP server
- =M-x mcp-server-lib-stop= - Stop the MCP server
- =M-x mcp-server-lib-describe-setup= - View registered tools and resources with usage statistics
- =M-x mcp-server-lib-show-metrics= - View usage metrics
- =M-x mcp-server-lib-uninstall= - Remove the stdio script
- For Developers
To build your own MCP server, see [[https://github.com/laurynas-biveinis/elisp-dev-mcp][elisp-dev-mcp]] for a complete example.
** Client Registration
Register your MCP server with a client using the stdio script:
#+BEGIN_EXAMPLE
claude mcp add -s user -t stdio your-server – ~/.emacs.d/emacs-mcp-stdio.sh
–init-function=your-init-func --stop-function=your-stop-func
#+END_EXAMPLE
Script options:
- =–init-function=NAME= - Emacs function to call on startup
- =–stop-function=NAME= - Emacs function to call on shutdown
- =–socket=PATH= - Custom Emacs server socket (optional)
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →