Skip to content

Conversation

@illume
Copy link
Contributor

@illume illume commented Nov 7, 2025

Adds support for running MCP (Model Context Protocol) servers from the desktop app by integrating @langchain/mcp-adapters library and creating a client architecture to manage MCP server connections.

Continued on from:

Related to:


  • app: Add @langchain/mcp-adapters 1.0.0
  • app: main: MCPClient: Add stub MCPClient class and hook it up to main

  • app: MCPToolStateStore: Add MCPToolStateStore for tool state, stats, and persistence
  • app: MCPToolStateStore: Add parseServerNameToolName to get separate components
  • app: MCPToolStateStore: Add summarizeMcpToolStateChanges and tests
  • app: MCPToolStateStore: Add initConfigFromClientTools
  • app: MCPToolStateStore: Add validateToolArgs
  • app: MCPToolStateStore: Add showToolsConfigConfirmationDialog

  • app: settings: runCmd: Extract loadSettings saveSettings into own module
  • app: MCPSettings: Add functions for load/save of mcp settings
  • app: MCPSettings: Add expandEnvAndResolvePaths to process env
  • app: MCPSettings: Add makeMcpServersFromSettings
  • app: MCPSettings: Add settingsChanges for human-readable changes
  • app: MCPSettings: Add showSettingsChangeDialog
  • app: MCPSettings: Add hasClusterDependentServers

  • app: MCPClient: Add showConfirmationDialog
  • app: main: MCPClient: Use MultiServerMCPClient from langchain/mcp-adapters
  • app: MCPClient: Add mcpExecuteTool
  • app: MCPClient: MCPSettings: Add setupIpcHandlers and ipc methods
  • app: preload: Add mcp APIs to be exposed to frontend/

Screenshots

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.

  1. Configure ai-assistant plugin. (Also from new PR).
  2. ... MCP servers
  3. ...
  • Enabling / Disabling a tool/mcp server
  • Security of ipc functions,
    • All of ipc functions that are dangerous ask for confirmation electron side first?
  • compiled mac app
    • existing functionality works
    • ai-assistant MCP functionality all works
  • compiled linux app
    • existing functionality works
    • ai-assistant MCP functionality all works
  • compiled windows app
    • existing functionality works
    • ai-assistant MCP functionality all works

Other things to test:

  • Set HEADLAMP_MCP_ENABLE=false to disable MCP features. The default is to enable MCP support, to switch it off by default see top of electron/main.ts
  • runCmd was changed the settings code was extracted from there, so need to retest users of that (minikube plugin for example)

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 7, 2025
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 7, 2025
@illume illume requested review from Copilot and removed request for skoeva and yolossn November 7, 2025 11:53
Copy link
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

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-adapters v0.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.

illume and others added 10 commits November 7, 2025 10:21
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>
illume and others added 4 commits November 7, 2025 11:14
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>
illume and others added 2 commits November 7, 2025 11:14
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>
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

illume and others added 4 commits November 7, 2025 12:02
…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>
@joaquimrocha
Copy link
Contributor

I will keep this comment updated to bugs I find.

  • Just ran this branch + ai-assistant. When I enabled the MCP servers, it was indeed enabled, but the UI remained as if it didn't. Not sure if a bug in this branch or the ai-assistant plugin (most likely)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants