Repository navigation
Description
Area: MCP tools (internal/controller/mcp_controller.go, internal/schema/mcp_schema.go)
While auditing the MCP tool surface I found a group of related defects: the semantic search tool bypasses the visibility rules every other MCP tool applies, and several tools silently break their own documented input contracts.
1. semantic_search leaks deleted / hidden content
MCPSemanticSearchHandler takes object IDs from vector-search metadata and fetches content without any visibility check:
questioncommon.Info(...)returns deleted questions too (Status == QuestionStatusDeletedis handled explicitly insideInfo), and the handler publishedTitle+Contentfor whatever came back - unlikeMCPQuestionDetailHandler, which gates throughmcpQuestionIsPublic. A question deleted or hidden after its embedding was stored stays readable throughsemantic_search, together with its full markdown content.- Answers are fetched with
answerRepo.GetAnswer(...)and theirOriginalTextreturned without checkingStatus == AnswerStatusAvailable-MCPAnswersHandlerfilters deleted and pending answers explicitly; the semantic handler does not. - Answer-type results never verify the parent question is public, so
Titleof a hidden question leaks through an answer hit. - Comments are returned without a status check as well.
Consequences: content that was deleted (or moderated to hidden) remains retrievable via MCP for as long as the embedding exists, and MCP clients can read content the web UI would never show.
2. get_questions tag filter ignores its documented separator
The tool declares the tag argument as "semicolon separated for multiple tags", but the parser does strings.Split(tag, ","). A client that follows the documentation and sends "go;java" gets a single bogus tag [go;java] and therefore zero results. Surrounding whitespace is not trimmed either, so "go, java" searches for the tag " java".
3. score argument is silently ignored for conforming clients
get_questions declares score as a string argument in its tool schema, but the parser only accepts a JSON number (getRequestNumber checks for float64). A client that follows the schema and sends "score": "5" has the filter silently dropped. Pagination arguments (page, page_size) already accept both forms via request.GetInt; score does not.
4. top_k is unbounded
semantic_search's top_k has no upper bound - in contrast with page_size, which is capped at MCPMaxPageSize = 50 "so clients cannot request unbounded results". A client can request top_k: 1000000 and make the vector plugin dump everything it stored.
Suggested fix
- Gate every fetch in
MCPSemanticSearchHandlerwith the same visibility rules the other tools apply (public question, available answer, available comment), via small pure helpers so the policy is testable likemcpQuestionIsPublic. - Accept
,and;as tag separators and trim entries (splitTagList). - Read
scoreandtop_kwithrequest.GetInt(string and number forms), clamptop_kto a newMCPMaxTopK. - Fill the
question_titlefield the answers response schema declares and drop the unreachable duplicated block inMCPAnswersHandler.
I have a fix with tests ready and will open a PR referencing this issue.
Activity
fix(mcp): enforce visibility and input bounds in MCP tools (#1690)