Repository navigation
Forkable reference agent templates: research, RAG, and monitor over the MCP triad #28
Description
Context
There are no examples/ and no Nexus/Talus 'first agent call' onboarding (roadmap §5 gaps). Agent builders have to reverse-engineer how to drive contextmem_extract/recall/remember from the MCP server in packages/mcp. The roadmap calls for 2-3 runnable templates plus a sample Nexus DAG that calls a tool and emits an on-chain receipt.
Goal / user story
As an agent builder, I want forkable starter templates that already wire the ContextMEM triad over MCP for the three obvious patterns — research, RAG chat, and change-monitoring — so I can clone one, point it at my namespace, and have a working Sui-native agent in minutes.
Acceptance criteria
-
examples/research-agent/— a minimal TS/LangGraph (or plain MCP-client) agent that runsextractover N sources,remembers them to a namespace, thenrecalls to answer a question; runnable with documented env. -
examples/rag-chat/— a recall-grounded chat loop that callsrecall(withincludeSources) against the hosted MCP namespace and cites sources per turn. -
examples/monitor-agent/— a scheduled agent that re-extracts a target, diffs vs the prior run, andremembers only the delta (mirroring the live*/30freshness pattern), printing 'what changed'. - A combined
mcpServersJSON example shows ContextMEM (and optionally a second MCP) configured together for Claude/Cursor, including the read-token header for private namespaces. -
examples/nexus-dag/— a sample Talus/Nexus DAG (or a clearly-labeled scaffold) that calls one triad tool as a node and shows where the attribution receipt id flows intoparentsof the next node. - Each template has its own README (prereqs, env, run command) and an
examples/README.mdindex; CI or a documentedbuncommand can at least typecheck the templates.
Implementation notes
- Add a top-level
examples/dir; templates consume the published@contextmem/mcp(or the hosted URL viamcp-remote) — keep them decoupled from monorepo internals so they're genuinely forkable. - Reuse the canonical triad I/O schemas (from the triad issue) as the typed contract; the monitor template should reuse
diffRunSnapshotssemantics and the delta-write path (rememberSnapshotDelta) conceptually. - The
nexus-dagexample should reference the receipt envelope returned by the tools (receipt.id,parents) so it doubles as the 'first Nexus call' doc; mark clearly which parts are live vs awaiting the Move receipt module. - Gotcha: private namespaces need the
Authorization: Bearer <read-token>header — make this explicit in every template's config so users don't hit silent 401s. - Keep secrets out of committed examples; use
.env.exampleper template.
Sui Overflow angle
These templates are the agent-ecosystem on-ramp for Sui Overflow: research/RAG/monitor are the canonical agent shapes, and shipping them pre-wired to a Walrus-backed, receipt-emitting memory layer lets other hackathon teams build Sui-native agents on top of ContextMEM. The Nexus DAG example is the concrete 'compose ContextMEM into a Talus pipeline' artifact judges can run.
Dependencies
Depends on the canonical triad issue (stable tool contract). Soft-depends on the publish issue (@contextmem/mcp for clean installs) and the on-chain attribution-receipt issue (for the Nexus DAG receipt flow).
Part of the ContextMEM roadmap (#4) • Sui Overflow build.
Activity
harrymove-ctrl commentedon Jun 19, 2026
Implementation Plan
Approach
Add a new top-level
examples/directory with five forkable artifacts (research-agent, rag-chat, monitor-agent, a combinedmcpServersconfig, and a clearly-labeled nexus-dag scaffold), each driving ContextMEM purely over MCP — the hosted read MCP viamcp-remote/StreamableHTTP, and the local write MCP via stdio (bun .../packages/mcp/src/index.ts). Key design decision: templates are decoupled from monorepo internals (ownpackage.json+.env.exampleper template, kept OUT of rootworkspacesso a fork is genuinely standalone), while an in-repoexamples/tsconfig.json+bun run typecheck:examples(wired into CI) keeps them green by resolving against the root-hoisted@modelcontextprotocol/sdk+zod. Because there is no published npm@contextmem/mcpyet (it isprivate:true,exports→./src/index.ts) and no on-chainreceipt.id/parents, the plan defaults to the install paths that work today and marks the Nexus receipt fields as scaffold-only.Prerequisites & dependencies
packages/mcp/src/index.ts; the hosted read tools export TS result types from@contextmem/mcp/hosted(HostedSearchResult,HostedNamespaceSummary, etc.). Templates should import the canonical shared schemas once that issue lands; until then they pin a small localcontract.tsmirroring the real I/O (documented as “replace with the published schema”).@contextmem/mcpon npm). Until it ships there is nonpx @contextmem/mcp: WRITE toolset is clone-based (bun <repo>/packages/mcp/src/index.ts), READ toolset isnpx -y mcp-remote <hosted-url>. State both in every README.WalrusStorageReceipt(packages/core/src/types.ts:654) ={ provider:"tatum", jobId, blobId?, artifactDigest?, certified, downloadUrls?, ... }with noidand noparents. The nexus-dag example is a scaffold that maps those to the future Movereceiptstruct (roadmap §2:op,namespace,producer,source_digest,artifact_digest,walrus_blob_id,parents: vector<ID>)..env.example):MEMWAL_ACCOUNT_ID+MEMWAL_PRIVATE_KEY(64-char Ed25519 hex) — required byMemWalMcpClient(packages/memwal/src/index.ts:85-89);CONTEXTMEM_RUNS_DIR; andTATUM_API_KEY(mainnet) +TATUM_STORAGE_URLonly if callingupload_proof_to_walrus(README.md:123).CONTEXTMEM_MCP_URL(defaulthttps://contextmem-backend.petlofi.workers.dev/mcp?namespace=<ns>, worker.ts:4601-4605),CONTEXTMEM_NAMESPACE, andCONTEXTMEM_READ_TOKEN(ctxm_…) sent asAuthorization: Bearer <token>— required for private namespaces (worker.ts:779; auth checkstore.authorizeNamespace).OPENAI_API_KEY/ OpenRouter base+model (templates degrade to printing grounded sources if unset).Step-by-step
Scaffold
examples/+ shared contract + tooling.examples/README.md(index table of the 5 templates, the “which install path works today” note, and the env-matrix above).examples/tsconfig.jsonextendingtsconfig.base.jsonwithnoEmitandinclude: ["*/src/**/*.ts", "_shared/**/*.ts"].examples/_shared/contract.ts: re-export hosted result types from@contextmem/mcp/hostedand define a minimal triad I/O + a placeholderReceiptEnvelopetype ({ id?: string; parents?: string[]; blobId?: string; artifactDigest?: string; jobId: string; certified: boolean }) with a comment thatid/parentsawait the Move receipt module. Createexamples/_shared/mcpClient.tshelpers:connectStdioWrite()(StdioClientTransport spawningbun <repo>/packages/mcp/src/index.ts) andconnectHostedRead({url, token})(StreamableHTTPClientTransport withrequestInit.headers.Authorization). Imports:@modelcontextprotocol/sdk/client/index.js,.../client/stdio.js,.../client/streamableHttp.js.package.json: add"typecheck:examples": "tsc -p examples/tsconfig.json --noEmit"and append it to thecheckscript. Do not addexamples/*toworkspaces(keeps forks standalone).(Recommended enabling change) Expose a web build tool in the local MCP. Today
buildAgentReadableSiteis imported but never registered as a tool (packages/mcp/src/index.ts:8); the only run-dir-producing tool isextract_walrus_context(index.ts:114-131, Walrus-only). Add abuild_web_contexttool (wrapsbuildAgentReadableSite, writes a run underrunsDir, returns{ runDir }) so the research/monitor web flow is pure-MCPextract → remember. Without it, web templates must shell thecontextmemCLI to create a run, or target Walrus sites. (Small, isolated; lives in the executing engineer’s scope, not this plan.)examples/research-agent/— local write MCP (stdio). Files:package.json,tsconfig.json,.env.example,README.md,src/index.ts.build_web_contextfrom step 2, orextract_walrus_contextfor*.wal.app,index.ts:114) → remember viaremember_site_snapshot({ runDir, namespace })(index.ts:161-186) → recall viarecall_site_context({ namespace, query })(index.ts:234-241) to answer the question; print the answer. Document the LangGraph variant as an optional swap-in (same MCP calls inside graph nodes).remember_site_snapshotneeds a run dir (context/manifest.json); that is exactly why step 2 matters for web sources.examples/rag-chat/— hosted read MCP (StreamableHTTP). Files as above +src/index.ts.get_context_bundle({ query })(hosted,packages/mcp/src/hosted.ts:220-259) which returns{ summary, searchResults[], excerpts[], memory };searchResultscarrysourceLabel/sourceTarget/snippet(hosted.ts:48-57). This is the concrete answer to the issue’s “recallwithincludeSources” — there is no literalincludeSourcesflag;get_context_bundle/search_contextare the source-grounded tools. Build a cited prompt, call the LLM (OpenRouter/OpenAI viafetch) or print grounded sources if no key; cite sources every turn.Authorization: Bearer $CONTEXTMEM_READ_TOKEN) and a one-line note that public namespaces need no token (mirrors worker.ts:8024 hint).examples/monitor-agent/— local write MCP (stdio), mirrors the live*/30freshness pattern. Files as above +src/index.ts+ a.last-run.json(gitignored) for prior-run state.setInterval; README documents the real*/30cron analog): re-extract target into a new run → diff viadiff_site_snapshots({ runId, compareToRunId: priorRunId })(index.ts:287-294, backed bydiffRunSnapshots) → if changed, remember only the delta viaupload_proof_to_walrus({ runDir, remember:true, namespace, whatChanged:<diff summary> })(index.ts:188-224) and print “what changed.” README cites the conceptual reuse ofdiffRunSnapshots+rememberSnapshotDelta/rememberStorageIndex(packages/memwal/src/index.ts:123,164) that power the production cron, and notes that pure per-chunk delta writes are a library-level path (rememberSnapshotDelta) not yet a standalone MCP tool.examples/mcpServers.example.json+ section inexamples/README.md— combined config for Claude/Cursor showing ContextMEM (hosted, viamcp-remotewith--header Authorization: Bearer <token>) + a second MCP (@tatumio/blockchain-mcp). Reuse the exact snippet shapes from worker.ts:3244-3293 (claudeDesktop/cursor) and README.md:100-121; make the read-token header explicit and add the “public needs no token” caveat. Provide both a private (header) and public (no header) variant.examples/nexus-dag/— clearly-labeled scaffold (not a runnable mainnet DAG). Files:README.md,dag.example.{yaml,ts},src/receipt-flow.ts.upload_proof_to_walrus), and node B consumesreceiptin itsparents. Use theReceiptEnvelopeplaceholder from step 1. Inline comments mark LIVE today (receipt.blobId,receipt.jobId,receipt.artifactDigest,receipt.certifiedfromWalrusStorageReceipt, core/types.ts:654) vs AWAITING the Movereceiptmodule (receipt.id= Sui object id,parents: vector<ID>lineage; roadmap §2). README doubles as the “first Nexus call” doc and points to the on-chain attribution-receipt issue.Per-template READMEs + CI. Each template README: prereqs, env (link
.env.example), exact run command (bun run start/bun src/index.ts), and both install paths (clone-based write vsmcp-remoteread). Append a CI step to.github/workflows/bun-check.yml(bun run typecheck:examples) — note thatbun install --frozen-lockfilealready hoists@modelcontextprotocol/sdk/zod, so the examples typecheck without being workspaces. Keep.env.exampleonly (no secrets); addexamples/**/.env*(except.env.example) to.gitignore.New / changed files
examples/README.md(index + env matrix + combined-config section)examples/tsconfig.jsonexamples/_shared/contract.ts,examples/_shared/mcpClient.tsexamples/research-agent/{package.json,tsconfig.json,.env.example,README.md,src/index.ts}examples/rag-chat/{package.json,tsconfig.json,.env.example,README.md,src/index.ts}examples/monitor-agent/{package.json,tsconfig.json,.env.example,README.md,src/index.ts}examples/mcpServers.example.jsonexamples/nexus-dag/{README.md,dag.example.yaml,dag.example.ts,src/receipt-flow.ts}package.json(addtypecheck:examples, extendcheck) — changed.github/workflows/bun-check.yml(add typecheck:examples step) — changed.gitignore(ignoreexamples/**/.envexcept.env.example) — changedpackages/mcp/src/index.ts(optional step 2: registerbuild_web_context) — changedREADME.md(linkexamples/from DEV Onboarding) — changedTest plan
bun run typecheck:examplespasses locally and inbun-check.yml; satisfies AC6’s “documented bun command can typecheck the templates.”extract_walrus_context) or a web URL (via step-2 tool), assert a non-empty recall answer and thatremember_site_snapshotreturns a MemWaljobId/status. RequiresMEMWAL_*.CONTEXTMEM_READ_TOKEN); assert per-turn output includes ≥1 citedsourceLabel/sourceTargetfromget_context_bundle; assert that omitting the token on the private namespace yields the 401/NAMESPACE_TOKENpath (proves the header gotcha is real).TATUM_API_KEY, assert a certifiedWalrusStorageReceiptwith a realblobId(round-trip proof the delta was stored).mcpServers.example.jsonin Claude Desktop/Cursor; confirm both servers connect and a ContextMEM read tool returns data.receipt-flow.tsthat a mock receipt’s LIVE fields are populated andid/parentsare explicitly marked TODO; no on-chain tx expected this milestone.Risks & gotchas
Authorization: Bearer <read-token>(worker.ts:779). Test the negative case.@contextmem/mcpisprivate:true; do not writenpx @contextmem/mcpexamples until the publish issue lands. Use clone-based write +mcp-remoteread.receipt.id/parentsdon’t exist — only onWalrusStorageReceiptareblobId/jobId/artifactDigest; the nexus-dag must not pretend otherwise (AC5: “mark clearly which parts are live vs awaiting the Move receipt module”).remember_site_snapshot/upload_proof_to_walrusneed a run dir; web extract has no run-producing MCP tool today (only Walrus). Step 2 fixes this cleanly; otherwise document the CLI fallback.upload_proof_to_walrusrequires a mainnetTATUM_API_KEY(README.md:123); recall/remember go through the MemWal relayer. Keep this explicit so users don’t mix testnet creds.@contextmem/mcp/hostedtypes via the path alias for in-repo TS; a raw fork won’t resolve that. README must tell forkers to copy_shared/contract.tsor install the published package once available.enableJsonResponse:true+corsOptions.origin:"*"(worker.ts:789-792); ensure the client setsAccept: application/json, text/event-stream(the Worker’sacceptsEventStream, worker.ts:812-815) or it serves the HTML landing page instead of MCP.rememberWithRetry, memwal/index.ts:254); templates should tolerate/retry rather than hard-fail.Acceptance-criteria mapping
examples/research-agent/extract→remember→recall, runnable w/ env → Step 3 (+ enabling Step 2).examples/rag-chat/recall-grounded chat citing sources viaincludeSources→ Step 4 (get_context_bundle/search_context).examples/monitor-agent/re-extract → diff → remember delta, prints “what changed” → Step 5 (diff_site_snapshots+upload_proof_to_walruswhatChanged).mcpServersJSON for Claude/Cursor incl. read-token header → Step 6.examples/nexus-dag/scaffold showingreceipt.id→parents, live vs awaiting → Step 7.examples/README.mdindex + CI/bun typecheck → Steps 1, 3-8.Effort
M — ~4 person-days (≈0.5d scaffold/tooling+CI, 0.5d optional
build_web_contexttool, ~0.75d each for research/rag/monitor incl. README + manual run, 0.5d combined config, 0.5d nexus-dag scaffold + docs). Mostly thin MCP-client glue and docs, no new infra.Implementation plan generated for execution (planning phase). Part of the roadmap (#4).