How can I integrate with a Gin server? #308
-
I have a Gin server with other endpoints already, and I want to expose the SSE server over a prefix like I've seen some examples of using a custom http server, but it is not clear how to set it up with Gin, which is a rather popular framework. For reference, see this example of Gin integration in another MCP SDK: https://github.com/ThinkInAIXYZ/go-mcp?tab=readme-ov-file#integration-with-gin-server |
Beta Was this translation helpful? Give feedback.
Answered by
lariel-fernandes
May 19, 2025
Replies: 1 comment
-
Answering my own question here, I hope it might be useful for others: mcpServer := server.NewMCPServer("my_mcp", "0.0.0")
// add tools
sseServer := server.NewSSEServer(
mcpServer,
server.WithSSEEndpoint("/mcp/sse"),
server.WithMessageEndpoint("/mcp/message"),
)
// engine *gin.Engine
engine.GET("/mcp/sse", func(c *gin.Context) {
sseServer.SSEHandler().ServeHTTP(c.Writer, c.Request)
})
engine.POST("/mcp/message", func(c *gin.Context) {
sseServer.MessageHandler().ServeHTTP(c.Writer, c.Request)
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lariel-fernandes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answering my own question here, I hope it might be useful for others: