diff --git a/internal/router/mcp_router.go b/internal/router/mcp_router.go index 54f41971d..8025465db 100644 --- a/internal/router/mcp_router.go +++ b/internal/router/mcp_router.go @@ -29,6 +29,7 @@ func (a *AnswerAPIRouter) RegisterMCPRouter(r *gin.RouterGroup) { s := server.NewMCPServer("Answer Enterprise MCP Server", "1.0.0") s.AddTool(mcp_tools.NewQuestionsTool(), a.mcpController.MCPQuestionsHandler()) + s.AddTool(mcp_tools.NewQuestionDetailTool(), a.mcpController.MCPQuestionDetailHandler()) s.AddTool(mcp_tools.NewAnswersTool(), a.mcpController.MCPAnswersHandler()) s.AddTool(mcp_tools.NewCommentsTool(), a.mcpController.MCPCommentsHandler()) s.AddTool(mcp_tools.NewTagsTool(), a.mcpController.MCPTagsHandler()) diff --git a/internal/schema/mcp_tools/mcp_tools.go b/internal/schema/mcp_tools/mcp_tools.go index 3ae6b3bea..4b237b84a 100644 --- a/internal/schema/mcp_tools/mcp_tools.go +++ b/internal/schema/mcp_tools/mcp_tools.go @@ -55,6 +55,16 @@ func NewQuestionsTool() mcp.Tool { return listFilesTool } +func NewQuestionDetailTool() mcp.Tool { + return mcp.NewTool("get_question_detail", + mcp.WithDescription("Get the full content of a specific question by its ID. The question ID is provided by the get_questions tool."), + mcp.WithString(schema.MCPSearchCondQuestionID, + mcp.Required(), + mcp.Description("The ID of the question to retrieve"), + ), + ) +} + func NewAnswersTool() mcp.Tool { listFilesTool := mcp.NewTool("get_answers_by_question_id", mcp.WithDescription("Search for all answers corresponding to the question ID. The question ID is provided by get_questions tool."), diff --git a/internal/schema/mcp_tools/mcp_tools_test.go b/internal/schema/mcp_tools/mcp_tools_test.go new file mode 100644 index 000000000..b9902e480 --- /dev/null +++ b/internal/schema/mcp_tools/mcp_tools_test.go @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package mcp_tools + +import ( + "slices" + "testing" + + "github.com/apache/answer/internal/schema" +) + +func TestNewQuestionDetailTool(t *testing.T) { + tool := NewQuestionDetailTool() + + if tool.Name != "get_question_detail" { + t.Fatalf("tool name = %q, want %q", tool.Name, "get_question_detail") + } + if _, ok := tool.InputSchema.Properties[schema.MCPSearchCondQuestionID]; !ok { + t.Fatalf("%s must be an input property: %v", schema.MCPSearchCondQuestionID, tool.InputSchema.Properties) + } + + if !slices.Contains(tool.InputSchema.Required, schema.MCPSearchCondQuestionID) { + t.Fatalf("%s must be required: %v", schema.MCPSearchCondQuestionID, tool.InputSchema.Required) + } +}