Skip to content

feat: update mcp add and mcp remove commands to support GitHub Copilot CLI#319

Open
timrogers wants to merge 2 commits intoPostHog:mainfrom
timrogers:timrogers/copilot-cli
Open

feat: update mcp add and mcp remove commands to support GitHub Copilot CLI#319
timrogers wants to merge 2 commits intoPostHog:mainfrom
timrogers:timrogers/copilot-cli

Conversation

@timrogers
Copy link
Copy Markdown

This adds the ability to configure GitHub Copilot CLI with the mcp add and mcp remove commands.

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 (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

Closes #318.

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>
Copilot AI review requested due to automatic review settings March 5, 2026 12:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CopilotCLIMCPClient in 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.

Comment on lines +120 to +146
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'),
);
});
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
@sarahxsanders sarahxsanders requested a review from a team March 5, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update mcp commands to support GitHub Copilot CLI

2 participants