feat(resolvemcp): add SSE server and bunrouter setup functions

* Introduce SSEServer method for creating an SSE server bound to the handler.
* Add SetupBunRouterRoutes function to mount MCP HTTP/SSE endpoints on bunrouter.
* Update README with usage examples for new features.
This commit is contained in:
Hein
2026-03-27 13:28:03 +02:00
parent 7ef9cf39d3
commit 200a03c225
3 changed files with 416 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ import (
"github.com/gorilla/mux"
"github.com/mark3labs/mcp-go/server"
"github.com/uptrace/bun"
bunrouter "github.com/uptrace/bunrouter"
"gorm.io/gorm"
"github.com/bitechdev/ResolveSpec/pkg/common"
@@ -81,3 +82,19 @@ func NewSSEServer(handler *Handler, baseURL, basePath string) *server.SSEServer
server.WithBasePath(basePath),
)
}
// SetupBunRouterRoutes mounts the MCP HTTP/SSE endpoints on a bunrouter router.
//
// Two routes are registered under the given basePath prefix:
// - GET {basePath}/sse — SSE connection endpoint
// - POST {basePath}/message — JSON-RPC message endpoint
func SetupBunRouterRoutes(router *bunrouter.Router, handler *Handler, baseURL, basePath string) {
sseServer := server.NewSSEServer(
handler.mcpServer,
server.WithBaseURL(baseURL),
server.WithBasePath(basePath),
)
router.GET(basePath+"/sse", bunrouter.HTTPHandler(sseServer.SSEHandler()))
router.POST(basePath+"/message", bunrouter.HTTPHandler(sseServer.MessageHandler()))
}