Skip to content

feat(mcp): expose semantic_search tool on the MCP server - #1681

Open
shaktimaan00 wants to merge 1 commit into
apache:mainfrom
shaktimaan00:fix/1674-mcp-semantic-search
Open

shaktimaan00 wants to merge 1 commit into
apache:mainfrom
shaktimaan00:fix/1674-mcp-semantic-search

Conversation

@shaktimaan00

Copy link
Copy Markdown

Fixes #1674

Proposed Changes

  • internal/router/mcp_router.go: register semantic_search on the public MCP server when MCPController.SemanticSearchAvailable() reports a VectorSearch plugin, so external MCP clients (Claude Desktop, Cursor, …) can use the capability that already existed for the AI chat. The tool is registered last, after the six basic tools, and stays invisible on sites without a VectorSearch plugin — no tool that can never succeed is advertised.
  • The s.AddTool calls move into addMCPTools(s, c, semanticSearchAvailable bool). The bool seam exists for the same reason AIController.buildOpenAITools takes one (fix(ai): stop advertising semantic_search when no vector search plugin is enabled #1597): SemanticSearchAvailable() reads the process-wide plugin registry (plugin.IsVectorSearchEnabled()), which a unit test cannot switch on without a live plugin.
  • internal/router/mcp_router_test.go (new): regression coverage for the conditional, in the shape of internal/controller/ai_tools_test.go.

Acceptance criteria

The issue asks for the tool to be registered on the MCP server conditionally, and to stay hidden without a VectorSearch plugin:

  • With a VectorSearch plugin available, the MCP server registers semantic_search alongside the six basic tools — TestAddMCPToolsRegistersSemanticSearchWhenAvailable.
  • Without one, semantic_search is not registered and the six basic tools still are — TestAddMCPToolsOmitsSemanticSearchWhenUnavailable (asserts exactly 6 tools).
  • No new tool or handler: mcp_tools.NewSemanticSearchTool() and MCPController.MCPSemanticSearchHandler() are used as they are.

Validation

Run in a golang:1.25-bookworm container against main at 9e6ca4a:

gofmt -l internal/router/                     -> no output
go build ./...                                -> exit 0
go vet ./internal/router/ ./internal/controller/ -> exit 0
go test ./internal/router/ -run AddMCPTools -v   -> 2 tests, PASS
go test ./internal/router/ ./internal/controller/ ./internal/schema/mcp_tools/ -> ok
go test ./...                                 -> 25 packages ok, 0 FAIL
make test                                     -> ok  internal/repo/repo_test
golangci-lint v2.6.2 run ./internal/router/... -> 0 issues

The new test is not vacuous: forcing the gate to false fails the available-case test, and forcing it to true fails the unavailable-case test.

make lint itself needs Docker or Podman inside the runner for script/check-asf-header.sh, so it could not run here; that script was checked by diffing the ASF header of the two touched files against their neighbours (identical), and golangci-lint was run directly instead.

No frontend change, so no screenshot.

The semantic search tool, handler and availability check already existed but
RegisterMCPRouter only registered the six basic tools, so external MCP clients
could not use semantic search even with a VectorSearch plugin enabled.

Register semantic_search next to the basic tools when a VectorSearch plugin is
available, matching how the AI chat tool list hides the tool when it cannot
succeed. The registration is split into addMCPTools so the conditional is
covered by a test without a live plugin registry.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(mcp): expose semantic_search tool on the MCP server

1 participant