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>
LinkinStars
left a comment
There was a problem hiding this comment.
Thanks for the fixes. The input-contract issues are worth addressing: documented tag separators and string scores currently do not work as advertised, and bounding top_k is reasonable.
The semantic-search visibility issue has already been fixed in #1681, now merged into dev. Please update this branch against the latest dev and resolve the overlapping changes while preserving that fix and its tool registration/tests.
Please also address the inline lint finding and update the PR description to distinguish the remaining fixes from the visibility issue already addressed upstream.
| // The get_questions tool declares score as a string argument, so read it the | ||
| // same way the pagination arguments are read: both the string and the number | ||
| // form are accepted instead of silently ignoring one of them. | ||
| cond.Score = request.GetInt(MCPSearchCondScore, 0) |
There was a problem hiding this comment.
Switching the remaining numeric arguments to request.GetInt leaves getRequestNumber (line 270 in this revision) without any callers. Please remove that helper as well. I ran build/tools/golangci-lint-v2.6.2 run ./internal/schema/... and confirmed it fails with internal/schema/mcp_schema.go:270:6: func getRequestNumber is unused (unused).
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.