Skip to main content
Glama

Legal MCP - RAG System for Polish Legal Documents

An implementation of a RAG (Retrieval-Augmented Generation) system utilizing the Model Context Protocol (MCP). This project demonstrates a modular architecture for legal document processing and retrieval using ChromaDB as a vector store and Ollama for local LLM inference.

πŸ— Project Structure

The project is organized into several microservices:

  • mcp_server/: The core MCP server that exposes semantic search tools over the vector database. This is the primary service β€” connect any MCP-compatible LLM client directly to it.

  • ingestion/: REST API service for fetching and embedding documents from the SAOS (court judgments) and ELI (legislative acts) APIs into ChromaDB.

  • frontend/: Optional local chat UI backed by Ollama and the MCP server.

  • data/: Local storage for the ChromaDB database and other persistent assets.

  • scripts/: Utility scripts for ingestion and maintenance.

Related MCP server: SAOS MCP

πŸš€ Getting Started

Prerequisites

  • Docker & Docker Compose: Required for containerized deployment.

  • Python 3.10+: For local development.

  • Ollama: Installed locally, or use the integrated service in docker-compose.yml.

  • NVIDIA Container Toolkit: (Optional) For GPU acceleration within Docker.

Environment Setup

  1. Clone the repository:

    git clone https://github.com/barwojcik/legal_mcp.git
    cd legal_mcp
  2. Copy and review the environment variables:

    cp .env.example .env
    # Edit .env if you want to use OpenAI/Google embeddings instead of Ollama

Running with Docker Compose

Spin up ChromaDB, Ollama, the MCP server, and the ingestion service:

docker compose up -d chroma ollama mcp-server ingestion

To also run the optional frontend:

docker compose up -d

Services will be available at:

  • ChromaDB: http://localhost:8000

  • Ollama: http://localhost:11434

  • MCP Server: http://localhost:8001/mcp

  • Ingestion API: http://localhost:8002

  • Frontend (optional): http://localhost:8003

Populate the database

bash scripts/ingest_saso.sh

This fetches one page (20 judgments) from the SAOS API and embeds them into ChromaDB. See scripts/ingest_saso.sh and the Ingestion API docs for more options.

πŸ”Œ Connecting a Commercial LLM

The MCP server speaks the Model Context Protocol over HTTP/SSE. Once the stack is running, point your LLM client at http://localhost:8001/mcp.

Claude Desktop

Add the following to your claude_desktop_config.json (usually at ~/Library/Application Support/Claude/claude_desktop_config.json on macOS or %APPDATA%\Claude\claude_desktop_config.json on Windows):

{
  "mcpServers": {
    "legal": {
      "url": "http://localhost:8001/mcp",
      "type": "http"
    }
  }
}

Cursor / Zed / other MCP clients

Add an MCP server entry pointing to http://localhost:8001/mcp. Refer to your client's documentation for the exact configuration format.

Once connected, the LLM will have access to 14 tools for searching and retrieving Polish court judgments and legislative acts.

πŸ›  Ingestion API

The ingestion service exposes a REST API at http://localhost:8002.

Ingest SAOS court judgments:

curl -X POST http://localhost:8002/update \
  -H "Content-Type: application/json" \
  -d '{"n_pages": 1, "page_size": 20}'

Ingest ELI legislative acts:

curl -X POST http://localhost:8002/eli-update \
  -H "Content-Type: application/json" \
  -d '{"n_pages": 1, "page_size": 20}'

πŸ›  Development

Linting and Type Checking

# Run ruff
ruff check . --fix

# Run mypy
mypy .

Pre-commit Hooks

pre-commit install

βš– License

This project is licensed under the Apache-2.0 licence.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Enables AI-powered legal research and analysis of Polish legal acts from the Sejm API. Provides comprehensive search, document retrieval, metadata analysis, and content access for legal documents from Dziennik Ustaw and Monitor Polski.
      13
      23
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Provides access to Polish court judgments from the SAOS database. Enables search and retrieval of judgments with full-text search, filtering, and detailed case information.
      3
      20 npm
      1
      Apache 2.0
    • A
      license
      Not graded
      quality
      F
      maintenance
      MCP server providing access to Polish law statutes, provisions, case law, and EU law integrations, enabling natural language legal research, citation validation, and cross-referencing.
      52 npm
      7
      Apache 2.0