Skip to content

ai-assistant: Add ability to run mcp server from ai-assistant plugin#385

Draft
ashu8912 wants to merge 41 commits intomainfrom
add-mcp-server
Draft

ai-assistant: Add ability to run mcp server from ai-assistant plugin#385
ashu8912 wants to merge 41 commits intomainfrom
add-mcp-server

Conversation

@ashu8912
Copy link
Member

@ashu8912 ashu8912 commented Sep 8, 2025

No description provided.

@ashu8912 ashu8912 marked this pull request as draft September 8, 2025 17:33
@ashu8912 ashu8912 force-pushed the add-mcp-server branch 2 times, most recently from aa9aa8e to 3bd4cbb Compare September 10, 2025 04:21
@ashu8912 ashu8912 force-pushed the add-mcp-server branch 3 times, most recently from 10b04e6 to 1b93e58 Compare September 21, 2025 11:11
@ashu8912 ashu8912 marked this pull request as ready for review September 29, 2025 13:29
@ashu8912 ashu8912 force-pushed the add-mcp-server branch 2 times, most recently from 2620b42 to fe38c68 Compare September 29, 2025 14:12
@illume illume added ai-assistant enhancement New feature or request labels Oct 8, 2025
@ashu8912 ashu8912 force-pushed the add-mcp-server branch 2 times, most recently from c81b4a7 to 628ad14 Compare October 9, 2025 11:54
@ashu8912 ashu8912 force-pushed the add-mcp-server branch 5 times, most recently from 1f9cd8a to d9bb4cb Compare October 29, 2025 08:21
@illume illume requested a review from Copilot November 3, 2025 10:10
@illume illume changed the title Add ability to run mcp server from ai-assistant plugin ai-assistant: Add ability to run mcp server from ai-assistant plugin Nov 3, 2025
Copy link
Contributor

@illume illume left a comment

Choose a reason for hiding this comment

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

It's important to do these standard things for PRs to speed reviews along:

  • PR description
  • screenshots or video
  • steps to test each fix or piece of functionality
  • link to the related issue
  • If there are no tests at all, please justify this. Note that it will slow reviews down, and slow down future changes
  • Document fields and functions. This speeds up the review, and helps speed up further changes.
  • git commit messages with context of the modules changed in subject, AND a "why" in the git commit body unless it's covered in the git message subject.
ai-assistant: MCPSettings: Add MCP settings UI and Electron config API

- Add components/settings/MCPSettings.tsx: UI for configuring MCP servers (add/remove/toggle/edit),
  uses window.desktopApi.mcp.getConfig/updateConfig when running in Electron, falls back to pluginStore.
- Extend ElectronMCPApi typings with getConfig and updateConfig for config persistence.
- Provide default server when enabling MCP with no servers, and a "Test MCP Connection" action.

Notes:
- Argument parsing is space-based (no quote handling).
- Ensure native side exposes getTools (used by the test action) and that updateConfig triggers any required client restart.

Copy link

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 comprehensive MCP (Model Context Protocol) integration to the AI assistant, enabling connection to external tools and services. It introduces tool approval workflows, intelligent argument processing, and enhanced tool management capabilities.

  • Added MCP server configuration and management in Electron environments
  • Implemented tool approval dialogs with inline confirmation UI
  • Created intelligent argument processing using AI for MCP tools
  • Added tool orchestration for multi-tool execution

Reviewed Changes

