LEX — AI Legal Platform for Law Firms

AI-powered legal analysis platform for law firms and corporate counsel.

Features

Resources

Blog Articles

Technology

Built on AWS (EC2, Bedrock Claude AI, ALB, WAF, S3, ACM, KMS). PostgreSQL, Redis, Qdrant vector database. TypeScript, React, Node.js.

Start free — 50 credits on registration. Sign up

TECH 10 min

How We Built an MCP Server with 56 Tools for Legal AI

One endpoint. Three services. 58 MCP tools. Triple transport: stdio for Claude Desktop, HTTP REST for web apps, SSE for streaming. Every tool call goes through an 11-step pipeline with cost tracking at each stage. The number of tools will grow. The architecture does not care.

How We Built an MCP Server with 56 Tools for Legal AI

One endpoint. Three services. Triple transport. Here is what it takes to build a production MCP server that actually scales.


The Problem: Legal AI Needs More Than a Single API Call

When a lawyer asks "Negatory or vindication claim for unauthorized occupation of a land plot?" — the answer requires: searching 200+ court decisions, retrieving texts from the Civil Code and the Land Code, comparing "for" and "against" practice, checking precedents, synthesizing a strategic recommendation.

This is not a single LLM call. It is an orchestrated pipeline of 5-7 tool calls.

Architecture: 56 Tools, Three Services, One Gateway

| Service | Tools | Domain | |———|——-|——–| | mcp_backend | 36 | Court decisions, legislation, semantic search, documents, due diligence | | mcp_rada | 4 | Parliament — bills, deputies, voting | | mcp_openreyestr | 16 | State register — legal entities, beneficiaries, debtors |

A single environment variable — ENABLE_UNIFIED_GATEWAY=true — turns the backend into an aggregation point.

Triple Transport

stdio (MCP Native)

Pure JSON-RPC via stdin/stdout. Claude Desktop, MCP CLI. Zero overhead.

HTTP REST API

POST /api/tools/:toolName with Bearer token. Batch endpoint for parallel execution. Accept: text/event-stream header switches to SSE.

SSE (MCP-over-SSE)

Two variants: ChatGPT/OpenAI protocol (/sse) and standard MCP SSE (/v1/sse).

Call Flow: 11 Steps

  1. dualAuth — JWT or API key
  2. Balance check → 402 if insufficient
  3. Credit calculation for the tool
  4. Cost tracking — pending record
  5. Cost estimation before execution
  6. Gateway routing — local or remote?
  7. Execution in AsyncLocalStorage context
  8. Handler dispatch → domain logic
  9. Tracking completion — actual tokens
  10. Credit deduction after success
  11. Response with cost breakdown

Patterns That Saved Us

Cost hints in descriptions — every tool has an estimated cost in its description. The LLM sees this during planning.

Budget-aware models — the reasoning_budget parameter maps to different models: quick → nano, deep → gpt-5.1.

Vault isolation — userId is injected at the transport level, tool schema knows nothing about authentication.

Route normalization — without it, 56 tools + UUIDs create thousands of time series in Prometheus.

Numbers

The number of tools will grow. The architecture does not care.


Update: New Tools (March 2026)

The total number of MCP tools has grown from 56 to 58 thanks to two new tools in the mcp_openreyestr service.

New tools:

Improvements to existing tools:

The get_legislation_section tool now supports vector search as a fallback strategy. If the user provides a rada_id and a text query without a specific article number, the system automatically performs semantic search across the vector index of the relevant law, returning the most relevant sections.