Skip to content

feat(mcp): add get_question_detail tool to the MCP server - #1683

Open
shaktimaan00 wants to merge 1 commit into
apache:mainfrom
shaktimaan00:fix/1675-mcp-question-detail-tool
Open

shaktimaan00 wants to merge 1 commit into
apache:mainfrom
shaktimaan00:fix/1675-mcp-question-detail-tool

Conversation

@shaktimaan00

Copy link
Copy Markdown

Fixes #1675

Proposed Changes

  • Add NewQuestionDetailTool() to internal/schema/mcp_tools/mcp_tools.go: tool get_question_detail with a required question_id string argument.
  • Register it in RegisterMCPRouter against the existing MCPController.MCPQuestionDetailHandler(), so the handler is no longer dead code.
  • Add internal/schema/mcp_tools/mcp_tools_test.go covering the tool contract external clients bind to: the tool name, and question_id present and required.

Why

MCPQuestionDetailHandler() and the MCPSearchQuestionDetail schema already existed, but no tool definition referenced them, so the tool was never registered and an external MCP client could only read question summaries from get_questions (title, trimmed content, link). A dedicated detail tool matches the summary/detail split the issue asks for and keeps list responses from growing.

The handler already returns only publicly visible questions (mcpQuestionIsPublic: shown, and available or closed), so no additional access-control work is needed, as the issue notes. The handler body is untouched.

Scope note

mcp_tools.MCPToolsList is intentionally left alone. That list feeds the in-app AI chat (AIController.getMCPTools → buildOpenAITools), which dispatches tool calls by name in AIController and keeps its own catalogue in internal/base/constant/ai_config.go. Advertising get_question_detail to the chat would need those changes as well; this PR only adds the tool to the MCP server, which is what the issue asks for.

Validation

gofmt -l internal/schema/mcp_tools internal/router   # no output
go build ./...                                       # ok
go test ./...                                        # 26 packages ok, no failures
golangci-lint run                                    # 0 issues

make lint itself was not run: script/check-asf-header.sh drives the ASF header formatter through Docker, which is unavailable in my build environment. The new test file carries the ASF header copied byte for byte from its neighbour.

Acceptance criteria from the issue, checked:

  • Tool definition added — go test ./internal/schema/mcp_tools/ -run TestNewQuestionDetailTool passes; renaming the tool makes it fail with tool name = "get_question_details", want "get_question_detail".
  • Registered in RegisterMCPRouter — end-to-end over the SSE transport, a client initialize + tools/list against a gin engine with RegisterMCPRouter returns
    [get_answers_by_question_id get_comments get_question_detail get_questions get_tag_detail get_tags get_user].
    With the registration line removed, get_question_detail is absent and the list holds the previous six tools.
  • No extra access control — handler body unchanged, mcpQuestionIsPublic unchanged, its test still passes.

No UI change, so no screenshots.

MCPQuestionDetailHandler and its MCPSearchQuestionDetail schema already
existed, but no tool definition referenced them, so the handler was never
registered and external MCP clients could only read question summaries from
get_questions.

Add NewQuestionDetailTool with a required question_id and register it in
RegisterMCPRouter. The handler already restricts results to publicly visible
questions, so no access-control change is needed.

This branch has not been deployed

No deployments
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.

feat(mcp): add question detail tool (get_question_detail) to MCP server

1 participant