Documentation

Get started with Rhetra in minutes. Install the MCP server, ingest your first document, and start querying permissions.

Getting started

1. Install

npm install @legalformalize/core
# Rhetra uses the MCP SDK
npm install @modelcontextprotocol/sdk

2. Start the MCP server

# Set your API key (needed for document ingestion)
export ANTHROPIC_API_KEY=sk-ant-...

# Start Rhetra
npm run rhetra

The server starts on stdio transport. Connect any MCP-compatible agent platform.

3. Connect your agent

Add Rhetra to your MCP client configuration:

{
  "mcpServers": {
    "rhetra": {
      "command": "npx",
      "args": ["tsx", "src/rhetra/server.ts"],
      "env": {
        "ANTHROPIC_API_KEY": "sk-ant-..."
      }
    }
  }
}

4. Ingest a document

// Call via MCP
await mcp.callTool("ingest_document", {
  text: contractText,
  documentType: "contract",
  title: "Vendor MSA"
});
// Returns: { normsExtracted: 98, formulasCompiled: 98, ... }

5. Check permissions

const result = await mcp.callTool("check_permission", {
  bearer: "procurement-bot",
  action: "approve vendor contract"
});

// result.verdict: "PERMITTED" | "PROHIBITED" | "UNDETERMINED"
// result.enforcementLevel: "AUTO_PERMIT" | "SOFT_CHECK" | ...
// result.reasoning: "Action prohibited: authority limit..."
// result.applicableNorms: [{ sourceRef: "MSA §4.2", ... }]

Core concepts

Deontic modalities

Every norm has one of four modalities from Hohfeldian legal theory:

OBLIGATION

Must do

Seller shall deliver the goods

PROHIBITION

Must not do

Agent shall not disclose confidential data

PERMISSION

May do

Buyer may terminate upon 30 days notice

POWER

Can change normative relations

Manager may delegate procurement authority

Three-valued logic

Rhetra uses Kleene three-valued logic. Every evaluation produces one of three values:

PERMITTED

The action is allowed. A matching permission or obligation exists.

PROHIBITED

The action is forbidden. A matching prohibition exists with no applicable exception.

UNDETERMINED

The system cannot determine permissibility. Conditions are unresolved. The agent should escalate to a human.

UNDETERMINED is the key differentiator. When a prohibition has a scope condition ("shall not use beyond the scope of the license"), and the scope condition is unknown, Rhetra returns UNDETERMINED — not a false PROHIBITED.

Enforcement levels

Each verdict comes with an enforcement level based on the confidence of the underlying norms:

AUTO_PERMITHigh confidence. Execute immediately.
SOFT_CHECKGood confidence. Execute, flag for audit.
HUMAN_APPROVALMedium confidence. Pause for human.
PEER_REVIEWLow confidence. Independent evaluation.
ESCALATEVery low confidence. Block and escalate.

Agent scoping

Agents aren't employees. Only a subset of norms are relevant to any given agent, based on its capabilities. Register agents with their capabilities, and Rhetra filters to applicable norms only.

await mcp.callTool("register_agent", {
  agentId: "procurement-bot",
  agentName: "Procurement Bot",
  capabilities: ["make-purchases", "access-data"],
  actingAs: ["Customer", "Authorized Purchaser"]
});

// Now queries for this agent are filtered automatically