Developer guide
Everything you can build on Contextual, one chapter at a time: the call, and what changes for the person, before and after.
First edition · November 2026 · Srini Rentala Venkata, trading as rentala-studiosconst cx = new Contextual({ baseUrl, token });
const now = await cx.now();
// what needs the person, with its proofChapter 1: Make an app and its key
Everything starts with an app at app.contextual.exchange: a name, a sample mailbox, and a key that does only what you tick.
Sign in to the developer service, press New app, name it and choose Sample mail: made-up mail for Robin Vale, who is nobody real. Tick what the key may do and for how long, from one day to a year.
The key shows once. Keep it in your own secret store, never in code. The SDK takes it, with the address, and every call after that is checked against the ticks.
import { Contextual, ContextualError } from "@contextual/sdk";
const cx = new Contextual({
baseUrl: "https://email.contextual.exchange",
token: process.env.CONTEXTUAL_KEY,
});
try { await cx.now(); }
catch (e) { if (e instanceof ContextualError) console.log(e.needs); }Chapter 2: Read what needs the person
Now is what a person owes: replies, approvals and dates, each with who asked, by when, and the words that prove it.
Contextual reads each email for what it asks. Your app reads the result, not the inbox: a short list, each item with its conversation, so you can build a reminder, a tracker or a daily note.
Open the conversation behind any item, with its topics pulled apart, and write reply drafts. A draft is only ever a draft: the person sends it, or doesn't.
const now = await cx.now();
for (const e of now.needsYou) console.log(e.title, e.due ?? "");
const thread = await cx.conversation(now.needsYou[0].conversationId);
const drafts = await cx.drafts("Robin"); // drafts only: nothing is sentChapter 3: Folders and line maps
Contextual makes folders from the people, domains and topics that recur. Every folder has a line map: one line through time.
List the folders, then ask for a folder's line: a notch for each email, sent on one side and received on the other, filtered by person, topic or mark, a page at a time.
Exchange lines have a line map too, with each file's way of sharing, each opening and each note.
const [claim] = await cx.folders();
const line = await cx.folderLine(claim.id, { person: "rachel@northgate.example", limit: 50 });
// An Exchange line's map, too
const map = await cx.exchange.lineMap(lineId);Chapter 4: Search with the magic words
One call searches everything the person allowed, with the same magic words as the app.
in:, from:, to:, has:attachment, kind:, before:, after: and is:unread narrow it at once. Results come in groups, each with its count; ask a question and the answer comes first, with the email it came from.
Pass a folder to keep the search to it, the way Focus does on screen.
const hits = await cx.search("from:rachel has:attachment offer");
// Keep to one folder
const inClaim = await cx.search("deadline", claimFolderId);Chapter 5: The Record: asked, offered, agreed
The Record keeps what was asked, offered, agreed and due, each with the quote and the message that prove it.
Read it to build a tracker, a report or a reminder. Each entry carries its proof: the words, who said them and when.
Read the notes a person marked on their mail, confirmed or disputed. Only the person adds or changes them, from Contextual itself.
const { entries } = await cx.record();
// Only what you confirmed counts: an agreement Contextual read stays "suggested" until you say so
const agreed = entries.filter((e) => e.kind === "agreed" && e.state === "confirmed");
for (const e of agreed) console.log(e.title, e.proof[0]?.quote);
const notes = await cx.pills(messageId);We are prepared to offer £42,000 in full and final settlement. Please reply by 27 November.
Chapter 6: Bring mail in, and when
Choose what comes in from a mailbox, see how much first, then start it now, at a time, or only at night.
Count first: labels, dates, senders and size give an estimate before anything moves. Set the filter, then start the job, pause it or resume it. What has come in is filed and searchable straight away.
Connecting a mailbox and unsubscribing stay the person's own: a key can't do them.
const [gmail] = await cx.ways();
const size = await cx.countWay(gmail.id, { after: "2024-01-01", labels: ["Claims"] });
await cx.setWayFilter(gmail.id, { after: "2024-01-01", labels: ["Claims"] });
await cx.wayJob(gmail.id, { action: "start", nightly: { from: "22:00", to: "06:00", offset: 0 } });Chapter 7: Exchange lines, both ways
A line is a private folder between a firm and one client: messages, asks, files and notes, each step with a sealed receipt.
Open a line, invite the client with a one-time link (they need only a first name), ask for a document or send one, leave notes, and read the receipts for every step.
Each file keeps the way its sender chose: view once, view, keep a copy, or share with one person. A firm's own screens open once it has Enterprise.
const line = await cx.exchange.createLine({ subject: "14 Elmstead Avenue" });
const invite = await cx.exchange.invite({ lineId: line.id, name: "Sam", days: 7 });
await cx.exchange.ask(line.id, "Proof of funds");
await cx.exchange.note(line.id, "Viewing on Saturday at 11:00");
const receipts = await cx.exchange.receipts(line.id);Chapter 8: Files: every place a person keeps things
Search a person's computers, Google Drive and email attachments at once, see every version, and find what is kept twice.
The same magic words work across every place. Duplicates come back with where each copy lives and how much room the extras take.
Share a file on an Exchange line in the way the person picks. Pairing a computer needs the person: they check the same four words on both screens.
const found = await cx.filesApp.search("kind:pdf quote kitchen");
const twice = await cx.filesApp.duplicates();
const file = found.groups[0].hits[0].item;
await cx.filesApp.share(file.id, { lineId, how: "view-once" });Chapter 9: Storage and export
See where a person's mail is kept and export kept mail in a file sealed with a one-time code.
A key reads where the mail lives and how much there is, and makes a sealed export. LiveLink exports contain list details and snippets, not full Gmail messages or attachments. Import restores mail and folder rules. Matching manual filing for made folders and kept personal notes without replies need Organise my mail on; conflicts are skipped and other pills and notes do not move. The second copy and import stay the person's own.
const where = await cx.storage();
const sealed = await cx.exportEverything(); // sealed; keep sealed.code apart from the fileChapter 10: The API, the one the app uses
Contextual's own screens use the same HTTP and JSON API as your app. The whole contract is one OpenAPI file.
Send the key as a bearer token. A refusal names the permission it needed, so your app can ask the person for it.
curl https://email.contextual.exchange/v1/now \
-H "Authorization: Bearer $CONTEXTUAL_KEY"
# The whole contract: GET /v1/openapi.json{ "needsYou": [ { "title": "Sign the lease renewal",
"who": "Maya Osei", "due": "2026-11-20" } ],
"waiting": [ … ] }Chapter 11: An MCP server for AI agents
Give your own AI assistant Contextual's tools: what needs me, what was agreed, find conversations, file versions, drafts, due dates and my permissions.
Add the server to the assistant's settings with the key in its environment. Each tool needs its permission, every use leaves a receipt, and drafts are never sent.
{ "mcpServers": { "contextual": { "command": "contextual-mcp",
"args": ["--url", "https://app.contextual.exchange", "--read-only"] } } }
# Tools for every part: what_needs_me, search_mail, my_lines, open_line,
# files_search, ways_in, storage_info, my_permissions, …Chapter 12: The command line
Import mail files, list what needs you, export a case, or call the API, from a terminal.
Running a command is the permission to read the files you hand it, and the receipt says so. Over the API, the key comes from the environment and is never an argument.
contextual import claim.mbox --me robin@vale-home.example --store mail.db
contextual now --store mail.db --json
contextual export --store mail.db --out case.zip --name "Claim 4471"
contextual api lines # over the API, with CONTEXTUAL_KEYChapter 13: Signed hooks
Get told when something happens. Each delivery is signed with your hook's secret and the time.
Check the signature and that it is fresh, then act. Deliveries are tried again for up to a day, and only to apps allowed to know.
Two events are coming: new mail filed into a folder, and a file's new version.
import { createHmac, timingSafeEqual } from "node:crypto";
// x-contextual-signature: t=<unix time>,v1=<HMAC-SHA256(secret, t + "." + body)>
const { t, v1 } = Object.fromEntries(header.split(",").map((p) => p.split("=")));
const want = createHmac("sha256", secret).update(`${t}.${body}`).digest();
const ok = timingSafeEqual(Buffer.from(v1, "hex"), want) && Date.now() / 1000 - Number(t) < 300;Chapter 14: Extensions: connectors, readers, actions
An extension says what it asks for and why; the person grants it, and can take it back. Running an extension's own code (connectors, readers, actions) is coming.
The manifest says up front what it asks for, why and for how long. Its code is named by fingerprint in the manifest; an update never widens what it may do.
{ "id": "com.example.receipts", "name": "Tidy Receipts", "version": "1.0.0",
"publisher": "Example Ltd", "summary": "Files your receipts by shop.",
"kinds": ["reader"],
"asks": [{ "capability": "mail.read", "why": "To find your receipts" }],
"maxDays": 30,
"code": { "url": "https://example.com/receipts-1.0.0.js", "sha256": "<its SHA-256>" } }Chapter 15: Consent: ticks, time and taking back
An app does only what a person ticks, for a time they choose, until they take it back.
Anything not ticked is refused by name. When the time is up, the key stops. A person can revoke it at any moment, and your next call is refused.
try { await cx.drafts("Robin"); }
catch (e) { if (e instanceof ContextualError) console.log(e.needs); } // "Write reply drafts"Chapter 16: Receipts and usage
Every grant, use, refusal and revoke is a receipt the person can read, and your app can read them too.
The developer service shows each app's calls and errors for the last day and month: status, method and route only, never what the mail says.
Usage is yours, not the app's: read it signed in to the developer service as yourself. The app's key can't.
const receipts = await cx.receipts(); // with the app's key
// Signed in to the developer service as yourself, not with the app's key:
const usage = await me.developerAppUsage(appId);Start building
- Free for any developer to build
- A sample mailbox from the first minute
- The same calls on a real account, only as far as the person ticks