Commit Graph

2 Commits

Author SHA1 Message Date
Sam Morrow 1d05b3285e address review feedback
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
Build and Test Go Project / build (macos-latest) (push) Has been cancelled
Build and Test Go Project / build (ubuntu-latest) (push) Has been cancelled
Build and Test Go Project / build (windows-latest) (push) Has been cancelled
License Check / license-check (push) Has been cancelled
- Fix inconsistent terminology (NewInventoryBuilder -> CachedInventoryBuilder)
- Add explicit initialized flag for reliable state checking
- Clarify contradictory documentation about initialization requirement
- Improve ResetInventoryCache warning about thread safety
- Add comment explaining why tests don't use t.Parallel()
2025-12-17 23:06:41 +01:00
Sam Morrow a456b8249f perf: add inventory cache for stateless server patterns
Add CachedInventory to build tool/resource/prompt definitions once at
startup rather than per-request. This is particularly useful for the
remote server pattern where a new server instance is created per request.

Key features:
- InitInventoryCache(t) initializes the cache once at startup
- InitInventoryCacheWithExtras(t, tools, resources, prompts) allows
  injecting additional items (e.g., remote-only Copilot tools)
- CachedInventoryBuilder() returns a builder with pre-cached definitions
- Per-request configuration (read-only, toolsets, feature flags) still works
- Thread-safe via sync.Once
- Backward compatible: NewInventory(t) still works without caching

This addresses the performance concern raised in go-sdk PR #685 at a
higher level by caching the entire []ServerTool slice rather than
individual schemas.

Related: https://github.com/modelcontextprotocol/go-sdk/pull/685
2025-12-17 23:01:29 +01:00