feat(surf): AssembleRouter builds the router and handler once; the router stops the MCP endpoint it mounted (quick-261118-lbt)

- surf.AssembleRouter returns the router and the compiled handler from
  one build, so an mcp.enabled app is not built twice; Assemble keeps
  its signature and is implemented on top of it
- serve uses AssembleRouter with a deferred Router.Close
- pier.Pier.Close stops the session reaper and the Redis warm-up; the
  router that mounted the endpoint owns it
- ExampleAssembleRouter, routing/testing docs and the surf/pier READMEs
This commit is contained in:
Jakub Zych
2026-11-18 15:44:56 +01:00
parent d9e21ad019
commit 38f7f3a777
11 changed files with 257 additions and 16 deletions

View File

@@ -20,7 +20,15 @@ import (
// handler lookup and the two mount kinds without pier importing surf.
func init() {
mountPier = func(r *Router, app *backpack.App, plugins []party.Plugin) error {
return pier.Mount(pierHost{r: r, trusted: TrustedProxies(app.Config)}, app, plugins)
if err := pier.Mount(pierHost{r: r, trusted: TrustedProxies(app.Config)}, app, plugins); err != nil {
return err
}
// The router mounted the endpoint, so its Close stops the
// endpoint's background work (also on a later BuildRouter error).
if p, ok := app.Lookup[*pier.Pier](); ok && p != nil {
r.own(p.Close)
}
return nil
}
}