@lexapi/mcp 0.2.0 → 0.3.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/CHANGELOG.md +61 -0
- package/LICENSE +1 -1
- package/README.md +73 -34
- package/dist/client.d.ts +93 -19
- package/dist/client.js +300 -94
- package/dist/errors.d.ts +35 -0
- package/dist/errors.js +164 -0
- package/dist/http-server.d.ts +15 -1
- package/dist/http-server.js +166 -100
- package/dist/index.js +18 -60
- package/dist/server.d.ts +61 -0
- package/dist/server.js +97 -0
- package/dist/shape.d.ts +61 -0
- package/dist/shape.js +607 -0
- package/dist/tools.d.ts +25 -8
- package/dist/tools.js +803 -218
- package/dist/webhookUrl.d.ts +4 -0
- package/dist/webhookUrl.js +114 -0
- package/package.json +23 -15
- package/dist/types.d.ts +0 -43
- package/dist/types.js +0 -7
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function isPublicIPv4(a: string): boolean;
|
|
2
|
+
export declare function isPublicIPv6(a: string): boolean;
|
|
3
|
+
/** null when the URL passes every DNS-free rule; otherwise why it is refused. */
|
|
4
|
+
export declare function webhookUrlProblem(raw: string): string | null;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Client-side mirror of the DNS-free half of LexAPI's webhook egress guard
|
|
2
|
+
// (eurlex-parser server/utils/safeOutboundUrl.js, checkUrlSyntax). Defence in
|
|
3
|
+
// depth only: the API is authoritative and also checks every resolved
|
|
4
|
+
// address at send time. This lets a model hear "not allowed" before a call
|
|
5
|
+
// instead of after one.
|
|
6
|
+
import { isIP } from 'node:net';
|
|
7
|
+
const MAX_URL_LENGTH = 2048;
|
|
8
|
+
const HTTPS_PORTS = [443, 8443];
|
|
9
|
+
// Internal by construction (RFC 6761/6762/8375, cloud internal zones, LAN
|
|
10
|
+
// suffixes, reserved TLDs) — the same list the API uses.
|
|
11
|
+
const INTERNAL_SUFFIXES = [
|
|
12
|
+
'localhost', 'local', 'internal', 'localdomain', 'lan', 'home', 'corp',
|
|
13
|
+
'intranet', 'private', 'arpa', 'test', 'invalid', 'example', 'onion',
|
|
14
|
+
];
|
|
15
|
+
// IANA IPv4 special-purpose ranges (+ multicast / reserved).
|
|
16
|
+
const BLOCKED_V4 = [
|
|
17
|
+
['0.0.0.0', 8], ['10.0.0.0', 8], ['100.64.0.0', 10], ['127.0.0.0', 8],
|
|
18
|
+
['169.254.0.0', 16], ['172.16.0.0', 12], ['192.0.0.0', 24], ['192.0.2.0', 24],
|
|
19
|
+
['192.31.196.0', 24], ['192.52.193.0', 24], ['192.88.99.0', 24], ['192.168.0.0', 16],
|
|
20
|
+
['192.175.48.0', 24], ['198.18.0.0', 15], ['198.51.100.0', 24], ['203.0.113.0', 24],
|
|
21
|
+
['224.0.0.0', 4], ['240.0.0.0', 4],
|
|
22
|
+
];
|
|
23
|
+
function v4ToInt(a) {
|
|
24
|
+
return a.split('.').reduce((n, o) => n * 256 + Number(o), 0);
|
|
25
|
+
}
|
|
26
|
+
export function isPublicIPv4(a) {
|
|
27
|
+
const ip = v4ToInt(a);
|
|
28
|
+
for (const [base, bits] of BLOCKED_V4) {
|
|
29
|
+
const size = 2 ** (32 - bits);
|
|
30
|
+
const start = v4ToInt(base);
|
|
31
|
+
if (ip >= start && ip < start + size)
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
/** Expand an IPv6 literal (as normalised by the WHATWG URL parser) into 8 16-bit groups. */
|
|
37
|
+
function v6Groups(a) {
|
|
38
|
+
let text = a;
|
|
39
|
+
const v4 = /^(.*:)(\d{1,3}(?:\.\d{1,3}){3})$/.exec(text);
|
|
40
|
+
if (v4) {
|
|
41
|
+
const o = v4[2].split('.').map(Number);
|
|
42
|
+
text = `${v4[1]}${((o[0] << 8) | o[1]).toString(16)}:${((o[2] << 8) | o[3]).toString(16)}`;
|
|
43
|
+
}
|
|
44
|
+
const halves = text.split('::');
|
|
45
|
+
if (halves.length > 2)
|
|
46
|
+
return null;
|
|
47
|
+
const parse = (h) => (h ? h.split(':').map((g) => Number.parseInt(g, 16)) : []);
|
|
48
|
+
const head = parse(halves[0]);
|
|
49
|
+
const tail = halves.length === 2 ? parse(halves[1]) : [];
|
|
50
|
+
const fill = 8 - head.length - tail.length;
|
|
51
|
+
if (fill < 0 || (halves.length === 1 && fill !== 0))
|
|
52
|
+
return null;
|
|
53
|
+
const groups = [...head, ...Array(fill).fill(0), ...tail];
|
|
54
|
+
return groups.some((g) => Number.isNaN(g) || g < 0 || g > 0xffff) ? null : groups;
|
|
55
|
+
}
|
|
56
|
+
export function isPublicIPv6(a) {
|
|
57
|
+
const g = v6Groups(a);
|
|
58
|
+
if (!g)
|
|
59
|
+
return false;
|
|
60
|
+
const embeddedV4 = () => `${g[6] >> 8}.${g[6] & 255}.${g[7] >> 8}.${g[7] & 255}`;
|
|
61
|
+
// ::ffff:a.b.c.d (IPv4-mapped) and 64:ff9b::/96 (NAT64) reach an IPv4 address.
|
|
62
|
+
if (g.slice(0, 5).every((x) => x === 0) && g[5] === 0xffff)
|
|
63
|
+
return isPublicIPv4(embeddedV4());
|
|
64
|
+
if (g[0] === 0x64 && g[1] === 0xff9b && g.slice(2, 6).every((x) => x === 0))
|
|
65
|
+
return isPublicIPv4(embeddedV4());
|
|
66
|
+
if ((g[0] & 0xe000) !== 0x2000)
|
|
67
|
+
return false; // only global unicast 2000::/3
|
|
68
|
+
if (g[0] === 0x2001 && g[1] < 0x0200)
|
|
69
|
+
return false; // 2001::/23 IETF protocol assignments
|
|
70
|
+
if (g[0] === 0x2001 && g[1] === 0x0db8)
|
|
71
|
+
return false; // documentation
|
|
72
|
+
if (g[0] === 0x2002)
|
|
73
|
+
return false; // 6to4
|
|
74
|
+
if ((g[0] & 0xfff0) === 0x3ff0)
|
|
75
|
+
return false; // 3fff::/20 documentation
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
/** null when the URL passes every DNS-free rule; otherwise why it is refused. */
|
|
79
|
+
export function webhookUrlProblem(raw) {
|
|
80
|
+
if (typeof raw !== 'string' || !raw.trim())
|
|
81
|
+
return 'Webhook URL must be a non-empty string';
|
|
82
|
+
if (raw.length > MAX_URL_LENGTH)
|
|
83
|
+
return `Webhook URL must be at most ${MAX_URL_LENGTH} characters`;
|
|
84
|
+
let url;
|
|
85
|
+
try {
|
|
86
|
+
url = new URL(raw.trim());
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return 'Webhook URL is not a valid absolute URL';
|
|
90
|
+
}
|
|
91
|
+
if (url.protocol !== 'https:')
|
|
92
|
+
return `Webhook URL must use https (got "${url.protocol.replace(/:$/, '')}")`;
|
|
93
|
+
if (url.username || url.password)
|
|
94
|
+
return 'Webhook URL must not contain credentials (user:password@)';
|
|
95
|
+
const port = url.port ? Number(url.port) : 443;
|
|
96
|
+
if (!HTTPS_PORTS.includes(port))
|
|
97
|
+
return `Webhook URL port ${port} is not allowed; use 443 or 8443`;
|
|
98
|
+
const host = url.hostname.toLowerCase().replace(/^\[|\]$/g, '').replace(/\.+$/, '');
|
|
99
|
+
if (!host)
|
|
100
|
+
return 'Webhook URL has no hostname';
|
|
101
|
+
const ipVersion = isIP(host);
|
|
102
|
+
if (ipVersion === 4)
|
|
103
|
+
return isPublicIPv4(host) ? null : `Webhook URL points to a non-public address (${host})`;
|
|
104
|
+
if (ipVersion === 6)
|
|
105
|
+
return isPublicIPv6(host) ? null : `Webhook URL points to a non-public address (${host})`;
|
|
106
|
+
if (!host.includes('.'))
|
|
107
|
+
return `"${host}" is a single-label hostname; use a fully-qualified public domain name`;
|
|
108
|
+
const tld = host.split('.').pop();
|
|
109
|
+
if (INTERNAL_SUFFIXES.includes(tld))
|
|
110
|
+
return `"${host}" is an internal or reserved hostname`;
|
|
111
|
+
if (/^[0-9]+$/.test(tld) || /^0x[0-9a-f]*$/i.test(tld))
|
|
112
|
+
return `"${host}" is not a valid public hostname`;
|
|
113
|
+
return null;
|
|
114
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lexapi/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"mcpName": "io.github.Lex-API/lexapi-mcp",
|
|
5
|
-
"description": "Model Context Protocol server for LexAPI —
|
|
5
|
+
"description": "Model Context Protocol server for LexAPI — EUR-Lex legislation, CJEU case law, the citation graph and semantic search (with point-in-time asOf) from Claude, Cursor and other MCP clients.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"bin": {
|
|
@@ -11,15 +11,19 @@
|
|
|
11
11
|
"files": [
|
|
12
12
|
"dist",
|
|
13
13
|
"README.md",
|
|
14
|
+
"CHANGELOG.md",
|
|
14
15
|
"LICENSE"
|
|
15
16
|
],
|
|
16
17
|
"scripts": {
|
|
17
|
-
"build": "tsc",
|
|
18
|
-
"dev": "tsc --watch",
|
|
18
|
+
"build": "tsc -p tsconfig.json",
|
|
19
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
20
|
+
"typecheck": "tsc -p tsconfig.check.json",
|
|
21
|
+
"lint": "eslint .",
|
|
22
|
+
"test": "npm run build && vitest run",
|
|
19
23
|
"start": "node dist/index.js",
|
|
20
24
|
"start:http": "node dist/http-entry.js",
|
|
21
25
|
"clean": "rm -rf dist",
|
|
22
|
-
"prepublishOnly": "npm run clean && npm run
|
|
26
|
+
"prepublishOnly": "npm run clean && npm run typecheck && npm run lint && npm test"
|
|
23
27
|
},
|
|
24
28
|
"publishConfig": {
|
|
25
29
|
"access": "public"
|
|
@@ -31,9 +35,12 @@
|
|
|
31
35
|
"eur-lex",
|
|
32
36
|
"eu-law",
|
|
33
37
|
"legal",
|
|
34
|
-
"claude"
|
|
38
|
+
"claude",
|
|
39
|
+
"cjeu",
|
|
40
|
+
"case-law",
|
|
41
|
+
"semantic-search"
|
|
35
42
|
],
|
|
36
|
-
"author": "
|
|
43
|
+
"author": "Arieta Labs Ltd <support@lex-api.com> (https://lex-api.com)",
|
|
37
44
|
"license": "MIT",
|
|
38
45
|
"homepage": "https://lex-api.com",
|
|
39
46
|
"repository": {
|
|
@@ -44,15 +51,16 @@
|
|
|
44
51
|
"node": ">=20"
|
|
45
52
|
},
|
|
46
53
|
"dependencies": {
|
|
47
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
54
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
55
|
+
"zod": "^4.6.7"
|
|
48
56
|
},
|
|
49
57
|
"devDependencies": {
|
|
50
|
-
"@
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
58
|
+
"@eslint/js": "^10.0.1",
|
|
59
|
+
"@types/node": "^22.20.5",
|
|
60
|
+
"eslint": "^10.13.0",
|
|
61
|
+
"globals": "^17.13.0",
|
|
62
|
+
"typescript": "^5.9.3",
|
|
63
|
+
"typescript-eslint": "^8.72.0",
|
|
64
|
+
"vitest": "^5.0.5"
|
|
57
65
|
}
|
|
58
66
|
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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 {};
|