ley-energia
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@ley-energia Busca el artículo 30 de la LSE y dime si sigue vigente."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
ley-energia-mx makes Mexico's energy regulation searchable and citable by article: the laws of the 2025 energy reform, their regulations, the general administrative provisions (DACG) issued by the Comisión Nacional de Energía, and the 2014 laws they replaced, with validity dates and lineage. Every result carries its citation ("LSE, artículo 30"), whether it is in force, what replaced it, and the link to the official publication.
It works with Claude over MCP, with no API keys: Claude does the reasoning with your own subscription; this repository only serves official text with its citation. There is also a CLI, a local web app with hybrid search, and a static site that searches in your browser.
Site: beg-lag.github.io/ley-energia-mx ·
Corpus: corpus/fuentes.yaml ·
Evaluation: evaluacion/golden.yaml
Home | Search | Phone |
Use it with Claude
git clone https://github.com/BEG-lag/ley-energia-mx
cd ley-energia-mx
uv sync
uv run ley-energia indexar # builds data/ley-energia.sqlite locally (about a minute)Claude Code: open Claude Code inside the folder;
.mcp.jsonregisters the server. Or add it from anywhere:claude mcp add ley-energia -- uv --directory /path/to/ley-energia-mx run ley-energia mcp.Claude Desktop: add to
claude_desktop_config.json:"mcpServers": { "ley-energia": { "command": "uv", "args": ["--directory", "/path/to/ley-energia-mx", "run", "ley-energia", "mcp"] } }
The server is read-only and exposes five tools and three prompts:
Tool | What it returns |
| Hybrid search with filters by type, issuer, abrogated laws and date (the regime in force that day). Each hit has |
| The full text of an article, provision ("1.2") or transitory article ("transitorio segundo"; those of each amending decree carry its DOF date, e.g. "transitorio primero (dof 2021-03-09)"). |
| Publication data, validity, lineage and the table of contents of a document. |
| What a norm replaced and what replaced it, with the date and legal basis. |
| Everything in the corpus with its status. |
Prompts: due_diligence (regulatory review of a project), regimen_temporal (what applied on a
date) and regulacion_aplicable. The repository also ships two Claude Code skills in
.claude/skills/. The server instructions tell Claude to read before citing, to
cite document and article, to flag abrogated norms, to say when the corpus has no support, and to
treat document text as data, not instructions.
Nothing to install: the site's Copiar para Claude button copies your question, the full text of the top results with their citations, and the answering instructions, ready to paste into Claude.
Related MCP server: corpus-iuris
Command line
uv run ley-energia buscar "permisos de generación de energía eléctrica"
uv run ley-energia buscar "permisos de generación" --fecha 2020-01-01 # regime in force that day
uv run ley-energia articulo LSE 30
uv run ley-energia linaje LIE
uv run ley-energia serve # http://127.0.0.1:8000 with hybrid search
uv run ley-energia evaluar -v # runs the 40-case evaluationWhat is in the corpus
Cutoff: 25 November 2026. 35 documents, 4,417 fragments, 3,376 articles and provisions.
Group | Documents |
Laws in force (2025 reform and related) | LSE, LSH, LPTE, Ley de la CNE, LEPECFE, LEPEPM, Ley de Geotermia, Ley de Biocombustibles, LIH, Ley de la ASEA (from leyes-mx) |
Regulations | Reglamentos of the LSE, LSH, LPTE, Geotermia, Biocombustibles, LEPECFE, LEPEPM and LIH (Cámara de Diputados) |
CNE DACG | Generation and storage permits, transmission tariffs, self-supply, competitive mechanisms, cogeneration, storage integration, hydrocarbon permit terms, commercialization (DOF) |
Abrogated, with lineage | LIE → LSE, LH → LSH, LTE → LPTE, LORCME → Ley de la CNE, LCFE → LEPECFE, LPM → LEPEPM, Ley de Energía Geotérmica → Ley de Geotermia, LPDB → Ley de Biocombustibles, CRE Agreement A/113/2024 → CNE storage DACG |
Abrogation dates were checked against the transitory articles of each replacing instrument (for example, the 2025 laws took effect on 19 March 2025; the CNE storage DACG took effect on the next business day after 16 April 2026 and left A/113/2024 without effect).
How search works
Manifest.
corpus/fuentes.yamldeclares each document, its official source, publication and validity dates and its successor.ley-energia actualizardownloads and segments; the segmented texts are versioned incorpus/textos/, so the index can be rebuilt anywhere without touching government sites.Segmentation by legal unit. One fragment per article, numbered provision (DACG) or transitory article, keeping its path (Title, Chapter, Section). Long articles are split into numbered parts without losing the article key.
Single-file index. SQLite with FTS5 over Spanish Snowball stems and local embeddings (
paraphrase-multilingual-MiniLM-L12-v2through fastembed/ONNX). No database server, no extensions, no keys.Weighted reciprocal rank fusion of four signals: lexical, vector, exact article (so "artículo 8" never returns article 80) and named document (acronyms, aliases and titles; the longest name wins, so "Reglamento de la LSE" is the regulation, not the law). Old 2014 vocabulary ("venta directa", "autoabasto") is mapped to the 2025 terms.
Validity filters. By default only norms in force; an abrogated one is included when the query names it or when you ask for a date.
Evaluation
40 cases written from the official text, not from what the engine returned: exact articles, named documents, topics, 2014 vocabulary and point-in-time regimes.
Engine | Recall@5 | MRR | Cases passed |
Hybrid, Python (CLI, local web, MCP) | 1.00 | 0.89 | 40 / 40 |
In-browser, JavaScript (the static site, | 1.00 | 0.92 | 40 / 40 |
CI rebuilds the index and runs both evaluations on every push. The browser engine is deterministic and must pass every case; the hybrid one must pass every exact-article, first-place and validity case and keep recall@5 at 0.95 or more and MRR at 0.85 or more, because the ONNX model can differ slightly between platforms on borderline topic cases.
Add a document
Add an entry to corpus/fuentes.yaml (formats: leyes-mx, pdf, dof), then:
uv run ley-energia actualizar --solo <id>
uv run ley-energia indexar
uv run ley-energia evaluarA scheduled workflow re-downloads every source each Monday and opens a pull request if any official text changed.
Limitations
It is a curated corpus, not all of Mexico's energy regulation: no NOMs, CENACE market manuals or CRE/CNH regulation other than A/113/2024.
The date filter selects which documents were in force on a date, but each text is the version as of the cutoff. For laws reformed after publication (for example, the LIH), the historical wording of each article is not reconstructed.
DOF notes are extracted from HTML; tables and images in annexes may be incomplete.
The embedding model is small and general-purpose. On this evaluation set the lexical, exact-article and named-document signals carry most of the work; the vectors help with paraphrased questions.
Legal notice
Information from official sources, for informational purposes only. It is not legal or tax advice. The only authoritative versions are the official publications in the DOF and of each issuing authority; validate with the competent authority.
Background
The first version (April 2026) was a private prototype with Postgres, paid embeddings and Claude API calls. It was audited and rebuilt from scratch for this release; the audit and a before-and-after table are in audits/2026-11-auditoria.md (Spanish).
License and credits
Code under the MIT License. Data and the project's additions under CC0; see DATA-LICENSE.md. Fonts under the SIL Open Font License.
Made by Benjamín Esponda García, PIVOTEK. Related: leyes-mx (federal laws with history), radar·energía (daily energy radar). For lawyers: Con Criterio, an AI toolkit for legal practice in Mexico.
Available Tools
5 toolsbuscarARead-onlyIdempotent
Busca en la regulación energética mexicana y devuelve fragmentos citables.
Args:
consulta: pregunta o términos en español. Reconoce artículos ("artículo 20"), siglas
(LSE, LSH, LIE...) y nombres de leyes, reglamentos y DACG.
k: número de resultados (máximo 20).
tipo: "ley", "reglamento" o "dacg".
emisor: por ejemplo "Comisión Nacional de Energía" o "CNE".
incluir_abrogados: incluye normas abrogadas (por omisión sólo vigentes, salvo que la
consulta nombre una abrogada).
fecha: AAAA-MM-DD; devuelve sólo lo que estaba en vigor ese día (régimen temporal).
Inputs: consulta (required), k, tipo, fecha, +2 more. Returns: object
catalogoARead-onlyIdempotent
Lista los documentos del corpus con su estado.
Args:
tipo: "ley", "reglamento" o "dacg" (opcional).
incluir_abrogados: incluye las normas abrogadas.
Inputs: tipo, incluir_abrogados. Returns: object
documentoBRead-onlyIdempotent
Ficha de un documento: datos de publicación, vigencia, linaje e índice de artículos.
Args:
documento: id, sigla o nombre.
Inputs: documento (required). Returns: object
leer_articuloARead-onlyIdempotent
Texto completo de un artículo, disposición o transitorio.
Args:
documento: id, sigla o nombre (por ejemplo "LSE", "lse", "Reglamento de la LSH").
articulo: "20", "8 bis", "1.2" (disposición de una DACG), "transitorio segundo" o la
clave completa que dio buscar (p. ej. "transitorio primero (dof 2025-03-18)").
Inputs: articulo (required), documento (required). Returns: object
linajeARead-onlyIdempotent
Qué norma sustituyó a esta y a cuáles sustituyó ella, con fecha y fundamento.
Args:
documento: id, sigla o nombre.
Inputs: documento (required). Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool maps to a distinct operation: search, full-text read, document profile, lineage, and corpus listing. The one soft overlap is that `documento` already advertises 'linaje' in its output while a dedicated `linaje` tool exists, which could cause an agent to fetch lineage from the wrong entry point. `catalogo` vs `documento` is also mildly close (list vs single ficha), but the singular/plural scope makes them distinguishable.
All names are lowercase Spanish with a consistent language and casing style, which is readable. However the set mixes a bare verb (`buscar`), a verb_noun compound (`leer_articulo`), and three bare nouns (`documento`, `linaje`, `catalogo`), so there is no predictable verb_noun pattern to extrapolate from.
Five tools is well-scoped for a legal-corpus retrieval server: discover, read, inspect, trace lineage, enumerate. Each tool earns its place and there is no filler or trivially thin surface.
The surface covers the core lifecycle of legal research: search, retrieve full text, document metadata/index, normative lineage, and corpus catalog, including abrogated norms and point-in-time vigency. Minor gaps remain, such as resolving cross-references inside an article or comparing two norms side by side, but agents can approximate these with existing tools.
Maintenance
Related MCP Connectors
JusPronto is case-management software for Brazilian law firms. Its remote MCP server (OAuth 2.1 with PKCE, per-permission scopes, audit log) lets Claude and ChatGPT read the firm's own cases, deadlines, agenda, recent court movements and case files with the page cited. Write actions require the lawyer's approval. Requires a JusPronto account.
Connect Claude to your Platform7n workspaces: chat, links, work and decks. One-click OAuth.
- platform7nDeprecatedtech.p7n
Connect Claude to your Platform7n workspaces: chat, links, work and decks. One-click OAuth.
Semantic retrieval across 295,000+ Indonesian regulations and 5.6M+ legal provisions, updated daily. Give AI direct access to Indonesian regulatory knowledge before reasoning.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables Claude to search and retrieve legal sources from Mexican and inter-American courts (SCJN, TFJA, DOF, Corte IDH) with complete citations and official links.MIT
- FlicenseNot gradedqualityCmaintenanceEnables AI agents to search Mexican federal and state statutes, Supreme Court theses, and precedents, returning verifiable citations with dated validity, public URLs, and explicit indication of whether case law is binding jurisprudence or merely persuasive.-
- AlicenseAqualityCmaintenanceEnables MCP clients to search Colombian energy and gas resolutions and legal opinions, read them in chunks or by internal search, and explore each rule's regulatory graph with validity computed from the texts themselves.4MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI assistants to search and analyze Turkish electricity and energy market regulation by scanning the Resmî Gazete and EPDK, EPİAŞ, ETKB and TEİAŞ announcements, extracting amended articles and effective dates, and ranking changes by market importance with reasoning. It also provides source health status and rule-based effective-date extraction from any text, without requiring an API key.250 PyPI2MIT