Implement resource subscriptions with file sync (resources-subscribe)#273
Draft
jancurn wants to merge 1 commit into
Draft
Implement resource subscriptions with file sync (resources-subscribe)#273jancurn wants to merge 1 commit into
jancurn wants to merge 1 commit into
Conversation
…safe resources-subscribe <uri> <file> now keeps a local file in sync with the resource: the bridge downloads it on subscribe and rewrites it on every notifications/resources/updated (re-reading the resource, per the MCP spec the notification carries no content). Subscriptions persist in sessions.json, are re-established and re-synced on bridge restart, and are listed in `mcpc @session` output. resources-unsubscribe stops the sync and keeps the file. resources-read gains -o <file> (binary-safe save that decodes base64 blobs; previously advertised but unimplemented) and --raw for piping (consistent with skills-get --raw, with a TTY guard for binary content). The default human view renders text in a fenced block and summarizes binary content instead of dumping it. The never-enforced --max-size option is removed. https://claude.ai/code/session_01HWY3cK2NAURyyQRxDDjoBY
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
Implements the
resources-subscribeandresources-unsubscribecommands, allowing users to keep local files in sync with MCP server resources. When a resource is subscribed, the bridge downloads it to a local file and automatically re-syncs whenever the server sendsnotifications/resources/updatednotifications. Subscriptions persist across bridge restarts.Key Changes
Core Resource Sync Infrastructure:
ResourceSyncManager(src/bridge/resource-sync.ts) to track subscriptions and coordinate file syncingsessions.jsonfor crash recoveryselectResourceContent()andwriteResourceFile()helpers (src/lib/resource-content.ts) for materializing MCP resource contentsCLI Commands:
resources-subscribe <uri> <file>command to subscribe and sync a resource to a local fileresources-unsubscribe <uri>command to remove subscriptions (keeps the synced file)resources-readcommand with:-o/--output <file>flag to save resource content to a file (binary-safe)--rawflag to print bare content suitable for pipingBridge Integration:
ResourceSyncManagerinto bridge process to handlenotifications/resources/updatedrestoreResourceSubscriptions()to re-establish persisted subscriptions on bridge startupSession Data & Output:
resourceSubscriptionsfield toSessionDatafor persistenceResourceSubscriptionEntrytype with URI, file path, timestamps, and error trackingformatServerDetails()to show active subscriptions with sync statusformatResourceContents()for pretty-printing resource read resultsformatTimeAgo()helper for human-friendly timestamp displayTest Coverage:
ResourceSyncManager(coalescing, error handling, persistence)resource-sync.test.sh) covering subscribe/unsubscribe, notifications, restarts, and error casesNotable Implementation Details
resources/updatednotifications arriving during an in-flight sync are collapsed into exactly one queued follow-up sync, preventing thrashing on rapid updatesresourceSubscriptionsfield is optional inSessionDatahttps://claude.ai/code/session_01HWY3cK2NAURyyQRxDDjoBY