feat: update mcp add and mcp remove commands to support GitHub Copilot CLI#319
feat: update mcp add and mcp remove commands to support GitHub Copilot CLI#319timrogers wants to merge 2 commits intoPostHog:mainfrom
mcp add and mcp remove commands to support GitHub Copilot CLI#319Conversation
Add CopilotCLIMCPClient to configure the PostHog MCP server for the GitHub Copilot CLI. This is a JSON-file-based client like Cursor and VS Code, but with CLI-based detection like Codex. Key design decisions: - Detection: runs `copilot --version` (similar to Codex) rather than platform checks, since the CLI can be installed on any OS - Config path: ~/.copilot/mcp-config.json (macOS/Linux) or %USERPROFILE%\.copilot\mcp-config.json (Windows) - Config key: `mcpServers` (the default, same as Cursor/Claude Desktop) - Transport: streamable-http with native HTTP config (like Cursor) - Server config includes `type: "http"` field, which Copilot CLI requires for all entries (similar to VS Code's `type: "http"`) - OAuth mode omits the Authorization header, API key mode includes it Differs from VS Code in using `mcpServers` (not `servers`) and using USERPROFILE (not APPDATA) for the Windows config path. Differs from Cursor in adding the explicit `type: "http"` field. Differs from CLI-based clients (Claude Code, Codex) in writing a JSON config file rather than shelling out to a CLI subcommand. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds support for installing/removing the PostHog MCP server configuration in the GitHub Copilot CLI client, using Copilot CLI detection and a JSON config file in ~/.copilot/mcp-config.json (or %USERPROFILE%\.copilot\mcp-config.json on Windows).
Changes:
- Register a new
CopilotCLIMCPClientin the supported client list. - Implement Copilot CLI client detection (
copilot --version), config path resolution, and HTTP server config generation (OAuth vs API-key headers). - Add a dedicated Jest test suite covering support detection, config path logic, add/remove behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/steps/add-mcp-server-to-clients/index.ts |
Includes Copilot CLI in supported MCP clients so mcp add/remove can target it. |
src/steps/add-mcp-server-to-clients/clients/copilot-cli.ts |
Implements Copilot CLI client integration (detection, config path, server config). |
src/steps/add-mcp-server-to-clients/clients/__tests__/copilot-cli.test.ts |
Adds automated coverage for the new Copilot CLI client behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| it('should return correct path for Windows', async () => { | ||
| Object.defineProperty(process, 'platform', { | ||
| value: 'win32', | ||
| writable: true, | ||
| }); | ||
|
|
||
| const mockUserProfile = 'C:\\Users\\Test'; | ||
| process.env.USERPROFILE = mockUserProfile; | ||
|
|
||
| const configPath = await client.getConfigPath(); | ||
| expect(configPath).toBe( | ||
| path.join(mockUserProfile, '.copilot', 'mcp-config.json'), | ||
| ); | ||
| }); | ||
|
|
||
| it('should fall back to homedir on Windows when USERPROFILE is unset', async () => { | ||
| Object.defineProperty(process, 'platform', { | ||
| value: 'win32', | ||
| writable: true, | ||
| }); | ||
| delete process.env.USERPROFILE; | ||
|
|
||
| const configPath = await client.getConfigPath(); | ||
| expect(configPath).toBe( | ||
| path.join(mockHomeDir, '.copilot', 'mcp-config.json'), | ||
| ); | ||
| }); |
There was a problem hiding this comment.
This test suite mutates process.env.USERPROFILE but never restores the original value, which can leak state into other tests and cause order-dependent failures. Store the previous value (or undefined) and restore it in afterEach/afterAll (or reset it within each test that changes it).
This adds the ability to configure GitHub Copilot CLI with the
mcp addandmcp removecommands.This is a JSON-file-based client like Cursor and VS Code, but with CLI-based detection like Codex.
Key design decisions
copilot --version(similar to Codex) rather than platform checks, since the CLI can be installed on any OS~/.copilot/mcp-config.json(macOS/Linux) or%USERPROFILE%\.copilot\mcp-config.json(Windows)mcpServers(same as Cursor/Claude Desktop)type: "http"field, which Copilot CLI requires for all entries (similar to VS Code'stype: "http")Closes #318.