You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add SessionWithResourceTemplates for session-specific resource templates (#624)
* feat: add SessionWithResourceTemplates for session-specific resource templates
Implements session-specific resource templates to achieve parity with
SessionWithTools and SessionWithResources. This allows sessions to have
their own resource templates that override global templates with the
same URI pattern.
Key changes:
- Add SessionWithResourceTemplates interface to ClientSession hierarchy
- Implement interface in both SSE and StreamableHTTP transports
- Add AddSessionResourceTemplate(s) and DeleteSessionResourceTemplates methods
- Update handleListResourceTemplates to merge session and global templates
- Update handleReadResource to check session templates before global ones
- Session templates trigger notifications/resources/list_changed when modified
Closes#622
* test: add comprehensive tests for session resource templates
- Add sessionTestClientWithResourceTemplates mock
- Test AddSessionResourceTemplate and AddSessionResourceTemplates
- Test DeleteSessionResourceTemplates
- Test session template override behavior
- Test notification behavior (enabled/disabled)
- Test uninitialized session handling
- Test error cases for unsupported sessions
- Verify thread-safety through existing patterns
Coverage increased from 70.17% to 72.8% (+2.63%)
* refactor: address CodeRabbit review comments
- Use atomic.Bool for initialized field in test mock to prevent data races
- Add nil checks for URITemplate in handleReadResource for both session and global templates
- Add validation in AddSessionResourceTemplates to prevent nil URITemplate, empty URI, or empty Name
- Simplify Get/SetSessionResourceTemplates using maps.Clone
- Fix test initialization states to match expected behavior
All tests pass with race detector.
0 commit comments