GitHub Copilot layer
Table of ContentsClose
1. Description
This layer enables usage of GitHub Copilot in Spacemacs.
It provides code completion, chat-based AI interaction, and a powerful framework for integrating external AI tools and models.
1.1. Features:
- AI powered code completions using copilot.el.
- AI chat interactions using copilot-chat.el.
- AI tool integration via mcp.el, allowing the chat AI to run commands, interact with the filesystem, and more. [EXPERIMENTAL]
- Automatic generation of git commit messages.
2. Install
To use this configuration layer, add it to your `~/.spacemacs`. You will need to add `github-copilot` to the existing `dotspacemacs-configuration-layers` list in this file.
2.1. Prerequisites
This layer requires external components to be fully functional.
Copilot Language Server: The core `copilot.el` package requires the language server. It can be installed manually with:
$ npm install -g @github/copilot-language-server
Or, you can install it from within Emacs:
SPC SPC copilot-install-server
- Python 3 (for MCP Tools): While the layer itself does not require it, most useful MCP servers (like the filesystem or shell servers) are Python-based scripts. Please ensure you have a `python3` (or `python`) command available in your system's `PATH` to run them.
MCP Server Installation (Manual): This layer does not install MCP servers for you. You must install them manually. For example, the common filesystem server is a Node.js package.
$ npm install -g @modelcontextprotocol/server-filesystem
3. Configuration
The Copilot service must be logged into.
- For code completion: run `SPC SPC copilot-login`.
- For chat: the chat interface will prompt for a separate login the first time it is started.
3.1. Git Commit Messages
To enable automatic generation of git commit messages using copilot-chat, set the layer variable `github-copilot-enable-commit-messages` to `t` in your `~/.spacemacs` file.
(github-copilot :variables github-copilot-enable-commit-messages t)
Alternatively, you can invoke `SPC SPC copilot-chat-insert-commit-message` manually within a Git commit buffer.
3.2. MCP / Tool Integration (Manual Setup Required)
This layer provides powerful tool-using capabilities to the AI chat by integrating `mcp.el` (Model Context Protocol).
This framework requires manual configuration. The layer provides the `github-copilot-mcp-servers` variable (which is `nil` by default) for you to define your servers.
You must add your server list to the `dotspacemacs/user-config` function in your `~/.spacemacs` file after the `mcp-hub` package is loaded.
3.2.1. Example: Enabling the Filesystem Server *
First, install the server (this requires Node.js / `npx`):
$ npm install -g @modelcontextprotocol/server-filesystem
Then, add the following code to your `dotspacemacs/user-config`:
(defun dotspacemacs/user-config () ;; ... (with-eval-after-load 'mcp-hub ;; This list is the "Single Source of Truth" (setq github-copilot-mcp-servers '(;; Add the filesystem server ;; It must be installed (e.g., via "npm install -g @modelcontextprotocol/server-filesystem") ("fs" . (:command "npx" :args ("-y" "@modelcontextprotocol/server-filesystem" ;; This path MUST be absolute and point to your projects "/home/your-user/projects"))))) ;; We must also tell the mcp-hub to use this new list (setq mcp-hub-servers github-copilot-mcp-servers)) )
3.2.2. Finding More Servers *
You can add any MCP-compliant server to this list (like a local Ollama instance). You can find more servers to install and use here:
- Official MCP Repo: https://github.com/lizqwerscott/mcp.el
- Server Directory: https://www.mcpserver.directory/
4. Key bindings
4.1. General
| Key binding | Description |
|---|---|
| `C-M-<return>` | accept the current completion suggestion |
| `C-M-S-<return>` | accept the current completion suggestion word by word |
| `C-M-<tab>` | show the next github copilot completion (and refresh) |
| `C-M-<iso-lefttab>` | show the previous github copilot completion (and refresh) |
| `SPC $ c` | Start a transient state for the Copilot chat interface |
| `SPC $ m` | Open the `*Mcp-Hub*` buffer to manage/view tool servers |
4.2. In Chat
| Key binding | Description |
|---|---|
| `,,` | Send the current text to Copilot (in Normal mode) |
| `,a` | Kill the chat process (in Normal mode) |
| `,k` | Kill the chat process (in Normal mode) |
| `C-c C-c` | Send the current text to Copilot (in Prompt buffer) |
| `C-c C-a` | Kill the chat process (in Prompt buffer) |
| `C-c C-k` | Kill the chat process (in Prompt buffer) |