feat(resources): Add resources/subscribe and resources/unsubscribe support#98
Open
getlarge wants to merge 2 commits intoplatformatic:mainfrom
Open
feat(resources): Add resources/subscribe and resources/unsubscribe support#98getlarge wants to merge 2 commits intoplatformatic:mainfrom
getlarge wants to merge 2 commits intoplatformatic:mainfrom
Conversation
…on tests The MCP SDK types use discriminated unions (e.g., text | image content). TypeScript requires type narrowing before accessing type-specific properties. This fixes typecheck failures introduced by SDK type changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…pport - Add mcpSetResourceSubscribeHandler and mcpSetResourceUnsubscribeHandler decorators for custom subscription management - Implement resources/subscribe and resources/unsubscribe JSON-RPC methods - Add query parameter URI fallback: when exact match fails and URI has query params, try base URI for resources with uriSchema - Return METHOD_NOT_FOUND when handlers not configured (clear signal) This enables MCP clients to subscribe/unsubscribe to resource changes while keeping subscription storage application-managed. Closes platformatic#96 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds MCP spec-compliant
resources/subscribeandresources/unsubscribemethods, plus query parameter URI matching for resources withuriSchema.Closes #96
Changes
1. Custom Subscription Handlers
Applications can now implement their own subscription storage:
2. Query Parameter URI Matching
Resources with
uriSchemacan now be read with query parameters:Files Changed
src/types.ts- Add subscription handler types and Fastify declarationsrc/decorators/meta.ts- Add setter decoratorssrc/handlers.ts- Add subscription handlers and query param fallbacksrc/index.ts- Create and pass resourceHandlerssrc/routes/mcp.ts- Include resourceHandlers in dependenciestest/integration.test.ts- Fix type guards (cherry-picked)Design Decisions
Backwards Compatibility
mcpAddResourceregistrations unchangedresources/readbehavior unchanged for exact matchesTest Plan
npm run typecheck)npm run test)🤖 Generated with Claude Code