Skip to content

fix(ai-assistant): use MCP server's manifest description in approval dialog instead of hardcoded "Inspektor Gadget" fallback - #1097

Open
Saksham842 wants to merge 1 commit into
headlamp-k8s:mainfrom
Saksham842:fix/ai-assistant-mcp-tool-description
Open

Saksham842 wants to merge 1 commit into
headlamp-k8s:mainfrom
Saksham842:fix/ai-assistant-mcp-tool-description

Conversation

@Saksham842

Copy link
Copy Markdown

What does this PR do?

Fixes the MCP tool approval dialog showing "Inspektor Gadget debugging tool: <name>" for every non-Gadget MCP server (Flux, Prometheus, Vault, custom tools, etc.).

Closes #1096


Problem

getToolDescription() in packages/ai-common/src/tools/catalog/getToolDescription.ts used keyword heuristics tuned to Inspektor Gadget naming conventions, with a catch-all fallback that hardcoded the "Inspektor Gadget" brand name:

// Before
return `Inspektor Gadget debugging tool: ${toolName}`;

The MCP server's own tool description was already stored in RuntimeToolInfo.description at the getMCPTools() call sites — but it was never threaded through to getToolDescription. Every non-Gadget MCP tool therefore showed completely wrong text in the human approval dialog.


Solution

  1. getToolDescription.ts — added an optional catalogDescription?: string third parameter. When present for an MCP tool it is returned immediately, before any keyword heuristic runs. The "Inspektor Gadget" catch-all is replaced with the generic "MCP tool: <name>":
// After
export function getToolDescription(
  toolName: string,
  isMCPTool: boolean,
  catalogDescription?: string   // ← new optional param
): string {
  if (isMCPTool) {
    if (catalogDescription) return catalogDescription;  // server's own description wins
    // keyword heuristics as fallback …
    return `MCP tool: ${toolName}`;                    // generic, not Gadget-specific
  }
  …
}
  1. LangChainAssistantSession.ts — both toolCallsForApproval construction sites changed from .some() → .find() to capture the full RuntimeToolInfo object, then pass mcpToolEntry?.description as the third argument. The private getToolDescription wrapper is updated to forward the new parameter.

  2. getToolDescription.test.ts — updated the stale 'Inspektor Gadget' fallback assertion; added two new tests:

    • Catalog description wins over keyword heuristics (simulates a Flux tool containing run in its name)
    • Empty-string catalog description falls through to keyword heuristics

Before / After

Scenario Before After
flux__reconcile_kustomization (manifest desc: "Reconcile a Flux Kustomization object") "Inspektor Gadget debugging tool: flux__reconcile_kustomization" "Reconcile a Flux Kustomization object"
Unknown tool, no manifest description "Inspektor Gadget debugging tool: some__tool" "MCP tool: some__tool"
Gadget gadget__trace_open, no manifest description "Traces system calls and processes for debugging" unchanged

Checklist

  • Bug fix (non-breaking — new parameter is optional; all existing callers remain valid)
  • Tests updated / added (getToolDescription.test.ts — 11/11 )
  • No changes to public API surface
  • LangChainAssistantSession.ts — both approval construction sites updated consistently

Files changed

File Change
packages/ai-common/src/tools/catalog/getToolDescription.ts Added catalogDescription param; replaced Gadget fallback
packages/ai-common/src/assistant/LangChainAssistantSession.ts Pass mcpToolEntry?.description at both call sites
packages/ai-common/src/tools/catalog/getToolDescription.test.ts Updated stale test + 2 new tests

@Saksham842
Saksham842 force-pushed the fix/ai-assistant-mcp-tool-description branch from 3124ce8 to 0608c2d Compare August 9, 2026 14:27
@illume
illume requested a balanced review from Copilot September 29, 2026 06:47

@illume illume left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for these changes.

Can you please have a look at the git commits to see if they meet the contribution guidelines? We use a Linux kernel style of git commits. See the contributing guide for general context, and please see previous git commits with git log for examples.

Commits that need attention
  • fix(ai-assistant): thread MCP manifest description into approval dialog — Missing area: description prefix — e.g. frontend: HomeButton: Fix so it navigates to home or backend: config: Add enable-dynamic-clusters flag.
Commit guidelines
  • Use atomic commits focused on a single change.
  • Use the title format <area>: <Description of changes> — description must start with a capital letter.
  • Keep the title under 72 characters (soft requirement).
  • Explain the intention and why the change is needed.
  • Make commit titles meaningful and describe what changed.
  • Do not add code that a later commit rewrites; squash or reorder commits instead.
  • Do not include Fixes #NN in commit messages.

