feat(36-01): export cabana.TokenScopeCovers and warn on uncovered backend write MCP tools in pier.Mount
This commit is contained in:
@@ -113,6 +113,7 @@ func Mount(host Host, app *backpack.App, plugins []party.Plugin) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
warnUncoveredBackendWriteTools(app, plugins, cat)
|
||||
frontend, err := frontendGuardName(reg)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
46
modules/pier/uncovered_scopes_warning.go
Normal file
46
modules/pier/uncovered_scopes_warning.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package pier
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"slices"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/cabana"
|
||||
"git.golem15.com/golem15/summercms/modules/party"
|
||||
)
|
||||
|
||||
// warnUncoveredBackendWriteTools checks every compiled backend non-GET/HEAD
|
||||
// MCP tool against all registered non-"*" TokenScopes and logs one structured
|
||||
// Warn per plugin with uncovered tools so operators notice plugins missing
|
||||
// pact.HasTokenScopes. It never fails boot.
|
||||
func warnUncoveredBackendWriteTools(app *backpack.App, plugins []party.Plugin, cat *catalog) {
|
||||
if cat == nil || len(cat.tools) == 0 {
|
||||
return
|
||||
}
|
||||
byPlugin := map[string][]string{}
|
||||
var pluginOrder []string
|
||||
for _, t := range cat.tools {
|
||||
if t.guardName != BackendGuard {
|
||||
continue
|
||||
}
|
||||
if t.method == http.MethodGet || t.method == http.MethodHead {
|
||||
continue
|
||||
}
|
||||
if cabana.TokenScopeCovers(app, plugins, t.method, t.decl.Permissions) {
|
||||
continue
|
||||
}
|
||||
if _, seen := byPlugin[t.pluginID]; !seen {
|
||||
pluginOrder = append(pluginOrder, t.pluginID)
|
||||
}
|
||||
byPlugin[t.pluginID] = append(byPlugin[t.pluginID], t.name)
|
||||
}
|
||||
for _, pluginID := range pluginOrder {
|
||||
tools := byPlugin[pluginID]
|
||||
slices.Sort(tools)
|
||||
logger().Warn(
|
||||
"pier: plugin registers backend write MCP tools not covered by any non-* TokenScope; implement pact.HasTokenScopes so scoped tokens and MCP OAuth grants can call them",
|
||||
"plugin", pluginID,
|
||||
"tools", tools,
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user