mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-04-09 09:26:24 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ea5bb38ee4 | |||
| c2e2c9b873 |
@@ -67,52 +67,81 @@ Each call immediately creates four MCP **tools** and one MCP **resource** for th
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## HTTP / SSE Transport
|
## HTTP Transports
|
||||||
|
|
||||||
The `*server.SSEServer` returned by any of the helpers below implements `http.Handler`, so it works with every Go HTTP framework.
|
|
||||||
|
|
||||||
`Config.BasePath` is required and used for all route registration.
|
`Config.BasePath` is required and used for all route registration.
|
||||||
`Config.BaseURL` is optional — when empty it is detected from each request.
|
`Config.BaseURL` is optional — when empty it is detected from each request.
|
||||||
|
|
||||||
### Gorilla Mux
|
Two transports are supported: **SSE** (legacy, two-endpoint) and **Streamable HTTP** (recommended, single-endpoint).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### SSE Transport
|
||||||
|
|
||||||
|
Two endpoints: `GET {BasePath}/sse` (subscribe) + `POST {BasePath}/message` (send).
|
||||||
|
|
||||||
|
#### Gorilla Mux
|
||||||
|
|
||||||
```go
|
```go
|
||||||
resolvemcp.SetupMuxRoutes(r, handler)
|
resolvemcp.SetupMuxRoutes(r, handler)
|
||||||
```
|
```
|
||||||
|
|
||||||
Registers:
|
|
||||||
|
|
||||||
| Route | Method | Description |
|
| Route | Method | Description |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `{BasePath}/sse` | GET | SSE connection — clients subscribe here |
|
| `{BasePath}/sse` | GET | SSE connection — clients subscribe here |
|
||||||
| `{BasePath}/message` | POST | JSON-RPC — clients send requests here |
|
| `{BasePath}/message` | POST | JSON-RPC — clients send requests here |
|
||||||
| `{BasePath}/*` | any | Full SSE server (convenience prefix) |
|
|
||||||
|
|
||||||
### bunrouter
|
#### bunrouter
|
||||||
|
|
||||||
```go
|
```go
|
||||||
resolvemcp.SetupBunRouterRoutes(router, handler)
|
resolvemcp.SetupBunRouterRoutes(router, handler)
|
||||||
```
|
```
|
||||||
|
|
||||||
Registers `GET {BasePath}/sse` and `POST {BasePath}/message` on the provided `*bunrouter.Router`.
|
#### Gin / net/http / Echo
|
||||||
|
|
||||||
### Gin (or any `http.Handler`-compatible framework)
|
|
||||||
|
|
||||||
Use `handler.SSEServer()` to get an `http.Handler` and wrap it with the framework's adapter:
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
sse := handler.SSEServer()
|
sse := handler.SSEServer()
|
||||||
|
|
||||||
// Gin
|
engine.Any("/mcp/*path", gin.WrapH(sse)) // Gin
|
||||||
engine.Any("/mcp/*path", gin.WrapH(sse))
|
http.Handle("/mcp/", sse) // net/http
|
||||||
|
e.Any("/mcp/*", echo.WrapHandler(sse)) // Echo
|
||||||
// net/http
|
|
||||||
http.Handle("/mcp/", sse)
|
|
||||||
|
|
||||||
// Echo
|
|
||||||
e.Any("/mcp/*", echo.WrapHandler(sse))
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Streamable HTTP Transport
|
||||||
|
|
||||||
|
Single endpoint at `{BasePath}`. Handles POST (client→server) and GET (server→client streaming). Preferred for new integrations.
|
||||||
|
|
||||||
|
#### Gorilla Mux
|
||||||
|
|
||||||
|
```go
|
||||||
|
resolvemcp.SetupMuxStreamableHTTPRoutes(r, handler)
|
||||||
|
```
|
||||||
|
|
||||||
|
Mounts the handler at `{BasePath}` (all methods).
|
||||||
|
|
||||||
|
#### bunrouter
|
||||||
|
|
||||||
|
```go
|
||||||
|
resolvemcp.SetupBunRouterStreamableHTTPRoutes(router, handler)
|
||||||
|
```
|
||||||
|
|
||||||
|
Registers GET, POST, DELETE on `{BasePath}`.
|
||||||
|
|
||||||
|
#### Gin / net/http / Echo
|
||||||
|
|
||||||
|
```go
|
||||||
|
h := handler.StreamableHTTPServer()
|
||||||
|
// or: h := resolvemcp.NewStreamableHTTPHandler(handler)
|
||||||
|
|
||||||
|
engine.Any("/mcp", gin.WrapH(h)) // Gin
|
||||||
|
http.Handle("/mcp", h) // net/http
|
||||||
|
e.Any("/mcp", echo.WrapHandler(h)) // Echo
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Authentication
|
### Authentication
|
||||||
|
|
||||||
Add middleware before the MCP routes. The handler itself has no auth layer.
|
Add middleware before the MCP routes. The handler itself has no auth layer.
|
||||||
|
|||||||
@@ -69,12 +69,20 @@ func (h *Handler) SSEServer() http.Handler {
|
|||||||
return &dynamicSSEHandler{h: h}
|
return &dynamicSSEHandler{h: h}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StreamableHTTPServer returns an http.Handler that serves MCP over the streamable HTTP transport.
|
||||||
|
// Unlike SSE (which requires two endpoints), streamable HTTP uses a single endpoint for all
|
||||||
|
// client-server communication (POST for requests, GET for server-initiated messages).
|
||||||
|
// Mount the returned handler at the desired path; the path itself becomes the MCP endpoint.
|
||||||
|
func (h *Handler) StreamableHTTPServer() http.Handler {
|
||||||
|
return server.NewStreamableHTTPServer(h.mcpServer)
|
||||||
|
}
|
||||||
|
|
||||||
// newSSEServer creates a concrete *server.SSEServer for known baseURL and basePath values.
|
// newSSEServer creates a concrete *server.SSEServer for known baseURL and basePath values.
|
||||||
func (h *Handler) newSSEServer(baseURL, basePath string) *server.SSEServer {
|
func (h *Handler) newSSEServer(baseURL, basePath string) *server.SSEServer {
|
||||||
return server.NewSSEServer(
|
return server.NewSSEServer(
|
||||||
h.mcpServer,
|
h.mcpServer,
|
||||||
server.WithBaseURL(baseURL),
|
server.WithBaseURL(baseURL),
|
||||||
server.WithBasePath(basePath),
|
server.WithStaticBasePath(basePath),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,3 +98,36 @@ func SetupBunRouterRoutes(router *bunrouter.Router, handler *Handler) {
|
|||||||
func NewSSEServer(handler *Handler) http.Handler {
|
func NewSSEServer(handler *Handler) http.Handler {
|
||||||
return handler.SSEServer()
|
return handler.SSEServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetupMuxStreamableHTTPRoutes mounts the MCP streamable HTTP endpoint on the given Gorilla Mux router.
|
||||||
|
// The streamable HTTP transport uses a single endpoint (Config.BasePath) for all communication:
|
||||||
|
// POST for client→server messages, GET for server→client streaming.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// resolvemcp.SetupMuxStreamableHTTPRoutes(r, handler) // mounts at Config.BasePath
|
||||||
|
func SetupMuxStreamableHTTPRoutes(muxRouter *mux.Router, handler *Handler) {
|
||||||
|
basePath := handler.config.BasePath
|
||||||
|
h := handler.StreamableHTTPServer()
|
||||||
|
muxRouter.PathPrefix(basePath).Handler(http.StripPrefix(basePath, h))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupBunRouterStreamableHTTPRoutes mounts the MCP streamable HTTP endpoint on a bunrouter router.
|
||||||
|
// The streamable HTTP transport uses a single endpoint (Config.BasePath).
|
||||||
|
func SetupBunRouterStreamableHTTPRoutes(router *bunrouter.Router, handler *Handler) {
|
||||||
|
basePath := handler.config.BasePath
|
||||||
|
h := handler.StreamableHTTPServer()
|
||||||
|
router.GET(basePath, bunrouter.HTTPHandler(h))
|
||||||
|
router.POST(basePath, bunrouter.HTTPHandler(h))
|
||||||
|
router.DELETE(basePath, bunrouter.HTTPHandler(h))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewStreamableHTTPHandler returns an http.Handler that serves MCP over the streamable HTTP transport.
|
||||||
|
// Mount it at the desired path; that path becomes the MCP endpoint.
|
||||||
|
//
|
||||||
|
// h := resolvemcp.NewStreamableHTTPHandler(handler)
|
||||||
|
// http.Handle("/mcp", h)
|
||||||
|
// engine.Any("/mcp", gin.WrapH(h))
|
||||||
|
func NewStreamableHTTPHandler(handler *Handler) http.Handler {
|
||||||
|
return handler.StreamableHTTPServer()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user