Skip to content

MCP Server

Terminal window
git clone https://github.com/agentstatelabs/AgentStateGraph.git
cd AgentStateGraph
cargo build --release -p agentstategraph-mcp
cargo run --release -p agentstategraph-mcp
# Creates ./agentstategraph.db, listens on stdio

Add to ~/.claude.json or your project’s .mcp.json:

{
"mcpServers": {
"agentstategraph": {
"command": "/path/to/AgentStateGraph/target/release/agentstategraph-mcp"
}
}
}

Or run from source:

{
"mcpServers": {
"agentstategraph": {
"command": "cargo",
"args": ["run", "--release", "-p", "agentstategraph-mcp", "--manifest-path", "/path/to/AgentStateGraph/Cargo.toml"]
}
}
}

Restart Claude Code. The 77 AgentStateGraph tools appear automatically.

The same binary also supports HTTP mode, a REST API:

Terminal window
cargo run --release -p agentstategraph-mcp -- --http --port 3001
Terminal window
curl http://localhost:3001/api/health
curl http://localhost:3001/api/stats/main
curl http://localhost:3001/api/state/main?path=/cluster/name
curl "http://localhost:3001/api/blame/main?path=/cluster/name"
curl "http://localhost:3001/api/state/main/search?query=mesh"

The server logs to stderr. In HTTP mode it logs each request at info. Fields use OpenTelemetry’s names:

  • http.request.method;
  • url.path (no query);
  • http.route, the route template;
  • http.response.status_code;
  • http.server.request.duration (seconds);
  • asg.api_key.id, the API key’s id, never the key itself.

Set ASG_LOG to change the level (debug, or a filter like agentstategraph_mcp=debug). ASG_LOG_FORMAT chooses the form: auto (the default: text on a terminal, one flat JSON object per line otherwise, as in a container), text, json or ecs (Elastic Common Schema). A JSON line:

{"asg.api_key.id":"key_3f9c2a71d04e8b65","http.request.method":"GET","http.response.status_code":200,"http.route":"/api/state/{ref_name}","http.server.request.duration":0.000855667,"level":"INFO","message":"request","network.protocol.version":"1.1","server.address":"localhost","server.port":3001,"span_id":"69a6763a47ef0951","target":"oxtel_tower::server","timestamp":"2026-10-08T15:57:08.711714Z","trace_id":"1b2e39eb15704924f95003629fbcd488","url.path":"/api/state/main","url.scheme":"http"}

/api/health reports that the process is serving (liveness). /api/ready also checks that the store answers, and returns 503 if it doesn’t (readiness). agentstategraph-mcp healthcheck checks /api/ready from the same machine, for container health checks.

--metrics serves Prometheus metrics at /metrics, named as OpenTelemetry’s HTTP metrics are for Prometheus:

  • http_server_request_duration_seconds is a histogram by http_request_method, http_route (the template, so ref names never become labels), http_response_status_code and, for server errors, error_type. Its _count is the request count.
  • http_server_active_requests counts requests in progress.
  • target_info carries the version.

With --auth, scraping it needs an admin key.

With the otlp feature built in, set OTEL_EXPORTER_OTLP_ENDPOINT to send traces, metrics and these logs to an OpenTelemetry Collector or any OTLP backend. The Observability guide covers turning it on and lists every metric; docs/OBSERVABILITY.md lists every name.

An error response is JSON with a message, a stable code, and the id of the request’s trace:

{"error": "branch already exists: main", "code": "branch_already_exists", "trace_id": "4bf92f3577b34da6a3ce929d0e0e4736"}

Branch on the code; the message is for people and may change. Quote the trace id, or the x-request-id header every response carries, when reporting a problem: the server’s log lines carry both. A request may send its own x-request-id (up to 128 visible ASCII characters), and the response echoes it; otherwise the server makes one. The status follows from the code:

StatusCodes
404branch_not_found, ref_not_found, commit_not_found, namespace_not_found, object_not_found, path_not_found, speculation_not_found, key_not_found
409write_conflict, merge_conflict, merge_would_delete, branch_already_exists, namespace_already_exists, ref_already_exists, epoch_sealed, session_ended
400invalid_request, invalid_operation, invalid_json, ambiguous_commit_prefix, type_mismatch, not_a_container, index_out_of_bounds
403reserved_path, commit_ref_not_allowed, key_bound_to_namespace, cross_namespace_denied, taint_blocked
429too_many_speculations
503not_initialized
500storage_error, serialization_error, integrity_violation, key_store_failed, internal

A write_conflict means another writer moved the branch first; it’s safe to retry. MCP tools report the same codes at the start of their error text, Error [write_conflict]: …, and mark the result as an error (isError). So does agentstategraph_commit_spec when policy refuses a promotion; its text is then the Decision JSON.

The limits, authentication and host check below answer before a request reaches the API, in the same form. Their codes are the reasons the server counts them by, in asg.http.rejections:

StatusCodeWhy
401unauthenticatedno API key, or one that isn’t valid
403forbiddenthe key can’t use this endpoint, such as a non-admin key on an admin route
403host_refusedthe request named a host this server doesn’t answer to
413body_too_largethe body is over the limit
429rate_limitedover the rate limit; Retry-After says when to try again
503over_capacitythe server is handling its limit of requests; Retry-After: 1
503timed_outthe request ran past the timeout; a write may still have completed

Each request body may be up to 4 MiB (--max-body-bytes); a larger one gets 413. A request still running after 30 seconds (--request-timeout-secs, 0 for none) gets 503; a write may still complete after that, so check before retrying it. At most 256 requests are handled at once (--max-concurrent-requests); more get 503 with Retry-After: 1 rather than queueing. /api/health is never turned away.

The rate limit (--rate-limit-rpm, default 600 a minute) applies per API key when --auth is on, and per client IP otherwise. Requests without a valid key count against their IP. Every setting has an environment variable too; see --help.

Browser pages served from localhost (any port) can call the API. To let a page from another origin call it, pass --cors-origin https://app.example.com (repeatable, or ASG_CORS_ORIGINS as a comma-separated list). --cors-origin '*' allows any origin; only do that with --auth.

Bound to loopback, as it is by default, the server only answers requests addressed to localhost, 127.0.0.1 or [::1]. That stops another website from reaching it through DNS rebinding, where the site points a domain it controls at your machine. Behind a reverse proxy on the same machine that forwards its own host name, allow that name with --allowed-host asg.example.com (or ASG_ALLOWED_HOSTS). Bound to another address, the server answers any host name unless you list some.

Full endpoint list:

MethodEndpointDescription
GET/api/healthLiveness: the process is serving
GET/api/readyReadiness: the store answers (503 if not)
GET/api/stats/:refSummary statistics
GET/api/state/:ref?path=/xRead state value
GET/api/state/:ref/pathsList all paths
GET/api/state/:ref/search?query=xFull-text search values
POST/api/state/:ref/setWrite value with intent
POST/api/state/:ref/deleteDelete value with intent
GET/api/log/:refCommit log
GET/api/blame/:ref?path=/xBlame a path
GET/api/diff?ref_a=x&ref_b=yDiff two refs
POST/api/query/:refQuery with composable filters
GET/api/graph/:refCommit DAG
GET/api/branchesList branches
POST/api/branchesCreate branch
POST/api/mergeMerge branches
GET/api/epochsList epochs
POST/api/epochsCreate epoch
POST/api/epochs/sealSeal epoch
GET/api/intents/:refIntent decomposition tree

Any MCP client that supports stdio transport works. Point it at the agentstategraph-mcp binary.