Copilot reviewed 40 out of 42 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
ai-assistant/src/utils/ToolConfigManager.ts Added source tracking ('built-in' vs 'mcp'), MCP tool integration functions, and tool state initialization
ai-assistant/src/utils/ToolApprovalManager.ts New approval manager for tool execution with session-based auto-approval
ai-assistant/src/utils/InlineToolApprovalManager.ts Inline tool approval with user context extraction for intelligent argument processing
ai-assistant/src/langchain/tools/ToolManager.ts Enhanced with MCP tool support, argument mapping, and formatter integration
ai-assistant/src/langchain/tools/ToolOrchestrator.ts New orchestrator for analyzing and coordinating multi-tool execution
ai-assistant/src/langchain/formatters/MCPOutputFormatter.ts AI-powered formatter for MCP tool output with markdown support
ai-assistant/src/langchain/LangChainManager.ts Major updates for tool orchestration, inline approval, and argument enhancement
ai-assistant/src/components/mcpOutput/MCPOutputDisplay.tsx Rich UI component for displaying formatted MCP tool results
ai-assistant/src/components/mcpOutput/MCPArgumentProcessor.ts Intelligent argument processing with schema validation
ai-assistant/src/components/settings/MCPSettings.tsx MCP server configuration UI with enable/disable controls
ai-assistant/src/components/common/InlineToolConfirmation.tsx Inline tool confirmation component (exported via index)
ai-assistant/src/types/electron.d.ts TypeScript definitions for Electron MCP API
ai-assistant/src/hooks/useClusterChangeNotifier.ts Hook for monitoring cluster changes and notifying MCP servers
Files not reviewed (1)
  • ai-assistant/package-lock.json: Language not supported
Comments suppressed due to low confidence (2)

ai-assistant/src/langchain/tools/ToolManager.ts:226

  • This statement is unreachable.
    ai-assistant/src/langchain/tools/ToolManager.ts:258
  • This statement is unreachable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 225 to 226
return this.filterMCPArguments(inputValue, inputSchema);
return this.filterMCPArguments(inputValue, inputSchema);
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

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

Duplicate return statement on lines 225-226. The second return is unreachable and should be removed.

Copilot uses AI. Check for mistakes.
Comment on lines 257 to 258
return inputValue;
return inputValue;
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

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

Duplicate return statement on lines 257-258. The second return is unreachable and should be removed.

Copilot uses AI. Check for mistakes.
Comment on lines 3 to 16
import {
Alert,
Box,
Button,
DialogActions,
DialogContent,
DialogTitle,
FormControlLabel,
IconButton,
Paper,
Switch,
TextField,
Typography,
} from '@mui/material';
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

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

Unused import Paper.

Copilot uses AI. Check for mistakes.
Comment on lines 3 to 24
import {
Alert,
Box,
Button,
Chip,
DialogActions,
DialogContent,
DialogTitle,
FormControlLabel,
IconButton,
Paper,
Switch,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
TextField,
Tooltip,
Typography,
} from '@mui/material';
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

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

Unused import Chip.

Copilot uses AI. Check for mistakes.
): FormattedMCPOutput {
// Try to detect if it's JSON
let data: any;
let type: FormattedMCPOutput['type'] = 'text';
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

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

The initial value of type is unused, since it is always overwritten.

Suggested change
let type: FormattedMCPOutput['type'] = 'text';
let type: FormattedMCPOutput['type'];

Copilot uses AI. Check for mistakes.
cursor: isActionInProgress ? 'not-allowed' : 'pointer',
}}
>
{isDenying ? 'Denying...' : 'Deny'}
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

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

This use of variable 'isDenying' always evaluates to false.