Good examples:

  • frontend: HomeButton: Fix so it navigates to home
  • backend: config: Add enable-dynamic-clusters flag

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The multi-tool orchestration approval path still uses an LLM-generated description instead of authoritative MCP metadata.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Updates MCP approval dialogs to prefer server-provided tool descriptions over Gadget-specific heuristics.

Changes:

  • Adds optional catalog descriptions and a generic MCP fallback.
  • Threads descriptions through direct and streaming approval paths.
  • Adds unit tests for precedence and fallback behavior.
File Description
getToolDescription.ts Adds manifest-description support and generic fallback.
getToolDescription.test.ts Tests description precedence and fallbacks.
LangChainAssistantSession.ts Passes MCP metadata into approval descriptions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

id: tc.id,
name: toolName,
description: this.getToolDescription(toolName, isMCPTool),
description: this.getToolDescription(toolName, isMCPTool, mcpToolEntry?.description),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in the latest rebased commit. In handleMultipleToolExecution(), we now resolve the matching RuntimeToolInfo from this.toolManager.getMCPTools() and route it through getToolDescription(toolName, isMCPTool, mcpToolEntry?.description). This ensures manifest descriptions take precedence over planner LLM output during multi-tool execution approvals. Added a unit test in LangChainAssistantSession.test.ts covering this path.

@illume illume left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution.

There are some open Copilot review comments — could you take a look at them? Please mark each one as resolved once you've addressed it.

@illume illume added ai-assistant bug Something isn't working labels Oct 11, 2026
@Saksham842
Saksham842 force-pushed the fix/ai-assistant-mcp-tool-description branch from 0608c2d to b4cee74 Compare October 17, 2026 00:08
The tool approval dialog showed "Inspektor Gadget debugging tool: toolname"
for every MCP tool whose name did not match a small set of Inspektor
Gadget-specific keywords (exec, run, trace, etc.). Non-Gadget MCP servers
such as Flux, Prometheus, or custom tools were all affected.

Root cause: getToolDescription() only received a toolName string and a
boolean isMCPTool flag. The MCP server's own description — already stored
in RuntimeToolInfo.description and available in every getMCPTools() call —
was never threaded through to the function. Additionally, multi-tool
orchestration approval used LLM-generated descriptions rather than
manifest descriptions.

Fix:
- Add an optional catalogDescription?: string third param to
  getToolDescription(). When present for an MCP tool it is returned
  immediately, before any keyword heuristic runs (backward-compatible:
  all existing callers that omit the param keep their current behavior).
- Replace the hardcoded "Inspektor Gadget debugging tool: toolname" catch-all
  with the generic "MCP tool: toolname".
- At all approval construction sites in LangChainAssistantSession (direct,
  streaming, and multi-tool orchestration), capture the full RuntimeToolInfo
  object from getMCPTools() and pass mcpToolEntry?.description as the
  third argument.
- Update getToolDescription.test.ts: fix stale 'Inspektor Gadget'
  assertion; add tests for catalog-description priority and empty-string
  fallback behavior.
- Add unit test in LangChainAssistantSession.test.ts verifying orchestrated
  tools use MCP manifest descriptions in approval dialogs.

Signed-off-by: Saksham842 <sakshamhans5492@gmail.com>
@Saksham842
Saksham842 force-pushed the fix/ai-assistant-mcp-tool-description branch from b4cee74 to ccdbf74 Compare October 17, 2026 00:18
@Saksham842

Copy link
Copy Markdown
Author

Thanks for the review @illume!

  1. Commit Guidelines & Rebase:

    • Rebased the branch onto the latest main.
    • Squashed into a single atomic commit adhering to the Linux kernel style:
      • Title: ai-assistant: Use MCP manifest description in approval dialog (< 72 characters, capitalized description).
      • Removed Fixes #... from the commit message and included the intention, rationale, and DCO sign-off.
  2. Copilot Review:

    • Addressed the comment in handleMultipleToolExecution() so orchestrated multi-tool approvals now also source their descriptions from the MCP server manifest rather than the planner's LLM output.
    • Added a corresponding unit test in LangChainAssistantSession.test.ts to verify description precedence and fallback behavior for multi-tool orchestration. Marked the Copilot conversation as resolved.

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

Labels

ai-assistant bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(ai-assistant): MCP approval dialog shows hardcoded "Inspektor Gadget" text for all non-Gadget MCP servers (Flux, Prometheus, etc.)

3 participants