-
Notifications
You must be signed in to change notification settings - Fork 28
Group MCP tools by capability #2293
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
Open
GChaucer
wants to merge
2
commits into
PostHog:main
Choose a base branch
from
GChaucer:fix/mcp-tool-groups
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
apps/code/src/renderer/features/mcp-servers/hooks/mcpToolGroups.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import type { McpInstallationTool } from "@renderer/api/posthogClient"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { getMcpToolGroup, groupMcpToolsByCapability } from "./mcpToolGroups"; | ||
|
|
||
| function tool( | ||
| name: string, | ||
| overrides: Partial<McpInstallationTool> = {}, | ||
| ): McpInstallationTool { | ||
| return { | ||
| id: `tool-${name}`, | ||
| tool_name: name, | ||
| display_name: name, | ||
| description: "", | ||
| input_schema: {}, | ||
| approval_state: "needs_approval", | ||
| last_seen_at: "2026-01-01T00:00:00Z", | ||
| removed_at: null, | ||
| created_at: "2026-01-01T00:00:00Z", | ||
| updated_at: "2026-01-01T00:00:00Z", | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe("getMcpToolGroup", () => { | ||
| it.each(["get_ticket", "list_projects", "search_docs", "lookup_customer"])( | ||
| "classifies %s as read", | ||
| (toolName) => { | ||
| expect(getMcpToolGroup(tool(toolName))).toBe("read"); | ||
| }, | ||
| ); | ||
|
|
||
| it.each(["create_ticket", "delete_file", "send_message", "run_query"])( | ||
| "classifies %s as write/delete", | ||
| (toolName) => { | ||
| expect(getMcpToolGroup(tool(toolName))).toBe("write_delete"); | ||
| }, | ||
| ); | ||
|
|
||
| it("falls back to display name and description when the tool name is ambiguous", () => { | ||
| expect( | ||
| getMcpToolGroup( | ||
| tool("ticket", { | ||
| display_name: "Find ticket", | ||
| }), | ||
| ), | ||
| ).toBe("read"); | ||
| expect( | ||
| getMcpToolGroup( | ||
| tool("message", { | ||
| display_name: "Message", | ||
| description: "Send a message to the current channel", | ||
| }), | ||
| ), | ||
| ).toBe("write_delete"); | ||
| }); | ||
|
|
||
| it("defaults ambiguous tools to write/delete for safety", () => { | ||
| expect(getMcpToolGroup(tool("ticket"))).toBe("write_delete"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("groupMcpToolsByCapability", () => { | ||
| it("groups tools while preserving their input order within each group", () => { | ||
| const tools = [ | ||
| tool("create_ticket"), | ||
| tool("get_ticket"), | ||
| tool("search_tickets"), | ||
| tool("update_ticket"), | ||
| ]; | ||
|
|
||
| expect(groupMcpToolsByCapability(tools)).toEqual({ | ||
| read: [tools[1], tools[2]], | ||
| write_delete: [tools[0], tools[3]], | ||
| }); | ||
| }); | ||
| }); |
73 changes: 73 additions & 0 deletions
73
apps/code/src/renderer/features/mcp-servers/hooks/mcpToolGroups.ts
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is IMO the wrong way of going about it. MCP tools expose whether they actually are read only, destructive, etc. via tool annotations. We should use that instead: https://modelcontextprotocol.io/specification/2025-11-25/schema#toolannotations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import type { McpInstallationTool } from "@renderer/api/posthogClient"; | ||
|
|
||
| export type McpToolGroup = "read" | "write_delete"; | ||
|
|
||
| const READ_VERBS = new Set([ | ||
| "fetch", | ||
| "find", | ||
| "get", | ||
| "list", | ||
| "lookup", | ||
| "query", | ||
| "read", | ||
| "search", | ||
| "view", | ||
| ]); | ||
|
|
||
| const WRITE_DELETE_VERBS = new Set([ | ||
| "add", | ||
| "archive", | ||
| "assign", | ||
| "close", | ||
| "create", | ||
| "delete", | ||
| "edit", | ||
| "execute", | ||
| "remove", | ||
| "run", | ||
| "send", | ||
| "set", | ||
| "update", | ||
| "upload", | ||
| ]); | ||
|
|
||
| function firstVerb(value: string | null | undefined): string | null { | ||
| const [verb] = | ||
| value | ||
| ?.trim() | ||
| .toLowerCase() | ||
| .match(/[a-z]+/) ?? []; | ||
| return verb ?? null; | ||
| } | ||
|
|
||
| function classifyVerb(verb: string | null): McpToolGroup | null { | ||
| if (!verb) return null; | ||
| if (READ_VERBS.has(verb)) return "read"; | ||
| if (WRITE_DELETE_VERBS.has(verb)) return "write_delete"; | ||
| return null; | ||
| } | ||
|
|
||
| export function getMcpToolGroup(tool: McpInstallationTool): McpToolGroup { | ||
| return ( | ||
| classifyVerb(firstVerb(tool.tool_name)) ?? | ||
| classifyVerb(firstVerb(tool.display_name)) ?? | ||
| classifyVerb(firstVerb(tool.description)) ?? | ||
| "write_delete" | ||
| ); | ||
| } | ||
|
|
||
| export function groupMcpToolsByCapability(tools: McpInstallationTool[]): { | ||
| read: McpInstallationTool[]; | ||
| write_delete: McpInstallationTool[]; | ||
| } { | ||
| return tools.reduce( | ||
| (groups, tool) => { | ||
| groups[getMcpToolGroup(tool)].push(tool); | ||
| return groups; | ||
| }, | ||
| { read: [], write_delete: [] } as { | ||
| read: McpInstallationTool[]; | ||
| write_delete: McpInstallationTool[]; | ||
| }, | ||
| ); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The identical
onToolApprovalChangecallback is defined twice — once for eachToolGroupSection. Extract it to auseCallback(or a plainconstbefore the return) so both sections share a single definition.Prompt To Fix With AI