Terminal window
agentstategraph-mcp [OPTIONS]
OPTIONS:
-s, --storage <TYPE> Storage backend: sqlite (default), memory, or postgres
-p, --path <PATH> SQLite database path (default: ./agentstategraph.db)
--database-url <URL>
Postgres connection URL (required for --storage postgres)
--tenant <ID> Tenant this server serves (default: "default")
--http Run as HTTP REST API instead of MCP stdio
--port <PORT> HTTP port (default: 3001, requires --http)
--policy-fail-safe <deny|allow>
When no policy matches: deny (default) or allow
-h, --help Print help with full endpoint list

Each commit records the trace it was made in, shown as trace_id and span_id in log and blame; set ASG_TRACE_LINKS=off to stop recording them. Set ASG_SQL_SPANS=on to trace each SQL statement as a span. Set ASG_COMMIT_EVENTS=on to log each commit as an asg.commit event, for a log backend or SIEM; it never carries values. See Observability.

A selection of the most-used tools is shown below. For the full set of all 77 tools — including namespaces, sessions, maintenance (GC and history), plans & tasks, policy, taint, and reminders — see the MCP Tools reference.

ToolDescription
agentstategraph_getRead a value at any branch/path. Use / for entire state.
agentstategraph_setWrite a value with intent metadata (category, description, reasoning, confidence).
agentstategraph_deleteRemove a value, creating a commit with intent.
ToolDescription
agentstategraph_branchCreate a branch from any ref. Supports namespaced names.
agentstategraph_list_branchesList all branches, optionally filtered by namespace prefix.
agentstategraph_mergeSchema-aware three-way merge. Returns conflicts if auto-resolution fails.
agentstategraph_diffStructured typed diff between two refs (not text diffs).
ToolDescription
agentstategraph_speculateCreate a lightweight O(1) speculation from a ref.
agentstategraph_spec_modifyApply set/delete operations within a speculation.
agentstategraph_compareCompare multiple speculations side-by-side.
agentstategraph_commit_specPromote a speculation to a real commit on its base branch, if policy allows it.
agentstategraph_discardDiscard a speculation. All changes freed immediately.
ToolDescription
agentstategraph_logCommit history with full intent, reasoning, and metadata.
agentstategraph_queryComposable filters: agent, category, tags, reasoning text, confidence range.
agentstategraph_blameFind which commit last modified a path and why.
ToolDescription
agentstategraph_create_epochCreate an epoch to group related work.
agentstategraph_seal_epochSeal an epoch (immutable, tamper-evident). Cannot be undone.
agentstategraph_list_epochsList all epochs with status, dates, and commit counts.
ToolDescription
agentstategraph_sessionsList active agent sessions with parent-child relationships.
ToolDescription
agentstategraph_list_pathsList all leaf paths in the state tree under a prefix.
agentstategraph_get_treeGet entire subtree as nested JSON (batch read).
agentstategraph_searchFull-text search across state values and key names.
agentstategraph_statsSummary statistics: commits, branches, paths, epochs, agents.
agentstategraph_commit_graphCommit DAG with parents, agents, categories for visualization.
agentstategraph_intent_treeIntent decomposition hierarchy across agents.
ToolDescription
agentstategraph_historyProject-history metrics: velocity, intent mix, authorship, milestones.
agentstategraph_gc_dry_runReport what garbage collection would reclaim, changing nothing.
agentstategraph_gc_sweepSweep under a retention policy; deletes only with mutate: true.
agentstategraph_gc_vacuumCompact the store after a sweep.
You: Store the cluster config under /cluster
Agent: [calls agentstategraph_set with path="/cluster/name", value="prod", ...]
You: Try two network approaches and compare them
Agent: [calls agentstategraph_speculate twice, agentstategraph_spec_modify on each,
agentstategraph_compare to diff them, agentstategraph_commit_spec on winner]
You: Who changed the network config and why?
Agent: [calls agentstategraph_blame with path="/cluster/network"]

See the full MCP Tools Reference for parameters and example payloads.