feat(19.7-01): streaming routes, MCP mount hook, configurable authorize scopes

- surf.Router.MountStream and recoverStream: a raw, unbuffered route kind
  whose http.Flusher reaches the client; panic after the first byte only
  aborts the body
- surf.MCPBuildTag and the mountPier hook: mcp.enabled is inert without the
  summercms_mcp tag until it is true, then boot fails naming the tag
  (pier_off.go is the untagged side)
- wristband parseAuthorizeScopes takes the server's allowed set built from
  Options.ScopesSupported; the default set is unchanged
- cooler.KeyPrefix exported for the MCP module's Redis keys
- smoke tests TestStreamingRouteSmoke, TestPierMountSmoke, TestMCPScopesSmoke
- surf, wristband and cooler READMEs, docs/services/{routing,oauth-server}.md
This commit is contained in:
Jakub Zych
2026-10-22 16:11:37 +02:00
parent 1bd91a4522
commit 5c15dea569
13 changed files with 506 additions and 12 deletions

View File

@@ -2,6 +2,7 @@ package surf
import (
"bytes"
"errors"
"fmt"
"log/slog"
"math"
@@ -46,8 +47,18 @@ type route struct {
// preflight marks an OPTIONS route addCORSPreflights registered for a
// cors:<profile> path: wrapped only in recovery and recordPattern.
preflight bool
// stream marks a MountStream route: raw, and served without the
// response buffer so the handler can flush to the client (streaming.go).
stream bool
}
// mountPier is the hook the MCP module (pier) sets when a binary is built
// with the summercms_mcp tag (pier_on.go); without the tag it stays nil
// (pier_off.go). BuildRouter calls it after every plugin route and the admin
// exist, when mcp.enabled is true. pier throttles its endpoint with the
// inline throttle:<max>,<minutes> spelling, so no bucket is registered here.
var mountPier func(r *Router, app *backpack.App, plugins []party.Plugin) error
// Router compiles group declarations onto net/http ServeMux.
type Router struct {
pluginID string
@@ -503,9 +514,12 @@ func (r *Router) wrap(rt route) (http.Handler, error) {
h = bodyLimit(limit)(h)
}
h = r.locale(h)
if rt.raw {
switch {
case rt.stream:
h = recoverStream(r.pages, h)
case rt.raw:
h = recoverBare(r.pages, h)
} else {
default:
h = recoverJSON(r.pages, h)
}
// The CORS profile wraps recovery, so a refusal from a guard listed
@@ -680,6 +694,16 @@ func BuildRouter(app *backpack.App, plugins []party.Plugin) (*Router, error) {
r.pages.setAdminPrefix(admin.Prefix)
r.adminMounted = true
}
// The MCP module mounts last, so its tool bindings can see every plugin
// route and the admin (D-30: nothing when off; D-33: tag required).
if app != nil && app.Config != nil && app.Config.Bool("mcp.enabled") {
if mountPier == nil {
return nil, errors.New("surf: mcp.enabled is true but this binary was built without the summercms_mcp tag (summer.yaml build.tags)")
}
if err := mountPier(r, app, plugins); err != nil {
return nil, err
}
}
if err := r.compileHandlers(); err != nil {
return nil, err
}