@lexapi/mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LexAPI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # LexAPI MCP
2
+
3
+ [Model Context Protocol](https://modelcontextprotocol.io) server for [LexAPI](https://lex-api.com) — query EUR-Lex, EU case law, and the citation graph from Claude, Cursor, and other MCP-enabled clients.
4
+
5
+ Install once, get an API key, and ask your AI assistant: *"summarize Article 17 of the GDPR"* or *"which regulations amend Directive 95/46/EC?"* — the model calls LexAPI directly.
6
+
7
+ ## Install
8
+
9
+ You'll need a LexAPI API key. Create one for free at [lex-api.com/dashboard](https://lex-api.com/dashboard) (50 calls/day on the FREE tier).
10
+
11
+ ### Claude Desktop
12
+
13
+ Add to `claude_desktop_config.json` (location: `~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
14
+
15
+ ```json
16
+ {
17
+ "mcpServers": {
18
+ "lexapi": {
19
+ "command": "npx",
20
+ "args": ["-y", "@lexapi/mcp"],
21
+ "env": {
22
+ "LEXAPI_API_KEY": "lex_..."
23
+ }
24
+ }
25
+ }
26
+ }
27
+ ```
28
+
29
+ Restart Claude Desktop.
30
+
31
+ ### Claude Code
32
+
33
+ ```bash
34
+ claude mcp add lexapi --env LEXAPI_API_KEY=lex_... -- npx -y @lexapi/mcp
35
+ ```
36
+
37
+ ### Cursor / other MCP clients
38
+
39
+ Any client that supports stdio MCP servers can run this. The command is `npx -y @lexapi/mcp` with `LEXAPI_API_KEY` in the environment.
40
+
41
+ ## Tools
42
+
43
+ | Tool | What it does |
44
+ |---|---|
45
+ | `lex_search` | Structured EUR-Lex search (text, dates, document type, author, language). |
46
+ | `lex_get_document` | Full parsed document by CELEX — metadata + articles, sections, tables, annexes. |
47
+ | `lex_get_metadata` | Metadata only (faster than full content). |
48
+ | `lex_get_document_by_url` | Fetch by EUR-Lex URL (pasted from a browser). |
49
+ | `lex_recent_documents` | Recent Official Journal publications (default 7 days). |
50
+ | `lex_cited_by` | Documents citing this CELEX (inbound, typed edges). |
51
+ | `lex_cites` | Documents this CELEX cites (outbound, typed edges). |
52
+ | `lex_citation_network` | Both directions in one call. |
53
+ | `lex_semantic_case_law` | Embedding search over EU case law (paid plans). |
54
+ | `lex_semantic_legislation` | Embedding search over EU legislation (paid plans). |
55
+
56
+ ## Configuration
57
+
58
+ | Env var | Default | Purpose |
59
+ |---|---|---|
60
+ | `LEXAPI_API_KEY` | *(required)* | Your API key. Get one at [lex-api.com/dashboard](https://lex-api.com/dashboard). |
61
+ | `LEXAPI_BASE_URL` | `https://lex-api.com/api/v1` | Override for self-hosted or staging. |
62
+
63
+ ## Troubleshooting
64
+
65
+ **`LEXAPI_API_KEY is not set`** — the env var isn't reaching the spawned process. Double-check the `env` block in your MCP client config.
66
+
67
+ **`LexAPI error (401 invalid_api_key)`** — the key is wrong or revoked. Generate a new one at the dashboard.
68
+
69
+ **`LexAPI error (429 …)`** — you hit your daily quota or per-minute rate limit. The server retries once automatically; if you see this in tool output, you're over quota. Upgrade your plan or wait for reset.
70
+
71
+ **`LexAPI error (403 …)` on semantic tools** — semantic search requires a paid plan. FREE tier returns 403 for those endpoints.
72
+
73
+ ## Local development
74
+
75
+ ```bash
76
+ git clone https://github.com/lexapi/lexapi-mcp.git
77
+ cd lexapi-mcp
78
+ npm install
79
+ npm run build
80
+
81
+ LEXAPI_API_KEY=lex_xxx node dist/index.js
82
+ ```
83
+
84
+ ## License
85
+
86
+ MIT
@@ -0,0 +1,31 @@
1
+ import type { AnyResponse, CitationsQuery, DocumentContentRequest, RecentDocumentsQuery, SearchRequest, SemanticSearchRequest } from './types.js';
2
+ export declare class LexAPIError extends Error {
3
+ readonly status: number;
4
+ readonly slug: string;
5
+ constructor(status: number, slug: string, message: string);
6
+ }
7
+ export interface LexAPIClientOptions {
8
+ apiKey: string;
9
+ baseUrl?: string;
10
+ /** Max retries on transient errors (5xx, network). Default 2. */
11
+ maxRetries?: number;
12
+ }
13
+ export declare class LexAPIClient {
14
+ private readonly apiKey;
15
+ private readonly baseUrl;
16
+ private readonly maxRetries;
17
+ constructor(opts: LexAPIClientOptions);
18
+ private request;
19
+ search(body: SearchRequest): Promise<AnyResponse>;
20
+ getDocument(body: DocumentContentRequest): Promise<AnyResponse>;
21
+ getMetadata(body: DocumentContentRequest): Promise<AnyResponse>;
22
+ getDocumentByUrl(body: {
23
+ url: string;
24
+ }): Promise<AnyResponse>;
25
+ recentDocuments(query: RecentDocumentsQuery): Promise<AnyResponse>;
26
+ citedBy(celex: string, query?: CitationsQuery): Promise<AnyResponse>;
27
+ cites(celex: string, query?: CitationsQuery): Promise<AnyResponse>;
28
+ citationNetwork(celex: string): Promise<AnyResponse>;
29
+ semanticCaseLaw(body: SemanticSearchRequest): Promise<AnyResponse>;
30
+ semanticLegislation(body: SemanticSearchRequest): Promise<AnyResponse>;
31
+ }
package/dist/client.js ADDED
@@ -0,0 +1,133 @@
1
+ const DEFAULT_BASE_URL = 'https://lex-api.com/api/v1';
2
+ export class LexAPIError extends Error {
3
+ status;
4
+ slug;
5
+ constructor(status, slug, message) {
6
+ super(message);
7
+ this.status = status;
8
+ this.slug = slug;
9
+ this.name = 'LexAPIError';
10
+ }
11
+ }
12
+ export class LexAPIClient {
13
+ apiKey;
14
+ baseUrl;
15
+ maxRetries;
16
+ constructor(opts) {
17
+ if (!opts.apiKey)
18
+ throw new Error('LexAPIClient: apiKey is required');
19
+ this.apiKey = opts.apiKey;
20
+ this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, '');
21
+ this.maxRetries = opts.maxRetries ?? 2;
22
+ }
23
+ // ── HTTP ──────────────────────────────────────────────────────────
24
+ async request(method, path, body, query) {
25
+ const url = new URL(this.baseUrl + path);
26
+ if (query) {
27
+ for (const [k, v] of Object.entries(query)) {
28
+ if (v === undefined || v === null)
29
+ continue;
30
+ url.searchParams.set(k, String(v));
31
+ }
32
+ }
33
+ const init = {
34
+ method,
35
+ headers: {
36
+ 'x-api-key': this.apiKey,
37
+ ...(body !== undefined ? { 'Content-Type': 'application/json' } : {}),
38
+ },
39
+ ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
40
+ };
41
+ let attempt = 0;
42
+ while (true) {
43
+ const res = await fetch(url, init);
44
+ // Honor 429 Retry-After once before giving up.
45
+ if (res.status === 429 && attempt < this.maxRetries) {
46
+ const retryAfter = parseInt(res.headers.get('Retry-After') ?? '1', 10);
47
+ await sleep(Math.max(1, retryAfter) * 1000);
48
+ attempt++;
49
+ continue;
50
+ }
51
+ // Retry on transient 5xx with exponential backoff.
52
+ if (res.status >= 500 && res.status < 600 && attempt < this.maxRetries) {
53
+ await sleep(500 * Math.pow(2, attempt));
54
+ attempt++;
55
+ continue;
56
+ }
57
+ const text = await res.text();
58
+ const json = text ? safeJson(text) : {};
59
+ if (!res.ok) {
60
+ const { slug, message } = extractError(json, text, res.status);
61
+ throw new LexAPIError(res.status, slug, message);
62
+ }
63
+ return json;
64
+ }
65
+ }
66
+ // ── Endpoints ─────────────────────────────────────────────────────
67
+ search(body) {
68
+ return this.request('POST', '/search', body);
69
+ }
70
+ getDocument(body) {
71
+ return this.request('POST', '/documentContent', body);
72
+ }
73
+ getMetadata(body) {
74
+ return this.request('POST', '/documents/metadata', body);
75
+ }
76
+ getDocumentByUrl(body) {
77
+ return this.request('POST', '/documents/url', body);
78
+ }
79
+ recentDocuments(query) {
80
+ return this.request('GET', '/documents/recent', undefined, query);
81
+ }
82
+ citedBy(celex, query = {}) {
83
+ return this.request('GET', `/citations/cited-by/${encodeURIComponent(celex)}`, undefined, query);
84
+ }
85
+ cites(celex, query = {}) {
86
+ return this.request('GET', `/citations/cites/${encodeURIComponent(celex)}`, undefined, query);
87
+ }
88
+ citationNetwork(celex) {
89
+ return this.request('GET', `/citations/network/${encodeURIComponent(celex)}`);
90
+ }
91
+ semanticCaseLaw(body) {
92
+ return this.request('POST', '/search/semantic', body);
93
+ }
94
+ semanticLegislation(body) {
95
+ return this.request('POST', '/legislation/semantic', body);
96
+ }
97
+ }
98
+ function sleep(ms) {
99
+ return new Promise((resolve) => setTimeout(resolve, ms));
100
+ }
101
+ function safeJson(text) {
102
+ try {
103
+ return JSON.parse(text);
104
+ }
105
+ catch {
106
+ return { error: 'invalid_json', message: text.slice(0, 500) };
107
+ }
108
+ }
109
+ // Gateway returns either the typed envelope { error: { code, message } } or
110
+ // the legacy flat shape { error: "slug", message: "..." }. Handle both;
111
+ // fall back to HTTP status when neither is present.
112
+ function extractError(json, text, status) {
113
+ const fallbackMessage = text || `HTTP ${status}`;
114
+ const fallbackSlug = `http_${status}`;
115
+ if (!json || typeof json !== 'object') {
116
+ return { slug: fallbackSlug, message: fallbackMessage };
117
+ }
118
+ const j = json;
119
+ const e = j.error;
120
+ if (e && typeof e === 'object') {
121
+ const eo = e;
122
+ const slug = typeof eo.code === 'string' ? eo.code : fallbackSlug;
123
+ const message = typeof eo.message === 'string'
124
+ ? eo.message
125
+ : typeof j.message === 'string'
126
+ ? j.message
127
+ : fallbackMessage;
128
+ return { slug, message };
129
+ }
130
+ const slug = typeof e === 'string' ? e : fallbackSlug;
131
+ const message = typeof j.message === 'string' ? j.message : fallbackMessage;
132
+ return { slug, message };
133
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
5
+ import { LexAPIClient, LexAPIError } from './client.js';
6
+ import { tools, toolsByName } from './tools.js';
7
+ const PACKAGE_NAME = 'lexapi-mcp';
8
+ const PACKAGE_VERSION = '0.1.0';
9
+ const apiKey = process.env.LEXAPI_API_KEY;
10
+ if (!apiKey) {
11
+ console.error(`[${PACKAGE_NAME}] LEXAPI_API_KEY is not set. Get a key at https://lex-api.com/dashboard and pass it in your MCP client config.`);
12
+ process.exit(1);
13
+ }
14
+ const baseUrl = process.env.LEXAPI_BASE_URL;
15
+ const client = new LexAPIClient({
16
+ apiKey,
17
+ ...(baseUrl ? { baseUrl } : {}),
18
+ });
19
+ const server = new Server({ name: PACKAGE_NAME, version: PACKAGE_VERSION }, { capabilities: { tools: {} } });
20
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
21
+ tools: tools.map(({ name, description, inputSchema }) => ({
22
+ name,
23
+ description,
24
+ inputSchema,
25
+ })),
26
+ }));
27
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
28
+ const { name, arguments: args = {} } = request.params;
29
+ const tool = toolsByName[name];
30
+ if (!tool) {
31
+ return {
32
+ isError: true,
33
+ content: [{ type: 'text', text: `Unknown tool: ${name}` }],
34
+ };
35
+ }
36
+ try {
37
+ const result = await tool.handler(args, client);
38
+ return {
39
+ content: [
40
+ { type: 'text', text: JSON.stringify(result, null, 2) },
41
+ ],
42
+ };
43
+ }
44
+ catch (err) {
45
+ if (err instanceof LexAPIError) {
46
+ return {
47
+ isError: true,
48
+ content: [
49
+ {
50
+ type: 'text',
51
+ text: `LexAPI error (${err.status} ${err.slug}): ${err.message}`,
52
+ },
53
+ ],
54
+ };
55
+ }
56
+ const message = err instanceof Error ? err.message : String(err);
57
+ return {
58
+ isError: true,
59
+ content: [{ type: 'text', text: `Tool execution failed: ${message}` }],
60
+ };
61
+ }
62
+ });
63
+ const transport = new StdioServerTransport();
64
+ await server.connect(transport);
65
+ console.error(`[${PACKAGE_NAME}] v${PACKAGE_VERSION} ready · ${tools.length} tools registered`);
@@ -0,0 +1,10 @@
1
+ import type { LexAPIClient } from './client.js';
2
+ interface ToolDef {
3
+ name: string;
4
+ description: string;
5
+ inputSchema: Record<string, unknown>;
6
+ handler: (args: Record<string, unknown>, client: LexAPIClient) => Promise<unknown>;
7
+ }
8
+ export declare const tools: ToolDef[];
9
+ export declare const toolsByName: Record<string, ToolDef>;
10
+ export {};
package/dist/tools.js ADDED
@@ -0,0 +1,244 @@
1
+ const LANGUAGES = [
2
+ 'en', 'fr', 'de', 'es', 'it', 'pl', 'nl', 'pt', 'ro', 'bg',
3
+ 'cs', 'da', 'el', 'et', 'fi', 'ga', 'hr', 'hu', 'lt', 'lv',
4
+ 'mt', 'sk', 'sl', 'sv',
5
+ ];
6
+ const DOCUMENT_TYPES = [
7
+ 'judgment', 'opinion', 'order', 'regulation', 'directive',
8
+ 'decision', 'recommendation', 'opinion-act', 'communication',
9
+ 'proposal', 'report', 'resolution', 'declaration', 'treaty',
10
+ 'protocol', 'agreement', 'written-question', 'oral-question',
11
+ 'consolidated-text', 'guideline', 'implementing',
12
+ ];
13
+ const AUTHORS = [
14
+ 'commission', 'council', 'parliament', 'court-of-justice',
15
+ 'general-court', 'ecb', 'eca', 'eesc', 'cor', 'ema', 'efsa',
16
+ ];
17
+ const CITATION_TYPES = [
18
+ 'reference', 'amendment', 'repeal',
19
+ 'implementation', 'legal-basis', 'proposal',
20
+ ];
21
+ const CELEX_PATTERN = '^[0-9A-Z]{2,20}$';
22
+ export const tools = [
23
+ // ── Search ────────────────────────────────────────────────────────
24
+ {
25
+ name: 'lex_search',
26
+ description: 'Search EUR-Lex with structured filters (free text, date range, document type, author, language). Returns a paginated list of matching documents with CELEX numbers, titles, and dates. Use this when the user wants to find documents matching a topic or filter; use lex_get_document afterwards to fetch full content of a specific result.',
27
+ inputSchema: {
28
+ type: 'object',
29
+ properties: {
30
+ query: { type: 'string', description: 'Free-text search.' },
31
+ textScope: {
32
+ type: 'string',
33
+ enum: ['title', 'text', 'title-text', 'any'],
34
+ description: 'Where to apply the query string.',
35
+ },
36
+ dateFrom: { type: 'string', format: 'date' },
37
+ dateTo: { type: 'string', format: 'date' },
38
+ year: {
39
+ oneOf: [
40
+ { type: 'integer' },
41
+ { type: 'array', items: { type: 'integer' } },
42
+ ],
43
+ },
44
+ documentType: {
45
+ oneOf: [
46
+ { type: 'string', enum: DOCUMENT_TYPES },
47
+ { type: 'array', items: { type: 'string', enum: DOCUMENT_TYPES } },
48
+ ],
49
+ },
50
+ author: {
51
+ oneOf: [
52
+ { type: 'string', enum: AUTHORS },
53
+ { type: 'array', items: { type: 'string', enum: AUTHORS } },
54
+ ],
55
+ },
56
+ language: { type: 'string', enum: LANGUAGES, default: 'en' },
57
+ maxPages: {
58
+ type: 'integer',
59
+ minimum: 1,
60
+ default: 1,
61
+ description: 'Result pages to fetch (clamped by subscription tier).',
62
+ },
63
+ },
64
+ additionalProperties: false,
65
+ },
66
+ handler: (args, client) => client.search(args),
67
+ },
68
+ // ── Document fetch ────────────────────────────────────────────────
69
+ {
70
+ name: 'lex_get_document',
71
+ description: 'Fetch the full parsed content of a single EU document by CELEX number. Returns metadata (title, type, dates, author, ECLI/ELI, keywords) plus structured body (articles, sections, tables, annexes). Articles are individually addressable with id, number, title, and content. Use this when the user has a specific CELEX or wants the body of a known document.',
72
+ inputSchema: {
73
+ type: 'object',
74
+ required: ['celexNumber'],
75
+ properties: {
76
+ celexNumber: {
77
+ type: 'string',
78
+ pattern: CELEX_PATTERN,
79
+ description: 'CELEX identifier, e.g. 32016R0679 for the GDPR.',
80
+ },
81
+ bypassCorpus: {
82
+ type: 'boolean',
83
+ description: 'Force a fresh live fetch instead of the cached copy.',
84
+ },
85
+ },
86
+ additionalProperties: false,
87
+ },
88
+ handler: (args, client) => client.getDocument(args),
89
+ },
90
+ {
91
+ name: 'lex_get_metadata',
92
+ description: 'Fetch metadata only for a CELEX (title, dates, type, author, ECLI/ELI, keywords, subjects) — significantly faster than lex_get_document because it skips body parsing. Use this for quick "what is this document" lookups or before deciding whether to fetch the body.',
93
+ inputSchema: {
94
+ type: 'object',
95
+ required: ['celexNumber'],
96
+ properties: {
97
+ celexNumber: {
98
+ type: 'string',
99
+ pattern: CELEX_PATTERN,
100
+ description: 'CELEX identifier.',
101
+ },
102
+ },
103
+ additionalProperties: false,
104
+ },
105
+ handler: (args, client) => client.getMetadata(args),
106
+ },
107
+ {
108
+ name: 'lex_get_document_by_url',
109
+ description: 'Fetch a parsed document from any EUR-Lex URL — useful when the user pastes a link from their browser. Extracts the CELEX from the URL and returns the same shape as lex_get_document plus sourceUrl and extractedCelex echoes.',
110
+ inputSchema: {
111
+ type: 'object',
112
+ required: ['url'],
113
+ properties: {
114
+ url: {
115
+ type: 'string',
116
+ format: 'uri',
117
+ description: 'Any eur-lex.europa.eu URL containing a CELEX: identifier or uri= parameter.',
118
+ },
119
+ },
120
+ additionalProperties: false,
121
+ },
122
+ handler: (args, client) => client.getDocumentByUrl(args),
123
+ },
124
+ {
125
+ name: 'lex_recent_documents',
126
+ description: 'List documents published to the Official Journal recently. Default window is 7 days. Filterable by document type, author, and language. Use this when the user asks "what was published this week" or wants a delta over a date window.',
127
+ inputSchema: {
128
+ type: 'object',
129
+ properties: {
130
+ days: {
131
+ type: 'integer',
132
+ minimum: 1,
133
+ default: 7,
134
+ description: 'Look-back window in days.',
135
+ },
136
+ documentType: { type: 'string', enum: DOCUMENT_TYPES },
137
+ author: { type: 'string', enum: AUTHORS },
138
+ language: { type: 'string', enum: LANGUAGES, default: 'en' },
139
+ limit: { type: 'integer', minimum: 1, maximum: 500, default: 50 },
140
+ },
141
+ additionalProperties: false,
142
+ },
143
+ handler: (args, client) => client.recentDocuments(args),
144
+ },
145
+ // ── Citation graph ────────────────────────────────────────────────
146
+ {
147
+ name: 'lex_cited_by',
148
+ description: 'Find documents that cite this CELEX (inbound edges). Returns source documents grouped with their edge type (reference, amendment, repeal, implementation, legal-basis, proposal). Use to see who depends on or modifies a given act.',
149
+ inputSchema: {
150
+ type: 'object',
151
+ required: ['celexNumber'],
152
+ properties: {
153
+ celexNumber: { type: 'string', pattern: CELEX_PATTERN },
154
+ citationType: {
155
+ type: 'string',
156
+ enum: CITATION_TYPES,
157
+ description: 'Optionally filter to one edge type.',
158
+ },
159
+ limit: { type: 'integer', minimum: 1, maximum: 500, default: 100 },
160
+ offset: { type: 'integer', minimum: 0, default: 0 },
161
+ },
162
+ additionalProperties: false,
163
+ },
164
+ handler: (args, client) => {
165
+ const { celexNumber, ...query } = args;
166
+ return client.citedBy(celexNumber, query);
167
+ },
168
+ },
169
+ {
170
+ name: 'lex_cites',
171
+ description: 'Find documents this CELEX cites (outbound edges). Returns target documents grouped with their edge type. Use to see what an act relies on, amends, or implements.',
172
+ inputSchema: {
173
+ type: 'object',
174
+ required: ['celexNumber'],
175
+ properties: {
176
+ celexNumber: { type: 'string', pattern: CELEX_PATTERN },
177
+ citationType: { type: 'string', enum: CITATION_TYPES },
178
+ limit: { type: 'integer', minimum: 1, maximum: 500, default: 100 },
179
+ offset: { type: 'integer', minimum: 0, default: 0 },
180
+ },
181
+ additionalProperties: false,
182
+ },
183
+ handler: (args, client) => {
184
+ const { celexNumber, ...query } = args;
185
+ return client.cites(celexNumber, query);
186
+ },
187
+ },
188
+ {
189
+ name: 'lex_citation_network',
190
+ description: 'Fetch both inbound and outbound citations for a CELEX in one call, with per-edge-type counts. Use when the user wants a holistic view of how a document sits in the citation graph.',
191
+ inputSchema: {
192
+ type: 'object',
193
+ required: ['celexNumber'],
194
+ properties: {
195
+ celexNumber: { type: 'string', pattern: CELEX_PATTERN },
196
+ },
197
+ additionalProperties: false,
198
+ },
199
+ handler: (args, client) => client.citationNetwork(args.celexNumber),
200
+ },
201
+ // ── Semantic ──────────────────────────────────────────────────────
202
+ {
203
+ name: 'lex_semantic_case_law',
204
+ description: 'Embedding-based search over EU case law — finds cases by meaning, not exact keywords. Returns relevance-scored matches with ECLI, court, case name/number, and (where available) full text. Requires a paid LexAPI plan; returns 403 on FREE tier.',
205
+ inputSchema: {
206
+ type: 'object',
207
+ required: ['query'],
208
+ properties: {
209
+ query: { type: 'string', minLength: 1 },
210
+ limit: { type: 'integer', minimum: 1, maximum: 50, default: 10 },
211
+ min_score: {
212
+ type: 'number',
213
+ minimum: 0,
214
+ maximum: 1,
215
+ description: 'Drop results below this cosine similarity (0–1).',
216
+ },
217
+ filters: {
218
+ type: 'object',
219
+ additionalProperties: true,
220
+ description: 'Optional upstream filters passed through to the semantic backend.',
221
+ },
222
+ },
223
+ additionalProperties: false,
224
+ },
225
+ handler: (args, client) => client.semanticCaseLaw(args),
226
+ },
227
+ {
228
+ name: 'lex_semantic_legislation',
229
+ description: 'Embedding-based search over EU legislation at article granularity. Returns relevance-scored article hits with parent CELEX, article reference, and law title. Requires a paid LexAPI plan; returns 403 on FREE tier.',
230
+ inputSchema: {
231
+ type: 'object',
232
+ required: ['query'],
233
+ properties: {
234
+ query: { type: 'string', minLength: 1 },
235
+ limit: { type: 'integer', minimum: 1, maximum: 50, default: 10 },
236
+ min_score: { type: 'number', minimum: 0, maximum: 1 },
237
+ filters: { type: 'object', additionalProperties: true },
238
+ },
239
+ additionalProperties: false,
240
+ },
241
+ handler: (args, client) => client.semanticLegislation(args),
242
+ },
243
+ ];
244
+ export const toolsByName = Object.fromEntries(tools.map((t) => [t.name, t]));
@@ -0,0 +1,43 @@
1
+ export type Language = 'en' | 'fr' | 'de' | 'es' | 'it' | 'pl' | 'nl' | 'pt' | 'ro' | 'bg' | 'cs' | 'da' | 'el' | 'et' | 'fi' | 'ga' | 'hr' | 'hu' | 'lt' | 'lv' | 'mt' | 'sk' | 'sl' | 'sv';
2
+ export type DocumentType = 'judgment' | 'opinion' | 'order' | 'regulation' | 'directive' | 'decision' | 'recommendation' | 'opinion-act' | 'communication' | 'proposal' | 'report' | 'resolution' | 'declaration' | 'treaty' | 'protocol' | 'agreement' | 'written-question' | 'oral-question' | 'consolidated-text' | 'guideline' | 'implementing';
3
+ export type Author = 'commission' | 'council' | 'parliament' | 'court-of-justice' | 'general-court' | 'ecb' | 'eca' | 'eesc' | 'cor' | 'ema' | 'efsa';
4
+ export type CitationType = 'reference' | 'amendment' | 'repeal' | 'implementation' | 'legal-basis' | 'proposal';
5
+ export interface SearchRequest {
6
+ query?: string;
7
+ textScope?: 'title' | 'text' | 'title-text' | 'any';
8
+ dateFrom?: string;
9
+ dateTo?: string;
10
+ year?: number | number[];
11
+ month?: number | number[];
12
+ documentType?: DocumentType | DocumentType[];
13
+ author?: Author | Author[];
14
+ domain?: 'EU_LAW' | 'NATIONAL_LAW' | 'ALL';
15
+ subdomain?: string | string[];
16
+ language?: Language;
17
+ maxPages?: number;
18
+ }
19
+ export interface DocumentContentRequest {
20
+ celexNumber: string;
21
+ bypassCorpus?: boolean;
22
+ }
23
+ export interface RecentDocumentsQuery {
24
+ days?: number;
25
+ documentType?: DocumentType;
26
+ author?: Author;
27
+ domain?: string;
28
+ subdomain?: string;
29
+ language?: Language;
30
+ limit?: number;
31
+ }
32
+ export interface CitationsQuery {
33
+ limit?: number;
34
+ offset?: number;
35
+ citationType?: CitationType;
36
+ }
37
+ export interface SemanticSearchRequest {
38
+ query: string;
39
+ limit?: number;
40
+ min_score?: number;
41
+ filters?: Record<string, unknown>;
42
+ }
43
+ export type AnyResponse = Record<string, unknown>;
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ // Types mirror the LexAPI OpenAPI spec at
2
+ // https://github.com/lexapi/eurlex-parser/blob/main/openapi.yaml
3
+ //
4
+ // Kept narrow on purpose — every endpoint response is much wider than this,
5
+ // but the MCP server only forwards the fields a model actually needs to
6
+ // reason about. Anything not modeled is passed through as `unknown`.
7
+ export {};
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@lexapi/mcp",
3
+ "version": "0.1.0",
4
+ "description": "Model Context Protocol server for LexAPI — query EUR-Lex and EU case law from Claude, Cursor, and other MCP-enabled clients.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "lexapi-mcp": "dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "dev": "tsc --watch",
18
+ "start": "node dist/index.js",
19
+ "clean": "rm -rf dist",
20
+ "prepublishOnly": "npm run clean && npm run build"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "keywords": [
26
+ "mcp",
27
+ "model-context-protocol",
28
+ "lexapi",
29
+ "eur-lex",
30
+ "eu-law",
31
+ "legal",
32
+ "claude"
33
+ ],
34
+ "author": "LexAPI",
35
+ "license": "MIT",
36
+ "homepage": "https://lex-api.com",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/lexapi/lexapi-mcp.git"
40
+ },
41
+ "engines": {
42
+ "node": ">=20"
43
+ },
44
+ "dependencies": {
45
+ "@modelcontextprotocol/sdk": "^1.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@types/node": "^22.0.0",
49
+ "typescript": "^5.5.0"
50
+ },
51
+ "overrides": {
52
+ "hono": "^4.12.27",
53
+ "qs": "^6.15.3"
54
+ }
55
+ }