Skip to content

fix(mcp): enforce visibility and input bounds in MCP tools - #1690

Merged
LinkinStars merged 1 commit into
apache:devfrom
NUAAwqy:fix/mcp-semantic-search-visibility
Dec 2, 2026
Merged

LinkinStars merged 1 commit into
apache:devfrom
NUAAwqy:fix/mcp-semantic-search-visibility

Conversation

@NUAAwqy

@NUAAwqy NUAAwqy commented Nov 28, 2026 •

Copy link
Copy Markdown

Proposed changes

Fixes #1689.

This branch has been rebased onto the current dev (which now contains #1681) and keeps only the follow-up fixes.

Input contracts - tools now accept what their schemas document:

  • the tag filter 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 with request.GetInt so the string form works instead of being silently ignored; the number form keeps working;
  • top_k is read the same way and clamped to a new MCPMaxTopK = 50, mirroring the page_size cap.

Answers handler - fills the question_title field its response schema declares and removes the unreachable duplicated result-assembly block (the branch below if len(cond.QuestionID) > 0 could never run because the empty-ID case returns earlier).

Lint - removes the now-unused getRequestNumber helper reported by golangci-lint.

Relationship to #1681

The semantic-search visibility gating proposed here has been superseded by #1681, which is already merged into dev; the overlapping changes were dropped in the rebase, so this PR no longer touches that handler.

Validation

  • internal/schema/mcp_schema_test.go: TestNewMCPSearchCondScore, TestNewMCPSearchCondTagSeparators, TestNewMCPSemanticSearchCondTopKBounds.
  • go build ./internal/... passes; go test ./internal/schema/ ./internal/controller/ passes; gofmt clean.

@LinkinStars LinkinStars left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in the latest revision: getRequestNumber is gone and the package builds and tests with the remaining GetInt call sites.

@LinkinStars LinkinStars self-assigned this Dec 1, 2026
- accept the semicolon-separated tag list the tool documents, while
  keeping the comma form; trim entries and drop empty ones
- read score and top_k through GetInt so the string form declared in the
  schema works, and clamp top_k to MCPMaxTopK like page_size
- drop the now-unused getRequestNumber helper
- fill question_title in get_answers and remove the unreachable
  duplicated result-assembly block

Signed-off-by: NUAAwqy <146524024+NUAAwqy@users.noreply.github.com>
@NUAAwqy
NUAAwqy force-pushed the fix/mcp-semantic-search-visibility branch from 8e19308 to acbcd00 Compare December 2, 2026 01:00
@NUAAwqy

NUAAwqy commented Dec 2, 2026

Copy link
Copy Markdown
Author

Rebased onto the current dev and dropped the semantic-search visibility changes now provided by #1681.

Remaining fixes: documented tag separators and string score handling, top_k bounded by MCPMaxTopK, the unused getRequestNumber helper removed, and question_title filled in the answers handler. go test ./internal/schema/ ./internal/controller/ passes. PR description updated accordingly.

@LinkinStars

Copy link
Copy Markdown
Member

LGTM

@LinkinStars
LinkinStars merged commit af27dda into apache:dev Dec 2, 2026
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.

2 participants