---
name: diurna-law-agent
description: Search U.S. federal, state, and local law with Diurna, cite official sources, and monitor code changes through the REST API and MCP.
---

# Diurna agent onboarding

Diurna publishes statutes, bills, ordinances, regulations, and related records with `citation` and `source_url` on every hit. Diurna is not legal advice. Quote the official publisher linked on each record.

## Get access

1. **Public catalog (no key)**  
   Call `GET https://trydiurna.com/api/v1/search` or MCP tools such as `search`, `get_statute`, and `list_jurisdictions` without authentication.

2. **Account tools (API key)**  
   Sign in at https://trydiurna.com, open **Settings → API keys**, and create a named key. The secret is shown once. Send it as header `X-Api-Key` on REST and MCP requests. Do not put the key in URLs, prompts, or logs.

3. **MCP in an assistant**  
   Copy-paste install configs for Cursor, Claude Desktop, Claude Code, VS Code, ChatGPT, Codex, OpenCode, and Grok Bot: https://trydiurna.com/developers/install  
   Hosted MCP URL: `POST https://trydiurna.com/api/mcp`  
   Browser sign-in over OAuth will use `https://trydiurna.com/api/mcp/oauth` when that route is deployed. Until then, use an API key or public tools only.

4. **Private matter reads**  
   Tools `list_client_matters`, `get_client_matter`, and `get_client_reviews` require a verified account session. API keys are rejected. Use the signed-in web app; do not copy session cookies into agent configs.

## REST quick reference

| Task | Method and path |
| --- | --- |
| Search | `GET /api/v1/search?q=...&jurisdiction=WA` |
| Short search | `GET /api/v1/search?q=...&format=highlights` or `format=answer` |
| Section by id | `GET /api/v1/sections/{id}` |
| Short section read | `GET /api/v1/sections/{id}?q=...&format=highlights` |
| Change feed | `GET /api/v1/changes?since=...` (API key) |
| Webhooks | `POST /api/v1/webhooks` (Team plan, API key) |

OpenAPI: `GET /api/v1/openapi.json`  
Human docs: https://trydiurna.com/developers/api

Search and section reads accept `format`, `fields`, and `max_tokens`. Omit all three for the full record.

- `format=highlights` returns the most relevant official excerpts. Each excerpt includes `citation` and `source_url`.
- `format=answer` returns a short answer quoted from those excerpts, with the same citations.
- `fields` keeps the named properties. `citation` and `source_url` remain on every record that has them.
- `max_tokens` bounds the JSON body. The count is about 4 characters per token. Citations are kept.

Section, bill, document, and CFR reads take `q` as the question used to choose excerpts. Search uses `q` on REST and `query` on MCP for both retrieval and excerpts.

## MCP quick reference

1. `initialize` with `protocolVersion` `2025-06-18` (or `2025-03-26`).
2. Send `notifications/initialized`.
3. `tools/list` to see tools enabled for your credential.
4. `tools/call` with the tool name and arguments from the schema.

Example public call:

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "search",
    "arguments": { "query": "landlord habitability", "jurisdiction": "WA" }
  }
}
```

Account example: same shape with header `X-Api-Key` and tools such as `list_changes`.

## Pagination and errors

- Catalog pages use `has_more` and `next_cursor`. Pass the previous `next_cursor` as `since` or `cursor` per tool schema.
- Honor HTTP 429 `Retry-After`. Do not retry forbidden or invalid-argument errors unchanged.
- Keep `X-Request-Id` for support without logging private payloads.

## Change webhooks for workflows

Team accounts can register HTTPS endpoints that receive `changes.recorded` events when new law is recorded. See https://trydiurna.com/developers/automation for Zapier, n8n, and signature verification.

## LangChain

Python tools live in `integrations/langchain` in the uslaws repository. Install locally and pass `DIURNA_API_KEY` for authenticated calls.

## Local MCP bridge

When a client only supports stdio, use the `diurna-mcp` npm package in `packages/mcp`. It forwards JSON-RPC to `/api/mcp` and reads `DIURNA_API_KEY` from the environment.
