feat/mcp-tool-modes - #7016
Draft
kohlivrinda wants to merge 1 commit into
Draft
Conversation
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueComment |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary
Introduces a
tool_modefield for MCP clients that replaces the binaryis_code_mode_clientflag with a five-way enum:direct,code,compact,compact_names, andsearch. The new modes address context bloat without requiring a Starlark sandbox:compactstrips all descriptions from tool definitions,compact_namesexposes only tool names plus an on-demandgetToolDetailsmeta-tool, andsearchhides tools entirely behind three meta-tools (searchTools,getToolDetails,executeTool) backed by a BM25 index. The legacyis_code_mode_clientflag is kept in sync on every read and write so rolled-back binaries continue to work.Changes
schemas.MCPToolMode— new string enum (direct,code,compact,compact_names,search) withResolvedToolMode()(explicit field wins, then legacy flag, thendirect) andNormalizeToolMode()(writes both fields into agreement).core/mcp/toolmodes.go— new file implementing:compactToolDefinition: strips function and parameter descriptions while preserving the JSON schema skeleton.nameOnlyToolDefinition: replaces the parameter schema with an open, empty object.newBM25Index,search) with camelCase-aware tokenization, plural normalization, and per-field weights that prevent long descriptions from burying exact name hits.searchModeTools: returns the three meta-tool definitions with catalog size and server list baked into thesearchToolsdescription.handleSearchTools,handleGetToolDetails,handleExecuteTool: dispatch logic for the meta-tools, including allow-list enforcement, request-context client filtering, nested request ID propagation, and plugin pipeline pass-through.GetAvailableTools— routes each client throughResolvedToolMode()and appends compact/name-only definitions or records search-mode tools for the meta-tool catalog; injects meta-tools exactly once.executeAgent—searchToolsandgetToolDetailsare always auto-executable;executeToolis auto-executable iff the inner tool would be if called directly.buildAllowedAutoExecutionTools— switched fromIsCodeModeClientboolean toResolvedToolMode() == MCPToolModeCode.resolveExecuteToolTarget— new helper that parses anexecuteToolcall'stoolargument and resolves it to the owning client.prepareToolExecution— skips client lookup for search-mode meta-tools, mirroring the existing code-mode skip.tool_mode VARCHAR(20)column added toconfig_mcp_clients; migration backfillscodefromis_code_mode_client = trueanddirectfor everything else; rollback drops the column.ToolModethreaded through all read, write, create, and update paths;addMCPClientandupdateMCPClientvalidate and normalize the field before persisting.tool_modeenum added;is_code_mode_clientmarked deprecated.Selectin both the create form and the edit sheet; the clients table "Code Mode" column becomes "Tool Mode" with human-readable labels;resolveToolModeandMCP_TOOL_MODE_LABELSadded to the MCP type module; optimistic cache update handlestool_mode.toolmodes_test.gocovers compact stripping, BM25 ranking, the full mode matrix inGetAvailableTools, all three search meta-tool handlers (including refusals, stringified arguments, inner error propagation), andresolveExecuteToolTarget.Type of change
Affected areas
How to test
To exercise search mode end-to-end:
tool_mode: "search".searchTools,getToolDetails, andexecuteToolappear in the tool list.searchToolswith a relevant query and confirm ranked results are returned.getToolDetailson a result and confirm full parameter docs including an exampleexecuteToolcall.executeTooland confirm the inner tool executes and its result is re-enveloped under the outer call ID.For
compactandcompact_names, verify that tool descriptions and parameter descriptions are absent from the request payload while the schema skeleton (types, required, enums) is preserved.Breaking changes
is_code_mode_clientcontinues to be read and written correctly. The database migration is additive and includes a rollback. Existing code-mode clients are automatically backfilled totool_mode = "code".Security considerations
executeToolenforces the same allow-list checks (ToolsToExecute,ToolsToAutoExecute, request-contextinclude_clients) as a direct tool call. It also refuses to proxy tools whose client is not insearchmode, preventing the meta-tool from being used as a bypass fordirectorcompactclients. The inner call goes through the full plugin pipeline.Checklist
docs/contributing/README.mdand followed the guidelines