-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Automatically remove duplicate manual MCP servers from configuration files #4646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
When the bundled MCP provider is used (VS Code >= 1.101.0 with MCP API support), automatically detect and uninstall any duplicate manual MCP installations that were previously set up via the CLI when the IDE didn't support bundled MCP. This prevents duplicate MCP servers from coexisting when an IDE adds support for VS Code's native MCP API. Co-authored-by: sergeibbb <[email protected]>
@copilot |
Instead of using `gk mcp uninstall` command (which doesn't work properly), directly analyze and modify MCP configuration JSON files in user profile. The implementation: - Locates the IDE-specific settings.json file based on app name and platform - Reads and parses the file (handling JSON comments) - Identifies GitKraken MCP servers by name pattern, command path, and source flag - Removes duplicate manual installations - Saves the updated configuration This approach provides proper cleanup of duplicate manual MCP installations when the bundled MCP provider becomes available. Co-authored-by: sergeibbb <[email protected]>
Updated implementation in commit e380a84. Now directly analyzes and modifies MCP configuration JSON files in the user profile instead of relying on
Supports all major platforms (Windows, macOS, Linux) and IDEs. |
@copilot What do you think about using |
Instead of manually constructing platform-specific paths, use VS Code's globalStorageUri and navigate up 2 levels to reach the User folder. Benefits: - More reliable - VS Code tells us where it stores files - Simpler code - removed ~70 lines of platform-specific logic - Handles custom installation paths automatically - Works for all IDEs that support VS Code extensions globalStorageUri points to: .../[AppName]/User/globalStorage/eamodio.gitlens Going up 2 levels gets: .../[AppName]/User/ Then append settings.json to get the settings file path. Co-authored-by: sergeibbb <[email protected]>
Great suggestion! Implemented in commit 5d27028. Using
The globalStorageUri approach is simpler and more maintainable. |
Problem
When GitLens is unable to bundle the GitKraken MCP server (typically when an IDE doesn't support VS Code's native MCP API), a manual setup process is required. The manual setup uses the GK CLI to install the MCP server directly into the IDE's configuration files.
If an IDE later adds support for VS Code's bundled MCP API (>= 1.101.0), both the bundled and manually installed MCP servers can coexist simultaneously. This results in duplicate GitKraken MCP servers being registered, which can cause confusion and potential conflicts.
Solution
This PR implements automatic cleanup of duplicate manual MCP installations by directly analyzing and modifying the IDE's configuration JSON files:
The cleanup process:
globalStorageUri
to locate the User folder (by going up 2 directory levels)--source=gitlens
flaglanguageModels.chat.mcpServers
Changes
Core Implementation
src/env/node/gk/mcp/integration.ts
:removeDuplicateManualMcpConfigurations()
method that directly modifies the settings.json fileUri.joinPath(globalStorageUri, '..', '..')
to reliably locate the User folderparseJsonWithComments()
to handle VS Code's JSON-with-comments formatisGitKrakenMcpServer()
to identify GitKraken MCP servers by checking name patterns, command paths, and source flagsPath Resolution
globalStorageUri
which points to:.../[AppName]/User/globalStorage/eamodio.gitlens
.../[AppName]/User/
settings.json
to get the settings file pathTelemetry
src/constants.telemetry.ts
: Addedmcp/uninstall/duplicate
telemetry event withMCPUninstallDuplicateEvent
interface to track cleanup operationsdocs/telemetry-events.md
: Auto-generated documentation for the new telemetry eventBenefits
--source=gitlens
flag)Testing
Fixes #4626
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.