Files
zzet--gortex/internal/mcp/resources_broadcaster.go
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

48 lines
1.8 KiB
Go

package mcp
// resourcesUpdatedNotifier is the slice of *server.MCPServer the
// resource broadcaster needs to push `notifications/resources/updated`
// events to every connected client. Defined here so tests can inject a
// recorder without spinning up a full MCP server.
//
// The MCP spec lets clients call `resources/subscribe` to opt into
// updates for a specific URI. Mark3labs's SDK doesn't track that
// subscription set itself — so we broadcast to all clients and let the
// client-side runtime ignore URIs it didn't subscribe to. That matches
// what the diagnostics broadcaster does for `notifications/diagnostics`,
// minus the per-session filter (resource updates are URI-scoped, not
// session-scoped, and the payload itself is empty — clients re-fetch).
type resourcesUpdatedNotifier interface {
SendNotificationToAllClients(method string, params map[string]any)
}
// notifyBootstrapResourcesUpdated pushes a
// `notifications/resources/updated` for every bootstrap resource URI.
// Called after each graph re-warm so subscribed clients can stop
// polling `gortex://stats` / `gortex://index-health` / etc.
//
// Prefers an explicit override (`Server.resourcesNotifier`) so tests
// can record broadcasts without spinning up a full MCP server. Falls
// back to the live mcpServer; no-ops cleanly when neither is wired.
func (s *Server) notifyBootstrapResourcesUpdated() {
notifier := s.effectiveResourcesNotifier()
if notifier == nil {
return
}
for _, uri := range bootstrapResourceURIs() {
notifier.SendNotificationToAllClients("notifications/resources/updated", map[string]any{
"uri": uri,
})
}
}
func (s *Server) effectiveResourcesNotifier() resourcesUpdatedNotifier {
if s.resourcesNotifier != nil {
return s.resourcesNotifier
}
if s.mcpServer == nil {
return nil
}
return s.mcpServer
}