|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package router |
| 21 | + |
| 22 | +import ( |
| 23 | + "github.com/apache/answer/internal/schema/mcp_tools" |
| 24 | + "github.com/gin-gonic/gin" |
| 25 | + "github.com/mark3labs/mcp-go/server" |
| 26 | +) |
| 27 | + |
| 28 | +func (a *AnswerAPIRouter) RegisterMCPRouter(r *gin.RouterGroup) { |
| 29 | + s := server.NewMCPServer("Answer Enterprise MCP Server", "1.0.0") |
| 30 | + |
| 31 | + s.AddTool(mcp_tools.NewQuestionsTool(), a.mcpController.MCPQuestionsHandler()) |
| 32 | + s.AddTool(mcp_tools.NewAnswersTool(), a.mcpController.MCPAnswersHandler()) |
| 33 | + s.AddTool(mcp_tools.NewCommentsTool(), a.mcpController.MCPCommentsHandler()) |
| 34 | + s.AddTool(mcp_tools.NewTagsTool(), a.mcpController.MCPTagsHandler()) |
| 35 | + s.AddTool(mcp_tools.NewTagDetailTool(), a.mcpController.MCPTagDetailsHandler()) |
| 36 | + s.AddTool(mcp_tools.NewUserTool(), a.mcpController.MCPUserDetailsHandler()) |
| 37 | + |
| 38 | + sseServer := server.NewSSEServer(s, |
| 39 | + server.WithSSEEndpoint("/answer/api/v1/mcp/see"), |
| 40 | + server.WithMessageEndpoint("/answer/api/v1/mcp/message"), |
| 41 | + ) |
| 42 | + r.GET("/mcp/sse", gin.WrapH(sseServer.SSEHandler())) |
| 43 | + r.POST("/mcp/message", gin.WrapH(sseServer.MessageHandler())) |
| 44 | +} |
0 commit comments