Copilot uses AI. Check for mistakes.
size="small"
onClick={handleApprove}
startIcon={
isApproving ? (
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

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

This use of variable 'isApproving' always evaluates to false.

Copilot uses AI. Check for mistakes.
}
color="primary"
sx={{
opacity: isApproving ? 0.7 : 1,
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

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

This use of variable 'isApproving' always evaluates to false.

Copilot uses AI. Check for mistakes.
cursor: isActionInProgress ? 'not-allowed' : 'pointer',
}}
>
{isApproving
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

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

This use of variable 'isApproving' always evaluates to false.

Copilot uses AI. Check for mistakes.
}

// First, check if args is properly structured for the schema
if (args && typeof args === 'object') {
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

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

This use of variable 'args' always evaluates to true.

Copilot uses AI. Check for mistakes.
@illume illume marked this pull request as draft November 3, 2025 19:45
@illume
Copy link
Contributor

illume commented Nov 4, 2025

I'm working on this.

@illume
Copy link
Contributor

illume commented Nov 7, 2025

Wtih Azure OpenAI provider gpt4 it's having issues.
With this plugin and headlamp branch mcp-electron 0b95d6d9d38445456655080a042badc3a698689c

With ai-assistant installed from Plugin Catalog it's working.

image

https://mgns-eastus2.openai.azure.com/openai/deployments/gpt-4/chat/completions?api-version=2024-12…
Request Method: POST

Status Code: 400 Bad Request
{
   "error": {
       "message": "'Make requests to the Kubernetes API server to fetch, create, update or delete resources.\n\nRESOURCE UPDATE GUIDELINES:\n- For UPDATE/MODIFY/CHANGE operations: Use PUT method with ONLY the specific fields to change\n- Provide patch objects that will be merged with existing resources\n- Use null values to remove fields (e.g., {"spec": {"livenessProbe": null}})\n- The system automatically merges patches with current resources before making PUT requests\n\nLOG HANDLING FOR MULTI-CONTAINER PODS:\n- When a user asks for logs from a pod, ALWAYS first check the pod specification to determine the number of containers\n- If the pod has only one container, directly fetch logs: kubernetes_api_request(url="/api/v1/namespaces/default/pods/pod-name/log", method="GET")\n- If the pod has multiple containers, you MUST ask the user which container they want logs from\n- List the available container names and ask the user to specify\n- Once the user specifies a container, fetch logs with the container parameter: kubernetes_api_request(url="/api/v1/namespaces/default/pods/pod-name/log?container=container-name", method="GET")\n- NEVER attempt to fetch logs from a multi-container pod without specifying the container name\n- Examples of user requests that specify containers:\n  - "get logs from pod-name container nginx" → kubernetes_api_request(url="/api/v1/namespaces/default/pods/pod-name/log?container=nginx", method="GET")\n  - "show logs for container sidecar in pod-name" → kubernetes_api_request(url="/api/v1/namespaces/default/pods/pod-name/log?container=sidecar", method="GET")\n- If you encounter an error about "container name must be specified", the error handler will automatically provide guidance to the user\n- IMPORTANT: Parse user requests carefully to detect if they\'re specifying a container name in their request:\n  - Look for patterns like "container [name]", "from container [name]", "[pod-name] [container-name]"\n  - If user specifies a container name, use it directly in the log URL\n  - If user doesn\'t specify a container and the pod has multiple containers, fetch pod details first to list available containers' is too long - 'tools.0.function.description'",
       "type": "invalid_request_error",
       "param": null,
       "code": null
   }
}

@ashu8912 ashu8912 force-pushed the add-mcp-server branch 2 times, most recently from 4e72235 to 2a74422 Compare February 17, 2026 09:33
Signed-off-by: Ashu Ghildiyal <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
ashu8912 and others added 26 commits February 17, 2026 15:07
- Replace plain textarea with professional editor dialog
- Add MCPServer interface support for environment variables
- Update example configuration with modern MCP server setups
- Add configuration summary with server count and status display
- Integrate MCPConfigEditorDialog for better user experience
- Show detailed server list with enabled/disabled status
- Remove complex JSON validation in favor of editor dialog approach

Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
- Add isElectron utility function for environment detection
- Enhance ToolConfigManager with configuration validation
- Update AIInputSection with improved tool integration
- Add electron client improvements for MCP communication
- Include helper functions for better component integration

Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
The "white-space: pre-wrap" left lots of spacing around the text.

Signed-off-by: Joaquim Rocha <joaquim.rocha@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: Joaquim Rocha <joaquim.rocha@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
So we don't show very long descriptions in the tools dialog.

Signed-off-by: Joaquim Rocha <joaquim.rocha@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: Joaquim Rocha <joaquim.rocha@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: Joaquim Rocha <joaquim.rocha@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: Joaquim Rocha <joaquim.rocha@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Instead of just relying on editing JSON.

Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
@ashu8912 ashu8912 force-pushed the add-mcp-server branch 2 times, most recently from f089f2f to 19b39dc Compare February 17, 2026 09:57
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assistant enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants