Repository navigation
Conversation
semantic_search exposed content that every other MCP tool excludes: a stale embedding handed the controller a question, answer or comment ID, and the handler returned title and content without checking that the question is public, that the answer is available, or that the comment is in a visible state. Deleted and hidden questions, deleted answers and their comments could therefore be read through MCP after deletion. Every fetch in the semantic search handler is now gated by the same rules the question-detail, answers and comments tools apply. The get_questions tool documents its tag filter as "semicolon separated" but the parser split on commas only and kept surrounding whitespace, so a client following the documented contract got zero results; both separators are now accepted and entries are trimmed. The tool declares score as a string argument while the parser only accepted numbers, so a conforming client had its filter silently dropped; numeric arguments are now read consistently. top_k had no upper bound, in contrast with page_size, and could request an unbounded dump of stored vectors; it is now capped like page_size. The answers tool also fills the question_title field its response schema declares, and the unreachable duplicated block in the answers handler is removed. Fixes apache#1689 Signed-off-by: NUAAwqy <146524024+NUAAwqy@users.noreply.github.com>
This branch has not been deployed
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.
Proposed changes
Fixes #1689 - MCP tools now enforce the visibility and input contracts they advertise.
Visibility gating in
semantic_search- the handler previously published title/content for whatever the vector metadata referenced. Every fetch is now gated by the same rules the question-detail, answers and comments tools apply:mcpQuestionIsPublic(not deleted, not hidden) - a stale embedding can no longer expose a deleted or hidden question;mcpSemanticSearchAnswerVisible(status available, non-nil);mcpSemanticSearchCommentVisible(status available, non-nil);Input contracts - tools now accept what their schemas document:
tagfilter accepts both the documented semicolon-separated form and the comma form, trims whitespace and drops empty entries (splitTagList);score, declared as a string argument in the tool schema, is read withrequest.GetIntso the string form works instead of being silently ignored; the number form keeps working;top_kis read the same way and clamped to a newMCPMaxTopK = 50, mirroring thepage_sizecap.Answers handler - fills the
question_titlefield its response schema declares and removes the unreachable duplicated result-assembly block (the branch belowif len(cond.QuestionID) > 0could never run because the empty-ID case returns earlier).Validation
New tests:
internal/schema/mcp_schema_test.go:TestNewMCPSearchCondScore(string form ofscore),TestNewMCPSearchCondTagSeparators(semicolon/comma/mixed/empty entries),TestNewMCPSemanticSearchCondTopKBounds(defaults, clamping, fallbacks). Before the fix 8 subtests of these fail ondev; after the fix all pass.internal/controller/mcp_controller_test.go:TestMCPSemanticSearchAnswerVisible,TestMCPSemanticSearchCommentVisiblecovering the new policy helpers.go build ./...passes;go test ./internal/schema/ ./internal/controller/ ./pkg/... ./internal/service/...all pass (schema: 6 tests incl. the 3 new ones; controller: 3 tests incl. the 2 new ones).gofmtclean.