examples: MongoDB SessionStore reference adapter#341
Open
alexbevi wants to merge 4 commits into
Open
Conversation
Adds a MongoDB-backed `SessionStore` example under `examples/session-stores/mongodb/`, mirroring the Postgres adapter's conventions: one document per JSONL entry, ordering via the server-generated `_id`, and live-only env-gated conformance. Provides `MongoDBSessionStore`, an `ensureSchema()` helper that creates the indexes covering `load()`, `delete()`, and `listSessions()`, plus a `demo.ts` round-trip and constructor unit tests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Updates the umbrella `examples/session-stores/README.md` to advertise the new MongoDB adapter alongside S3, Redis, and Postgres: adapter table row, layout glob, full MongoDB section (storage model + live end-to-end snippet), and a production-checklist subsection covering write concern, retention, and pool sizing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Updates the README, demo header, and conformance-test header to use `mongo:latest` instead of `mongo:7` for consistency with the rest of the project's tooling guidance. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The driver defaults to `w: "majority"`, which is the right thing for durability-sensitive mirror writes. Steering readers toward `w: 1` or mentioning `w: 0` at all is bad advice in this context — drop the bullet entirely. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Author
|
Can't update https://code.claude.com/docs/en/agent-sdk/session-storage#reference-implementations, but was hoping to get it added there. I can do the Python example as well if this approach is acceptable. |
Author
|
Ended up opening this as anthropics/claude-agent-sdk-python#1014 for the Python side |
8 tasks
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.
A self-contained reference
SessionStoreimplementation for MongoDB underexamples/session-stores/mongodb/, alongside the existing S3/Redis/Postgres adapters. ImportsSessionStore,SessionKey, andSessionStoreEntrytypes from the published@anthropic-ai/claude-agent-sdkpackage and passes the 13-contract conformance suite atexamples/session-stores/shared/conformance.ts.mongodb/mongodbSESSION_STORE_MONGODB_URLStorage model
One document per JSONL entry, ordering via the server-generated
_id(ObjectId) — same property the Postgres adapter exploits withBIGSERIAL.ensureSchema()is idempotent and creates two compound indexes coveringload()/delete()/listSubkeys()andlistSessions()respectively. The adapter follows the Postgres pattern of live-only conformance: there is no in-process Mongo mock that faithfully exercises the aggregation pipeline anddistinct.Running
CI / packaging impact: none
Nothing under
examples/is packaged, published, or built by repo CI;examples/.gitignorealready excludesnode_modulesand lockfiles. No workflow files added. The umbrellaexamples/session-stores/README.mdis updated to advertise the new adapter (table row, layout glob, MongoDB section, production checklist).Verified locally
bun run typecheckclean.bun test test/MongoDBSessionStore.test.ts— 2/2 pass; live suite skips cleanly when env unset.docker run -d -p 27017:27017 mongo:latest: 15/15 pass (13 contract tests +ensureSchema is idempotent+listSessions mtime is epoch ms).pineapple, second call resumed from Mongo and repliedpineappleagain.mongoshconfirmed 18 entries persisted underclaude_test.claude_session_entries.Test plan
cd examples/session-stores/mongodb && bun install && bun run typecheckbun test test/MongoDBSessionStore.test.ts— 2/2 pass with no infradocker run -d -p 27017:27017 mongo:latestthenSESSION_STORE_MONGODB_URL=mongodb://localhost:27017 bun run test:live— 15/15 passANTHROPIC_API_KEYset,SESSION_STORE_MONGODB_URL=mongodb://localhost:27017 bun run demo.tsprints twopineappleresults