@pipeworx/mcp-jsonschema 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 Pipeworx
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,56 @@
1
+ # mcp-jsonschema
2
+
3
+ JSON Schema validation MCP.
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 1170+ live data sources.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+ | `validate_json_schema` | Validate a JSON value against a JSON Schema (draft-07 subset: type, required, properties, additionalProperties, items, enum, const, min/max, minLength/maxLength, pattern, minItems/maxItems, uniqueItems, format). Returns {valid, errors:[{path,message}]}. Keyless, offline. |
12
+
13
+ ## Quick Start
14
+
15
+ Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
16
+
17
+ ```json
18
+ {
19
+ "mcpServers": {
20
+ "jsonschema": {
21
+ "url": "https://gateway.pipeworx.io/jsonschema/mcp"
22
+ }
23
+ }
24
+ }
25
+ ```
26
+
27
+ Or connect to the full Pipeworx gateway for access to all 1170+ data sources:
28
+
29
+ ```json
30
+ {
31
+ "mcpServers": {
32
+ "pipeworx": {
33
+ "url": "https://gateway.pipeworx.io/mcp"
34
+ }
35
+ }
36
+ }
37
+ ```
38
+
39
+ ## Using with ask_pipeworx
40
+
41
+ Instead of calling tools directly, you can ask questions in plain English:
42
+
43
+ ```
44
+ ask_pipeworx({ question: "your question about Jsonschema data" })
45
+ ```
46
+
47
+ The gateway picks the right tool and fills the arguments automatically.
48
+
49
+ ## More
50
+
51
+ - [All tools and guides](https://github.com/pipeworx-io/examples)
52
+ - [pipeworx.io](https://pipeworx.io)
53
+
54
+ ## License
55
+
56
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-jsonschema",
3
+ "version": "0.1.0",
4
+ "description": "JSON Schema validation MCP.",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "jsonschema"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-jsonschema"
13
+ },
14
+ "scripts": {
15
+ "typecheck": "tsc --noEmit"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^5.7.0"
19
+ }
20
+ }
package/server.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.pipeworx-io/jsonschema",
4
+ "title": "Jsonschema",
5
+ "description": "JSON Schema validation MCP.",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/jsonschema",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-jsonschema",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/jsonschema/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,120 @@
1
+ interface McpToolDefinition {
2
+ name: string;
3
+ description: string;
4
+ inputSchema: {
5
+ type: 'object';
6
+ properties: Record<string, unknown>;
7
+ required?: string[];
8
+ };
9
+ }
10
+
11
+ interface McpToolExport {
12
+ tools: McpToolDefinition[];
13
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
14
+ meter?: { credits: number };
15
+ cost?: Record<string, unknown>;
16
+ provider?: string;
17
+ }
18
+
19
+ /**
20
+ * JSON Schema validation MCP.
21
+ *
22
+ * Keyless, offline: validate a JSON value against a JSON Schema (a practical
23
+ * draft-07 subset — type, required, properties, additionalProperties, items,
24
+ * enum, const, min/max, length, pattern, items counts, uniqueItems, and common
25
+ * formats). Returns each failure with its path. Pure logic — no API, no key.
26
+ */
27
+
28
+
29
+ type Sch = Record<string, any>;
30
+ const FORMATS: Record<string, RegExp> = {
31
+ email: /^[^@\s]+@[^@\s]+\.[^@\s]+$/,
32
+ uri: /^[a-z][a-z0-9+.-]*:\/\/\S+$/i,
33
+ 'date-time': /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/,
34
+ date: /^\d{4}-\d{2}-\d{2}$/,
35
+ time: /^\d{2}:\d{2}:\d{2}/,
36
+ uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
37
+ ipv4: /^(\d{1,3}\.){3}\d{1,3}$/,
38
+ hostname: /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i,
39
+ };
40
+
41
+ function typeOf(v: unknown): string {
42
+ if (v === null) return 'null';
43
+ if (Array.isArray(v)) return 'array';
44
+ if (Number.isInteger(v)) return 'integer';
45
+ return typeof v;
46
+ }
47
+ function typeOk(v: unknown, t: string): boolean {
48
+ const a = typeOf(v);
49
+ if (t === 'number') return a === 'number' || a === 'integer';
50
+ return a === t;
51
+ }
52
+
53
+ function validate(data: unknown, schema: Sch, path: string, errors: { path: string; message: string }[]): void {
54
+ if (typeof schema !== 'object' || schema === null) return;
55
+ const p = path || '$';
56
+ if (schema.const !== undefined && JSON.stringify(data) !== JSON.stringify(schema.const)) errors.push({ path: p, message: `must equal const ${JSON.stringify(schema.const)}` });
57
+ if (schema.enum && !schema.enum.some((e: unknown) => JSON.stringify(e) === JSON.stringify(data))) errors.push({ path: p, message: `must be one of ${JSON.stringify(schema.enum)}` });
58
+ if (schema.type) {
59
+ const types = Array.isArray(schema.type) ? schema.type : [schema.type];
60
+ if (!types.some((t: string) => typeOk(data, t))) { errors.push({ path: p, message: `must be ${types.join(' or ')}, got ${typeOf(data)}` }); return; }
61
+ }
62
+ const t = typeOf(data);
63
+ if (t === 'string') {
64
+ const s = data as string;
65
+ if (schema.minLength !== undefined && s.length < schema.minLength) errors.push({ path: p, message: `shorter than minLength ${schema.minLength}` });
66
+ if (schema.maxLength !== undefined && s.length > schema.maxLength) errors.push({ path: p, message: `longer than maxLength ${schema.maxLength}` });
67
+ if (schema.pattern && !new RegExp(schema.pattern).test(s)) errors.push({ path: p, message: `does not match pattern ${schema.pattern}` });
68
+ if (schema.format && FORMATS[schema.format] && !FORMATS[schema.format].test(s)) errors.push({ path: p, message: `is not a valid ${schema.format}` });
69
+ }
70
+ if (t === 'number' || t === 'integer') {
71
+ const n = data as number;
72
+ if (schema.minimum !== undefined && n < schema.minimum) errors.push({ path: p, message: `less than minimum ${schema.minimum}` });
73
+ if (schema.maximum !== undefined && n > schema.maximum) errors.push({ path: p, message: `greater than maximum ${schema.maximum}` });
74
+ if (schema.exclusiveMinimum !== undefined && n <= schema.exclusiveMinimum) errors.push({ path: p, message: `must be > ${schema.exclusiveMinimum}` });
75
+ if (schema.exclusiveMaximum !== undefined && n >= schema.exclusiveMaximum) errors.push({ path: p, message: `must be < ${schema.exclusiveMaximum}` });
76
+ if (schema.multipleOf && n % schema.multipleOf !== 0) errors.push({ path: p, message: `not a multiple of ${schema.multipleOf}` });
77
+ }
78
+ if (t === 'array') {
79
+ const arr = data as unknown[];
80
+ if (schema.minItems !== undefined && arr.length < schema.minItems) errors.push({ path: p, message: `fewer than minItems ${schema.minItems}` });
81
+ if (schema.maxItems !== undefined && arr.length > schema.maxItems) errors.push({ path: p, message: `more than maxItems ${schema.maxItems}` });
82
+ if (schema.uniqueItems && new Set(arr.map((x) => JSON.stringify(x))).size !== arr.length) errors.push({ path: p, message: `items are not unique` });
83
+ if (schema.items) arr.forEach((item, i) => validate(item, schema.items, `${p}[${i}]`, errors));
84
+ }
85
+ if (t === 'object') {
86
+ const obj = data as Record<string, unknown>;
87
+ for (const req of schema.required ?? []) if (!(req in obj)) errors.push({ path: p, message: `missing required property "${req}"` });
88
+ if (schema.properties) for (const [k, sub] of Object.entries(schema.properties)) if (k in obj) validate(obj[k], sub as Sch, `${p}.${k}`, errors);
89
+ if (schema.additionalProperties === false && schema.properties) {
90
+ const allowed = new Set(Object.keys(schema.properties));
91
+ for (const k of Object.keys(obj)) if (!allowed.has(k)) errors.push({ path: `${p}.${k}`, message: `additional property not allowed` });
92
+ }
93
+ }
94
+ }
95
+
96
+ const tools: McpToolExport['tools'] = [
97
+ {
98
+ name: 'validate_json_schema',
99
+ description: 'Validate a JSON value against a JSON Schema (draft-07 subset: type, required, properties, additionalProperties, items, enum, const, min/max, minLength/maxLength, pattern, minItems/maxItems, uniqueItems, format). Returns {valid, errors:[{path,message}]}. Keyless, offline.',
100
+ inputSchema: {
101
+ type: 'object',
102
+ properties: {
103
+ data: { description: 'The JSON value to validate (any type).' },
104
+ schema: { type: 'object', description: 'The JSON Schema to validate against.' },
105
+ },
106
+ required: ['data', 'schema'],
107
+ },
108
+ },
109
+ ];
110
+
111
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
112
+ if (name !== 'validate_json_schema') throw new Error(`Unknown tool: ${name}`);
113
+ if (typeof args.schema !== 'object' || args.schema === null) throw new Error('Required argument "schema" must be a JSON Schema object.');
114
+ if (!('data' in args)) throw new Error('Required argument "data" is missing.');
115
+ const errors: { path: string; message: string }[] = [];
116
+ try { validate(args.data, args.schema as Sch, '', errors); } catch (e) { return { valid: false, errors: [{ path: '$', message: `schema error: ${(e as Error).message}` }] }; }
117
+ return { valid: errors.length === 0, error_count: errors.length, errors };
118
+ }
119
+
120
+ export default { tools, callTool, meter: { credits: 1 } } satisfies McpToolExport;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "dist",
10
+ "rootDir": "src",
11
+ "declaration": true
12
+ },
13
+ "include": ["src"]
14
+ }