feat(mcp): hide ask_codebase tool when no LLM providers configured#1018
Merged
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>
Contributor
|
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>
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
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