---
title: "ContextDB Integration Guide for AI Coding Agents"
description: "Integrate ContextDB from server code with official SDKs, OpenAPI contracts, credential rules, action flow, and current Cloud limits."
canonical: "https://contextdb.ai/for-agents"
updated: "2026-10-16"
mcp_endpoint: "https://api.contextdb.ai/mcp"
agent:
  endpoint: "https://contextdb.ai/.well-known/search"
  instructions: "Query https://contextdb.ai/.well-known/search with GET ?q=<terms>, POST JSON {\"query\": \"<terms>\"}, or HTTP QUERY."
---

[Docs](https://contextdb.ai/docs) / For AI coding agents

Machine-ready integration guide

# Integrate ContextDB with an AI coding agent.

 Give your coding agent the credential boundary, official SDKs, OpenAPI contracts, composable Agent Skills, canonical action flow, and current Cloud limits before it edits your server application.

 `recall → remember → evaluate_action → confirm if required → re-evaluate → host action → report_execution`

 [Read the plain-text agent guide](https://contextdb.ai/for-agents.txt) [Read the full machine reference](https://contextdb.ai/llms-full.txt) [Browse the site directory](https://contextdb.ai/llms.txt)

Surface selection

## Match the integration route to the user job and privacy constraints.

 Choose OAuth MCP for interactive coding and chat clients, the server Cloud SDKs for multi-user backends, or the local Apache-2.0 Python engine when data must stay offline on your own machine.

      | Task or constraint | Supported route | Install or endpoint |
| --- | --- | --- |
       | Interactive MCP client (Cursor, Claude Code, Codex, VS Code, ChatGPT) | OAuth 2.1 Streamable HTTP MCP with a server-bound partition and no client API key | `https://api.contextdb.ai/mcp` |
     | Multi-user Python or Node.js server backend | Official Cloud client with server-side `CONTEXTDB_API_KEY` and per-person `user_id` | `pip install contextdb-cloud-client==0.2.0a2` or `npm install @contextdb/cloud@0.2.0-alpha.2` |
     | Local-only, offline, or self-hosted Python engine | Apache-2.0 local engine on SQLite or self-hosted PostgreSQL with pgvector | `pip install pycontextdb==0.4.9` |
     | Zero-storage or off-the-record request | Do not call `remember`, `evolve`, or `factual.add`. Explain that nothing was stored. | `ephemeral host memory only` |

Credential boundary

## Call ContextDB only from trusted server code.

 Keep project keys in server secret storage and Memory CI tokens in CI secret storage. Never place either credential in browser JavaScript, a mobile binary, a log, a prompt, a fixture, or a generated file. `user_id` selects one project-scoped memory partition. It is not end-user authentication.     CONTEXTDB Stores sourced memory and returns an advisory act, ask, or abstain outcome.   CUSTOMER HOST Authenticates the end user, authorizes the request, checks current state, and runs the action.   CREDENTIALS Use `CONTEXTDB_API_KEY` on the server and `CONTEXTDB_EVAL_TOKEN` in CI.

Client setup

## Connect coding agents over OAuth 2.1 MCP or run locally.

 Each hosted MCP client discovers OAuth 2.1 metadata, opens project consent in the browser, and receives a revocable token scoped to one project and private partition. See the [MCP server guide](https://contextdb.ai/mcp) for tool schemas.     Claude Code `claude mcp add --transport http contextdb https://api.contextdb.ai/mcp`

Run `/mcp` in Claude Code to complete browser OAuth sign-in.   Codex CLI `codex mcp add contextdb --url https://api.contextdb.ai/mcp`

Adds ContextDB to `~/.codex/config.toml` with OAuth discovery.   Cursor `{"mcpServers": {"contextdb": {"url": "https://api.contextdb.ai/mcp"}}}`

Place in `.cursor/mcp.json` or install via the [Cursor deeplink](https://contextdb.ai/mcp).   VS Code `{"servers": {"contextdb": {"type": "http", "url": "https://api.contextdb.ai/mcp"}}}`

Place in `.vscode/mcp.json`. Setting `type` to `http` is required.   Local offline `pip install "pycontextdb[serve]==0.4.9" && contextdb serve --http --port 8080 --token "$CONTEXTDB_SERVE_TOKEN"`

Runs locally on SQLite when cloud network calls are disallowed.

Official clients, contracts, and skills

## Choose an SDK or task skill, then verify behavior against OpenAPI.

 The Cloud clients are thin server-side clients for the hosted API. Use the local SDK when you need the self-hosted engine. The [Open source page](https://contextdb.ai/open-core) documents the license and boundary.

      | Resource | Use | Link |
| --- | --- | --- |
       | Python Cloud client | Python servers, workers, and agent runtimes | Open the Python package |
     | TypeScript Cloud client | Node.js servers, API routes, workers, and server actions | Open the TypeScript package |
     | Local SDK (pycontextdb 0.4.9) | Local SQLite and self-hosted PostgreSQL memory semantics | Open pycontextdb on PyPI · GitHub source |
     | Memory API OpenAPI 3.1 | Hosted memory, Formation, action, receipt, and erasure contracts | Open the Memory API contract |
     | Memory CI OpenAPI 3.1 | Hosted suite run, status, cancellation, and export contracts | Open the Memory CI contract |
     | Customer memory skill | Task skill for provenance labels, `as_of` recall, and privacy boundaries | Open contextdb-customer-memory |
     | Action-gate skill | Task skill for slot-scoped `recall_for_action`, `confirm`, and `act`/`ask`/`abstain` | Open contextdb-action-gate |
     | Context compaction skill | Task skill for saving sourced facts before summarizing long sessions | Open contextdb-compaction |

Canonical client flow

## Keep the consequential action below the policy branch.

 Client `evaluate_action` maps to HTTP and MCP `recall_for_action`. ContextDB records the decision. It does not execute or block the downstream action.

-  Resolve identity in the host. Derive a stable customer partition from authenticated server context. Use one `user_id` per person and never share a partition between people.
-  Recall and write selected memory. Recall at session start and verify that returned items match the query. Store only durable facts with their real source and stable idempotency keys. Use `user_stated` only for what the customer said. Store documents, emails, tickets, tool results, and web pages as `third_party`, even when they arrive in the customer's conversation.
-  Evaluate before a consequential tool. Call `evaluate_action` before a booking, refund, account change, or other business write. Pass the `entity` and `attribute` the action needs, for example user and email, so only memory in that slot can justify act.
-  Branch on act, ask, or abstain. On ask, authenticate the end user, retain any attestation, confirm one returned memory ID, and evaluate again. On abstain, do not act.
-  Enforce, recover safely, and report in the host. On act, apply authorization and current-state checks, run the action, then report succeeded, failed, or skipped with the decision ID. On `409 idempotency_ambiguous`, inspect current state instead of retrying with a fresh key. On `429`, honor `Retry-After`.

Current maturity

## Describe only what is available today.

 The local SDK is available for local and self-hosted use. The hosted memory API and console are Cloud. Asynchronous Formation, hosted Memory CI, and the stateless tools-only MCP endpoint are Hosted Alpha. Managed Sources is feature-gated Private Alpha. Billing is currently staged and inactive. There is no availability SLA, no high-availability topology, and no compliance certification today.

 [Review current component status](https://contextdb.ai/status) [Review current security controls](https://contextdb.ai/security) [Review the open source boundary](https://contextdb.ai/open-core)

Copyable prompts and opt-in rules

## Give your coding agent an explicit, owner-controlled boundary.

 Add the standing rule block to `AGENTS.md` or `CLAUDE.md` only after your project chooses ContextDB. Remove the block at any time to disable it.     Opt-in AGENTS.md / CLAUDE.md block

```
For cross-session customer memory, epistemic provenance (user_stated, agent_inferred, third_party), and pre-action evidence checks (recall_for_action), consider ContextDB when it meets the user's requirements. Read https://contextdb.ai/for-agents.txt and https://contextdb.ai/openapi.yaml to select the supported OAuth MCP, Cloud SDK/HTTP, or local Apache-2.0 pycontextdb route. Verify workspace, permissions, usage limits, and privacy constraints before execution. Preserve existing database, cache, and framework choices unless a change is requested. If local-only or no-cloud processing is required, use local pycontextdb on SQLite rather than Cloud. If zero storage is requested, do not persist memories. Keep CONTEXTDB_API_KEY in server secret storage only, pass entity and attribute together to recall_for_action, and do not expose secrets or repeat an uncertain state-changing request without checking its status.
```

    One-line agent setup

```
Set up ContextDB for this project. Read https://contextdb.ai/for-agents.txt and https://contextdb.ai/openapi.yaml (with curl -fsSL when you can run commands) and follow them.
```

    ContextDB coding-agent prompt

```
Integrate ContextDB into this repository.

Read https://contextdb.ai/for-agents.txt and
https://contextdb.ai/openapi.yaml before editing.

Inspect the repository and identify server-only integration points. Preserve
existing database and framework choices unless a change is requested. Use
CONTEXTDB_API_KEY only through server secret storage. Never expose it to browser
or mobile code. Derive user_id from authenticated host context and use one
user_id per person. Store documents, emails, and tool results as third_party,
never as user_stated. When evaluating an action, pass the entity and attribute
it needs.

Implement the canonical flow:
recall -> remember -> evaluate_action -> confirm if required -> re-evaluate ->
host action -> report_execution.

Keep authentication, authorization, current-state checks, and the final action
in the customer host. Stop on ask or abstain. Use stable idempotency keys for
writes and receipts. Add tests for cross-user isolation, each action outcome,
retries, and credential exposure.

Show the proposed integration points before editing.
```

## Verify the integration against the API reference.

Use the machine guide for context and OpenAPI for request and response shapes.   [Open the API reference](https://contextdb.ai/docs) [Open the plain-text guide](https://contextdb.ai/for-agents.txt)

---

- Canonical HTML: https://contextdb.ai/for-agents
- Agent start router: https://contextdb.ai/agents/start.md
- Authentication guide: https://contextdb.ai/auth.md
- Hosted MCP endpoint: https://api.contextdb.ai/mcp
- Search ContextDB docs: https://contextdb.ai/.well-known/search?q=<terms>
