Project Idea: Emacs as a Model Context Protocol Client

Posted on Nov 26, 2024

On Nov 25th Anthropic AI of Claude fame published the v1 of their Model Context Protocol spec (MCP). I’ll let Anthropic describe it in their own words:

The Model Context Protocol is an open standard that enables developers to build secure, two-way connections between their data sources and AI-powered tools. The architecture is straightforward: developers can either expose their data through MCP servers or build AI applications (MCP clients) that connect to these servers.

Note that a context equates to a datasource. A database, filestore, document could all be considered contexts. MPC can be thought of as handling the “R” in Retrieval-augmented Generation (RAG) by defining a consistent protocol for how a client can pull from datasources.

A touchstone for comparison: Microsoft wrote the Language Server Protocol (LSP) back in 2016: by implementing a language server a programming language could expose useful dev features to any client implementing the protocol, e.g. auto-completion, in-line documentation, etc. For example, when I write Python in Emacs I use the pyright language server via the eglot client. The key value-add for developers is that it reduces the work of integrating programming languages and editors. Instead of each language / editor combination requiring an implementation (M x N), with LSP the integration only has to be solved once per language and once per editor (M + N). In the nine years since LSP was released an entire ecosystem of these LSP servers and clients have developed, and it’s been good. MCP might be poised to offer a similar advantage for AI contexts.

Just as LSP lowered the lift to integrate programming languages with editors, MCP could streamline the integration of AI tools with diverse datasources, fostering a similar ecosystem of compatibility. Going one step further, I think there’s an opportunity to contribute now, at this early stage, either by exposing contexts I find useful or connecting new clients. Like, Emacs.

An MCP client implemented within Emacs would allow LLMs to bring in context using any of the servers implemented for MCP. Because I tend to live in Emacs I prefer to call LLMs directly from it. An MCP client might keep the Emacs LLM experience cutting edge, letting me take advantage of a variety of datasources. Ideally, an Emacs MCP client should be usable by packages like chatgpt-shell, gptel, etc – it needs a chat interface to be useful.

MCP was released with some prior art: the Zed editor provides an example of an MCP being implemented in a software editor. The post shows context brought in from PostgreSQL, but it’d be able to take advantage of the context provided by any model context server.

I do see two major limitations that could hinder MCP’s adoption:

  • Only works with local MCP servers, i.e. you can only bring in context from your local environment, but it will be expanded to remote servers
  • Only works with an LLM that integrates the protocol, which as of the time of this writing is just Claude

Update 1/14/24: Others have taken the initiative. Here are some active Emacs MPC threads: