@haddowg/json-api-mcp 0.0.0-stage → 1.2.1
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 +21 -0
- package/README.md +51 -2
- package/dist/cli.d.mts +11 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/cli.mjs +71 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/generate-CiLuqQJ0.mjs +1474 -0
- package/dist/generate-CiLuqQJ0.mjs.map +1 -0
- package/dist/generate-CuWnYJUB.d.mts +337 -0
- package/dist/generate-CuWnYJUB.d.mts.map +1 -0
- package/dist/generate.d.mts +2 -0
- package/dist/generate.mjs +2 -0
- package/dist/index.cjs +808 -0
- package/dist/index.d.cts +534 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +534 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +788 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +77 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gregory Haddow
|
|
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
CHANGED
|
@@ -1,3 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @haddowg/json-api-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Part of the [jsonapi.rest](https://jsonapi.rest) suite** — a complete, spec-compliant
|
|
4
|
+
> JSON:API 1.1 stack: a framework-agnostic PHP [core](https://github.com/haddowg/json-api), a
|
|
5
|
+
> [Symfony bundle](https://github.com/haddowg/json-api-symfony), a
|
|
6
|
+
> [Laravel package](https://github.com/haddowg/json-api-laravel), and the **typed TypeScript
|
|
7
|
+
> client**, bound together by one conformance-tested OpenAPI 3.1 contract.
|
|
8
|
+
> Full documentation: **[haddowg.github.io/json-api-ts](https://haddowg.github.io/json-api-ts/)**.
|
|
9
|
+
|
|
10
|
+
MCP tool definitions and a call handler for a `haddowg/json-api` server. A build-time
|
|
11
|
+
generator turns the server's OpenAPI document into one JSON model, which you commit; the
|
|
12
|
+
runtime serves one tool per collection, resource, related and custom action operation from it,
|
|
13
|
+
with input schemas valid under OpenAI's and Anthropic's strict modes. Calls run through
|
|
14
|
+
[`@haddowg/json-api-client`](../client). The package doesn't own an MCP server: the host lists
|
|
15
|
+
the tools and passes calls to the handler.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @haddowg/json-api-mcp @haddowg/json-api-client
|
|
21
|
+
npm install --save-dev @haddowg/json-api-codegen
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Generate the model
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx json-api-mcp --input openapi/v5.json --output src/mcp/v5.mcp.json
|
|
28
|
+
npx json-api-mcp --input openapi/v5.json --output src/mcp/v5.mcp.json --check # in CI
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Tools include one relationship deep by default, so each tool's schema carries only the types its
|
|
32
|
+
direct relations reach. Pass `--include-depth <n>`, or `all` for every path the document
|
|
33
|
+
declares, to change that.
|
|
34
|
+
|
|
35
|
+
## Serve it
|
|
36
|
+
|
|
37
|
+
The runtime loads from ESM or CommonJS and needs only the client.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const { createJsonApiMcp } = require('@haddowg/json-api-mcp')
|
|
41
|
+
|
|
42
|
+
const mcp = createJsonApiMcp({ model: require('./mcp/v5.mcp.json') })
|
|
43
|
+
const session = await mcp.forRequest({ grantedScopes: token.scopes, context: { token } })
|
|
44
|
+
session.tools // answer tools/list with these
|
|
45
|
+
await session.callTool('albums_list', { sort: ['-releasedAt'], pageSize: 5 })
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Scope filtering counts only the security requirements a caller can meet with its credential
|
|
49
|
+
schemes, the document's `oauth2` schemes unless you pass `credentialSchemes`. Scopes, feature
|
|
50
|
+
gates, headers and error hints come from optional hooks: `scopeMatcher`, `capabilities`,
|
|
51
|
+
`includeOperation`, `decorateTool`, `requestInit` and `mapError`. See the
|
|
52
|
+
[MCP tools guide](https://haddowg.github.io/json-api-ts/mcp/).
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { n as WriteModelOptions } from "./generate-CuWnYJUB.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/cli.d.ts
|
|
4
|
+
declare const USAGE = "Usage: json-api-mcp --input <url|file> --output <file> [--default-page-size <n>] [--include-depth <n|all>] [--check]";
|
|
5
|
+
/** Read the command line into generator options. */
|
|
6
|
+
declare function parseArgs(argv: readonly string[]): Partial<WriteModelOptions>;
|
|
7
|
+
/** Run the CLI; resolves to the process exit code. */
|
|
8
|
+
declare function main(argv: readonly string[]): Promise<number>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { USAGE, main, parseArgs };
|
|
11
|
+
//# sourceMappingURL=cli.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.mts","names":[],"sources":["../src/cli.ts"],"mappings":";;;cAKa,KAAA;AAAb;AAAA,iBAIgB,SAAA,CAAU,IAAA,sBAA0B,OAAO,CAAC,iBAAA;;iBA8BtC,IAAA,CAAK,IAAA,sBAA0B,OAAO"}
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { r as writeMcpModel } from "./generate-CiLuqQJ0.mjs";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
//#region src/cli.ts
|
|
6
|
+
const USAGE = "Usage: json-api-mcp --input <url|file> --output <file> [--default-page-size <n>] [--include-depth <n|all>] [--check]";
|
|
7
|
+
/** Read the command line into generator options. */
|
|
8
|
+
function parseArgs(argv) {
|
|
9
|
+
const options = {};
|
|
10
|
+
for (let i = 0; i < argv.length; i++) {
|
|
11
|
+
const arg = argv[i];
|
|
12
|
+
if (arg === "--check") {
|
|
13
|
+
options.check = true;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const next = argv[i + 1];
|
|
17
|
+
if (next === void 0) continue;
|
|
18
|
+
if (arg === "--input") {
|
|
19
|
+
options.input = next;
|
|
20
|
+
i++;
|
|
21
|
+
} else if (arg === "--output") {
|
|
22
|
+
options.output = next;
|
|
23
|
+
i++;
|
|
24
|
+
} else if (arg === "--default-page-size") {
|
|
25
|
+
options.defaultPageSize = Number(next);
|
|
26
|
+
i++;
|
|
27
|
+
} else if (arg === "--include-depth") {
|
|
28
|
+
options.includeDepth = next === "all" ? null : Number(next);
|
|
29
|
+
i++;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return options;
|
|
33
|
+
}
|
|
34
|
+
/** Run the CLI; resolves to the process exit code. */
|
|
35
|
+
async function main(argv) {
|
|
36
|
+
const options = parseArgs(argv);
|
|
37
|
+
if (options.input === void 0 || options.output === void 0) {
|
|
38
|
+
console.error(USAGE);
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
if (options.defaultPageSize !== void 0 && !(Number.isInteger(options.defaultPageSize) && options.defaultPageSize > 0)) {
|
|
42
|
+
console.error("--default-page-size takes a positive whole number");
|
|
43
|
+
return 1;
|
|
44
|
+
}
|
|
45
|
+
if (typeof options.includeDepth === "number" && !(Number.isInteger(options.includeDepth) && options.includeDepth >= 0)) {
|
|
46
|
+
console.error("--include-depth takes a whole number of 0 or more, or all");
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const result = await writeMcpModel(options);
|
|
51
|
+
if (options.check === true) {
|
|
52
|
+
if (!result.upToDate) {
|
|
53
|
+
console.error(`[json-api-mcp] ${result.path} is out of date with ${options.input}; run json-api-mcp without --check to regenerate it.`);
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
console.error(`ok ${result.path}`);
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
console.error(`[json-api-mcp] wrote ${result.path}`);
|
|
60
|
+
return 0;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error(`[json-api-mcp] ${error instanceof Error ? error.message : String(error)}`);
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const invoked = process.argv[1];
|
|
67
|
+
if (invoked !== void 0 && realpathSync(invoked) === realpathSync(fileURLToPath(import.meta.url))) process.exitCode = await main(process.argv.slice(2));
|
|
68
|
+
//#endregion
|
|
69
|
+
export { USAGE, main, parseArgs };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=cli.mjs.map
|
package/dist/cli.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { realpathSync } from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport { writeMcpModel, type WriteModelOptions } from './generate'\n\nexport const USAGE =\n 'Usage: json-api-mcp --input <url|file> --output <file> [--default-page-size <n>] [--include-depth <n|all>] [--check]'\n\n/** Read the command line into generator options. */\nexport function parseArgs(argv: readonly string[]): Partial<WriteModelOptions> {\n const options: Partial<WriteModelOptions> = {}\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i]\n if (arg === '--check') {\n options.check = true\n continue\n }\n const next = argv[i + 1]\n if (next === undefined) {\n continue\n }\n if (arg === '--input') {\n options.input = next\n i++\n } else if (arg === '--output') {\n options.output = next\n i++\n } else if (arg === '--default-page-size') {\n options.defaultPageSize = Number(next)\n i++\n } else if (arg === '--include-depth') {\n options.includeDepth = next === 'all' ? null : Number(next)\n i++\n }\n }\n return options\n}\n\n/** Run the CLI; resolves to the process exit code. */\nexport async function main(argv: readonly string[]): Promise<number> {\n const options = parseArgs(argv)\n if (options.input === undefined || options.output === undefined) {\n console.error(USAGE)\n return 1\n }\n if (\n options.defaultPageSize !== undefined &&\n !(Number.isInteger(options.defaultPageSize) && options.defaultPageSize > 0)\n ) {\n console.error('--default-page-size takes a positive whole number')\n return 1\n }\n if (\n typeof options.includeDepth === 'number' &&\n !(Number.isInteger(options.includeDepth) && options.includeDepth >= 0)\n ) {\n console.error('--include-depth takes a whole number of 0 or more, or all')\n return 1\n }\n try {\n const result = await writeMcpModel(options as WriteModelOptions)\n if (options.check === true) {\n if (!result.upToDate) {\n console.error(\n `[json-api-mcp] ${result.path} is out of date with ${options.input}; run json-api-mcp without --check to regenerate it.`,\n )\n return 1\n }\n console.error(`ok ${result.path}`)\n return 0\n }\n console.error(`[json-api-mcp] wrote ${result.path}`)\n return 0\n } catch (error) {\n console.error(`[json-api-mcp] ${error instanceof Error ? error.message : String(error)}`)\n return 1\n }\n}\n\n// A package manager runs the bin through a symlink, so compare real paths.\nconst invoked = process.argv[1]\nif (\n invoked !== undefined &&\n realpathSync(invoked) === realpathSync(fileURLToPath(import.meta.url))\n) {\n process.exitCode = await main(process.argv.slice(2))\n}\n"],"mappings":";;;;;AAKA,MAAa,QACX;;AAGF,SAAgB,UAAU,MAAqD;CAC7E,MAAM,UAAsC,CAAC;CAC7C,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,MAAM,KAAK;EACjB,IAAI,QAAQ,WAAW;GACrB,QAAQ,QAAQ;GAChB;EACF;EACA,MAAM,OAAO,KAAK,IAAI;EACtB,IAAI,SAAS,KAAA,GACX;EAEF,IAAI,QAAQ,WAAW;GACrB,QAAQ,QAAQ;GAChB;EACF,OAAO,IAAI,QAAQ,YAAY;GAC7B,QAAQ,SAAS;GACjB;EACF,OAAO,IAAI,QAAQ,uBAAuB;GACxC,QAAQ,kBAAkB,OAAO,IAAI;GACrC;EACF,OAAO,IAAI,QAAQ,mBAAmB;GACpC,QAAQ,eAAe,SAAS,QAAQ,OAAO,OAAO,IAAI;GAC1D;EACF;CACF;CACA,OAAO;AACT;;AAGA,eAAsB,KAAK,MAA0C;CACnE,MAAM,UAAU,UAAU,IAAI;CAC9B,IAAI,QAAQ,UAAU,KAAA,KAAa,QAAQ,WAAW,KAAA,GAAW;EAC/D,QAAQ,MAAM,KAAK;EACnB,OAAO;CACT;CACA,IACE,QAAQ,oBAAoB,KAAA,KAC5B,EAAE,OAAO,UAAU,QAAQ,eAAe,KAAK,QAAQ,kBAAkB,IACzE;EACA,QAAQ,MAAM,mDAAmD;EACjE,OAAO;CACT;CACA,IACE,OAAO,QAAQ,iBAAiB,YAChC,EAAE,OAAO,UAAU,QAAQ,YAAY,KAAK,QAAQ,gBAAgB,IACpE;EACA,QAAQ,MAAM,2DAA2D;EACzE,OAAO;CACT;CACA,IAAI;EACF,MAAM,SAAS,MAAM,cAAc,OAA4B;EAC/D,IAAI,QAAQ,UAAU,MAAM;GAC1B,IAAI,CAAC,OAAO,UAAU;IACpB,QAAQ,MACN,kBAAkB,OAAO,KAAK,uBAAuB,QAAQ,MAAM,qDACrE;IACA,OAAO;GACT;GACA,QAAQ,MAAM,QAAQ,OAAO,MAAM;GACnC,OAAO;EACT;EACA,QAAQ,MAAM,wBAAwB,OAAO,MAAM;EACnD,OAAO;CACT,SAAS,OAAO;EACd,QAAQ,MAAM,kBAAkB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAAG;EACxF,OAAO;CACT;AACF;AAGA,MAAM,UAAU,QAAQ,KAAK;AAC7B,IACE,YAAY,KAAA,KACZ,aAAa,OAAO,MAAM,aAAa,cAAc,OAAO,KAAK,GAAG,CAAC,GAErE,QAAQ,WAAW,MAAM,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC"}
|