feat(subscription): realtime mutation publishing + MCP resource notifications - #2
feat(subscription): realtime mutation publishing + MCP resource notifications#2Azzerty23 wants to merge 1 commit into
Conversation
…ications Add a single-source-of-truth realtime path so data changes reach both the app (oRPC SSE) and MCP clients, without a second event bus. - MutationPublisher port + ModelMutationEvent, structurally identical to @viiite/server's Publisher so a Durable-Object-backed instance can be passed directly. Ships createInMemoryPublisher() default + defaultChannel(). - execute tool publishes a ModelMutationEvent after every successful write (channel = model.toLowerCase()); await-with-catch so a publish failure never fails the write and post-response async isn't cut on serverless. - registerModelResources + bridgeModelMutations: expose models as subscribable MCP resources and push notifications/resources/updated while subscribed. - server-adapters/workers: McpAgent (Durable Object) + OAuthProvider adapter wiring buildMcpServer, resources, and the publisher bridge; resolves the user from OAuth props. agents/@cloudflare/workers-oauth-provider are optional peers. - docs/realtime-notifications.md covers piece 1, piece 2, and the Workers wiring. Tests: in-memory publisher, execute-tool publishing, and the resource bridge. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Free Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (13)
WalkthroughAdds a mutation pub/sub system to ChangesMutation pub/sub and MCP resource notifications
Sequence Diagram(s)sequenceDiagram
participant LLMClient as LLM Client
rect rgba(100, 149, 237, 0.5)
Note over LLMClient,MutationPublisher: Setup
LLMClient->>McpServer: resources/subscribe (zenstack://Post)
McpServer->>bridgeModelMutations: subscribe handler
bridgeModelMutations->>MutationPublisher: subscribe("post", {signal})
end
rect rgba(144, 238, 144, 0.5)
Note over LLMClient,MutationPublisher: Write path
LLMClient->>McpServer: tool call: execute(create Post)
McpServer->>ZenStackClient: db.post.create(...)
ZenStackClient-->>McpServer: created record
McpServer->>MutationPublisher: publish("post", ModelMutationEvent{create})
MutationPublisher->>bridgeModelMutations: event delivered
bridgeModelMutations->>McpServer: sendResourceUpdated(zenstack://Post)
McpServer->>LLMClient: notifications/resources/updated
end
rect rgba(255, 165, 0, 0.5)
Note over LLMClient,MutationPublisher: Teardown
LLMClient->>McpServer: resources/unsubscribe
McpServer->>bridgeModelMutations: unsubscribe handler → abort loop
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Add a single-source-of-truth realtime path so data changes reach both the app (oRPC SSE) and MCP clients, without a second event bus.
Tests: in-memory publisher, execute-tool publishing, and the resource bridge.
Summary by CodeRabbit
Release Notes
New Features
Documentation
Tests