-
Notifications
You must be signed in to change notification settings - Fork 458
WIP: app: Add MCP server support for ai-assistant #4135
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds Model Context Protocol (MCP) integration to Headlamp, enabling AI-assisted operations through external MCP servers. The implementation includes a comprehensive MCP client system with tool state management, settings configuration, and security controls.
Key changes:
- Adds
@langchain/mcp-adaptersv0.6.0 dependency with peer dependencies for MCP server integration - Implements MCPClient for managing multi-server MCP connections and tool execution
- Creates MCPToolStateStore for managing tool enable/disable state and usage tracking
- Adds settings management layer for MCP server configuration
- Integrates MCP client lifecycle into Electron main process
Reviewed Changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| app/package.json | Adds @langchain/mcp-adapters dependency and includes new MCP source files in build |
| app/package-lock.json | Locks dependency versions for @langchain/mcp-adapters and transitive dependencies |
| app/electron/settings.ts | New generic settings load/save functions extracted from runCmd.ts |
| app/electron/settings.test.ts | Comprehensive tests for settings persistence |
| app/electron/runCmd.ts | Refactored to use shared settings functions |
| app/electron/preload.ts | Exposes MCP client APIs to renderer process |
| app/electron/mcp/MCPClient.ts | Core MCP client managing server connections and tool execution |
| app/electron/mcp/MCPClient.test.ts | Tests for MCPClient initialization and lifecycle |
| app/electron/mcp/MCPToolStateStore.ts | Manages tool configuration, state, and usage statistics |
| app/electron/mcp/MCPToolStateStore.test.ts | Tests for tool state management |
| app/electron/mcp/MCPSettings.ts | MCP-specific settings loading and server configuration |
| app/electron/mcp/MCPSettings.test.ts | Tests for MCP settings management |
| app/electron/main.ts | Integrates MCP client initialization and cleanup |
| app/.gitignore | Ignores transpiled JavaScript files for MCP modules |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There's supposed to be an AT in front of langchain package name but it's not there because k8s bot. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
- Add some basic tests - Add a ENABLE_MCP at top of main.ts to allow easily disabling MCP Set HEADLAMP_MCP_ENABLE=false to disable MCP features. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
…and persistence Introduce MCPToolStateStore class to track tool enabled/disabled state, usage statistics, input schemas and descriptions, with load/save and helpers to initialize, query, and replace configs. MCPClient.mcpToolState is the MCPToolStateStore The config can be initialized async for fast app loading. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
…omponents Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
This summarizes MCP tool state changes (added, removed, enabled, disabled) across servers and include unit tests covering key cases. Useful for showing concise change counts and ENABLE/DISABLE summaries in the UI before applying config updates. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
This initialzes the MCPToolStateStore with tools from MultiServerMCPClient.getTools(). Completely replacing the existing config with these current tools. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
For validating tool arguments against a schema. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
Show detailed confirmation dialog for tools configuration changes. Compares current and new configurations and displays a summary of changes. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
So that the tools can get expanded environment variables and paths. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
Make mpcServers from settings for the mpcServers arg of MultiServerMCPClient. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
settingsChanges returns a list of human-readable descriptions of changes between the current settings and the next settings. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
Shows a dialog asking user for confirmation if MCP settings changes are ok. Displays a summary of changes between currentSettings and nextSettings. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
Check if any server in the settings uses HEADLAMP_CURRENT_CLUSTER placeholder. This determines whether the MCP client needs to be restarted on cluster changes. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
Show user confirmation dialog for MCP operations. Displays a dialog to the user for security confirmation before executing MCP operations. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: illume The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…pters
- MCPClient accepts settingsPath and manages init lifecycle of MultiServerMCPClient
- initializeClient and doInitializeClient to prevent duplicate inits
- caches clientTools and client instance, tracks isInitialized and init promise
- cleanup and close logic for client
- constructs MultiServerMCPClient with options and populates MCPToolStateStore
- handles cluster changes: no-op when identical, skips restart if no cluster-dependent servers,
restarts client when necessary and restores state on error
- Add tests for initialization, empty-server handling, tool caching,
and cluster-change behaviors.
Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
Implement a private mcpExecuteTool on MCPClient that: - parses server/tool names via MCPToolStateStore helpers, - validates arguments with validateToolArgs, - checks whether the tool is enabled, - invokes the tool and records usage via mcpToolState, - returns a structured success/error result (including toolCallId). This will be used via Electron ipc from the frontend/. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
Added these ipc methods: mcp-execute-tool mcp-get-status mcp-reset-client mcp-update-config mcp-get-config mcp-get-tools-config mcp-update-tools-config mcp-set-tool-enabled mcp-get-tool-stats mcp-cluster-change These will be used via Electron ipc from the frontend/. Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
Co-Authored-By: Ashu Ghildiyal <aghildiyal@microsoft.com>
|
I will keep this comment updated to bugs I find.
|
Adds support for running MCP (Model Context Protocol) servers from the desktop app by integrating
@langchain/mcp-adapterslibrary and creating a client architecture to manage MCP server connections.Continued on from:
Related to:
app: Add @langchain/mcp-adapters 1.0.0Screenshots
WIP: include all the dialogs with summaries and changes shown too.
How to test
WIP: need to improve instructions to cover all functionality, and how to use it.
Other things to test: