> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lexera.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP Architecture: How Lexera Speaks JSON-RPC Over SSE

> Learn how Lexera uses the Model Context Protocol with JSON-RPC 2.0 over Server-Sent Events for asynchronous, stateful legal document verification.

Lexera exposes its legal verification pipeline through the Model Context Protocol (MCP), an open standard that lets AI agents and enterprise systems call tools over a persistent, event-driven transport. Because human attorney review takes time, Lexera's implementation is fully asynchronous and stateful: you open a single long-lived connection, dispatch a request, and receive the result later as a server event.

## Why JSON-RPC 2.0 over SSE

Traditional REST APIs expect an immediate response, which does not fit a workflow where a law firm may spend hours reviewing a contract. Lexera solves this with Server-Sent Events (SSE): a persistent HTTP connection that the server uses to push status updates, results, and errors back to your system. JSON-RPC 2.0 provides a lightweight, structured message format for invoking tools and correlating responses.

## JSON-RPC 2.0 message format

Every tool call is a JSON-RPC 2.0 request. The envelope is predictable and easy to generate from any language.

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "lexera_route_to_specialist",
    "arguments": {
      "document_text": "Vendor contract with uncapped liability clause...",
      "target_jurisdiction": "UAE",
      "specialist_instructions": "Cap liability at 100% of contract value."
    }
  }
}
```

| Field              | Description                                                        |
| ------------------ | ------------------------------------------------------------------ |
| `jsonrpc`          | Must be exactly `"2.0"`.                                           |
| `id`               | A client-generated identifier used to match responses.             |
| `method`           | Always `"tools/call"` for Lexera MCP tool invocation.              |
| `params.name`      | The MCP tool name (for example, `lexera_route_to_specialist`).     |
| `params.arguments` | Tool-specific parameters documented on each tool's reference page. |

## Server-Sent Events transport

Lexera streams three kinds of information over SSE:

1. **Session initialization** — After you open the stream, the server sends an `event: endpoint` containing your unique session URL. You must extract this URL to dispatch any RPC.
2. **Execution results** — Once you POST a tool call, the eventual result (for example, `DISPATCH_SUCCESS` or a completed order payload) arrives as a later SSE message on the same connection.
3. **Errors** — Validation failures, wallet issues, and authentication problems are also streamed as JSON-RPC error payloads over SSE.

## The `event: endpoint` handshake

Immediately after opening the SSE stream, the server pushes a session assignment. The event looks like this:

```text theme={null}
event: endpoint
data: /mcp-server/messages?sessionId=550e8400-e29b-41d4-a716-446655440000
```

Your code must parse the `data` line, prepend `https://lexera.dev`, and use the resulting URL for every subsequent JSON-RPC POST. Without this step, the server cannot correlate your tool calls with your open stream.

<Info>
  All SSE traffic, including the initial session assignment, requires a valid Bearer token. See [Authentication](/authentication) for how to obtain and pass your API key.
</Info>

## Next steps

* Learn the exact three-step flow in [Execution Lifecycle](/concepts/execution-lifecycle)
* See the full list of available MCP tools in [Tools Overview](/tools/introduction)
