Skip to content

MCP tools leak deleted/hidden content via semantic search and break their documented input contracts #1689

Backlog

Description

@NUAAwqy

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 == QuestionStatusDeleted is handled explicitly inside Info), and the handler published Title + Content for whatever came back - unlike MCPQuestionDetailHandler, which gates through mcpQuestionIsPublic. A question deleted or hidden after its embedding was stored stays readable through semantic_search, together with its full markdown content.
  • Answers are fetched with answerRepo.GetAnswer(...) and their OriginalText returned without checking Status == AnswerStatusAvailable - MCPAnswersHandler filters deleted and pending answers explicitly; the semantic handler does not.
  • Answer-type results never verify the parent question is public, so Title of 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 MCPSemanticSearchHandler with the same visibility rules the other tools apply (public question, available answer, available comment), via small pure helpers so the policy is testable like mcpQuestionIsPublic.
  • Accept , and ; as tag separators and trim entries (splitTagList).
  • Read score and top_k with request.GetInt (string and number forms), clamp top_k to a new MCPMaxTopK.
  • Fill the question_title field the answers response schema declares and drop the unreachable duplicated block in MCPAnswersHandler.

I have a fix with tests ready and will open a PR referencing this issue.

Activity

  1. added a commit that references this issue on Dec 2, 2026
    af27dda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions