Uh oh!
There was an error while loading. Please reload this page.
feat(mcp): hide ask_codebase tool when no LLM providers configured - #1018
Conversation
- Modified web MCP server to check configured language models before registering the ask_codebase tool - Made createMcpServer() async to support awaiting the config check - Updated standalone MCP package to check /api/models before registering ask_codebase tool - Tool is now only visible when at least one language model is configured Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughThis change refactors MCP server initialization to be asynchronous and conditionally registers the Changes
Sequence DiagramsequenceDiagram
participant Client
participant RouteHandler as Route Handler
participant ServerInit as Server Init
participant LMService as LM Service
participant MCPServer as MCP Server
Client->>RouteHandler: POST /mcp (new session)
RouteHandler->>ServerInit: await createMcpServer()
ServerInit->>LMService: getConfiguredLanguageModels()
LMService-->>ServerInit: models list
ServerInit->>MCPServer: new McpServer()
alt hasLanguageModels = true
ServerInit->>MCPServer: register ask_codebase tool
else hasLanguageModels = false
ServerInit->>MCPServer: skip ask_codebase tool
end
MCPServer-->>ServerInit: server instance
ServerInit-->>RouteHandler: Promise resolved
RouteHandler->>MCPServer: mcpServer.connect(transport)
MCPServer-->>Client: connection established
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
The packages/mcp package is deprecated and should not be modified. Reverted the conditional ask_codebase registration changes from this package. Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
Summary
This PR hides the
ask_codebasetool in MCP when no language model providers are configured. Previously, the tool was always visible but would return an error when invoked without configured models. Now the tool is simply not registered/visible when there are no models configured.Changes
Web MCP Server (
packages/web/src/features/mcp/server.ts)createMcpServer()async to support checking for configured language modelshasLanguageModelsbefore registering theask_codebasetoolMCP Route Handler (
packages/web/src/app/api/(server)/mcp/route.ts)createMcpServer()functionAGENTS.md
packages/mcpbeing deprecated (it should not be modified)Analysis: Making
createMcpServerAsyncConfirmed that making
createMcpServerasync is safe:withOptionalAuthV2callback)Testing
Verified the feature works correctly by testing the MCP API endpoint:
Without models configured (6 tools visible):
list_commits,list_language_models,list_repos,list_tree,read_file,search_codeask_codebaseis NOT visibleWith models configured (7 tools visible):
ask_codebase,list_commits,list_language_models,list_repos,list_tree,read_file,search_codeask_codebaseIS visibleAll existing tests pass:
yarn test- 617 tests passingyarn workspace @sourcebot/web lint- No errorsyarn workspace @sourcebot/web build- SuccessfulFixes SOU-718
Linear Issue: SOU-718
Summary by CodeRabbit
Changed
ask_codebaseMCP tool is now hidden when no language model providers are configured, ensuring it's only available when applicable.Documentation