DEV Community

Mikoshiba Kyu
Mikoshiba Kyu

Posted on

Managing GitHub Copilot CLI MCP Server Configuration in Your Repository

Introduction

When developing with GitHub Copilot CLI, MCP server configuration typically depends on each developer's individual environment.
However, in team development, there's a need to "standardize the MCP servers used within the repository."

This article explains how to include GitHub Copilot CLI MCP configuration in your repository using VSCode + WSL2 + DevContainers environment.

Background and Challenges

Environment

  • VSCode
  • WSL2 + DevContainers

Why Include MCP Configuration in the Repository?

Required MCP servers differ based on project characteristics.
For example, Chrome DevTools MCP is useful for web application development, but unnecessary for other types of projects.
On the other hand, code analysis tools like Serena might be desired across all repositories.

Currently, you need to document "Please install this MCP server" in the README's development environment setup section.
This requires each developer to manually install, leading to version differences or some people skipping installation due to inconvenience.
As a result, discrepancies in development environments within the team tend to arise.

Claude Code allows you to load MCP configuration by placing a .mcp.json file,
and also provides a mechanism called Claude Code Plugin for creating and sharing plugin store repositories.

Both of these features would be incredibly desirable for GitHub Copilot...
However, the current GitHub Copilot CLI requires workarounds.

The Challenge

In GitHub Copilot CLI, when you add configuration using the /mcp add command, it's saved by default in the ~/.copilot directory.
GitHub Copilot CLI then references this configuration in the home directory to operate.

In other words, MCP configuration sits outside the repository as a personal user setting.

Solution

1. Place MCP Configuration File in Repository

First, place .copilot/mcp-config.json in the project root directory.
Here's an example with Serena configuration.

{
  "mcpServers": {
    "serena": {
      "type": "local",
      "command": "uvx",
      "tools": ["*"],
      "args": [
        "--from",
        "git+https://github.com/oraios/serena",
        "serena",
        "start-mcp-server",
        "--context",
        "ide-assistant"
      ],
      "env": {}
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

2. Exclude Unnecessary Files in .gitignore

The .copilot directory generates files specific to individual environments, such as logs and config.json.
Since only the MCP configuration file should be committed, exclude them in .gitignore.

+ .copilot/logs/
+ .copilot/config.json
Enter fullscreen mode Exit fullscreen mode

3. Change GitHub Copilot CLI Configuration Directory in DevContainers

Configure DevContainers' postCreateCommand to execute postCreateCommand.sh,
where you change the GitHub Copilot CLI configuration directory.
Below is an example for zsh, specifying the project root.

+ GH_CLI_CONFIG_DIR="/workspaces/your-repo"

+ if ! grep -q 'export XDG_CONFIG_HOME=' ~/.zshrc; then
+     echo "export XDG_CONFIG_HOME=\"$GH_CLI_CONFIG_DIR\"" >> ~/.zshrc
+ fi
Enter fullscreen mode Exit fullscreen mode

4. Verification

Rebuild the DevContainer and launch GitHub Copilot CLI.
With the /mcp show command, you can confirm that Serena is loaded as shown below.

● MCP Server Configuration:

  • serena (local): Command: uvx

  Total servers: 1
  Config file: /workspaces/your-repo/.copilot/mcp-config.json
Enter fullscreen mode Exit fullscreen mode

The Config file path points to .copilot/mcp-config.json within the repository.

Conclusion

Now we can handle MCP servers at the same level as Claude Code's .mcp.json.

Looking at Awesome Copilot, it seems the philosophy is that MCP server configuration is a personal setting.
I hope MCP configuration will migrate to a similar structure, making this article obsolete.

References

Top comments (0)