@dimassetoid/openapi-mcp 0.1.0 → 0.2.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/README.md +51 -40
- package/dist/cli/update.d.ts +38 -0
- package/dist/cli/update.js +235 -0
- package/dist/engine/example-generator.js +2 -12
- package/dist/engine/index-builder.js +4 -28
- package/dist/engine/index.d.ts +4 -2
- package/dist/engine/index.js +3 -1
- package/dist/engine/lazy-expander.d.ts +37 -0
- package/dist/engine/lazy-expander.js +235 -0
- package/dist/engine/openapi-utils.d.ts +13 -0
- package/dist/engine/openapi-utils.js +48 -0
- package/dist/engine/query-sandbox.d.ts +8 -0
- package/dist/engine/query-sandbox.js +2 -0
- package/dist/engine/schema-index.js +2 -8
- package/dist/engine/spec-diagnostics.js +60 -19
- package/dist/engine/spec-diff.d.ts +1 -0
- package/dist/engine/spec-diff.js +25 -27
- package/dist/engine/spec-loader.d.ts +42 -1
- package/dist/engine/spec-loader.js +137 -93
- package/dist/index.d.ts +12 -0
- package/dist/index.js +79 -1
- package/dist/mcp/prompts.js +5 -5
- package/dist/mcp/resources.d.ts +5 -2
- package/dist/mcp/resources.js +47 -27
- package/dist/mcp/server.d.ts +46 -1
- package/dist/mcp/server.js +443 -56
- package/dist/telemetry/telemetry.d.ts +90 -0
- package/dist/telemetry/telemetry.js +299 -0
- package/docs/feature/README.md +18 -30
- package/docs/feature/getting-started.md +46 -10
- package/docs/feature/index-and-prompts.md +13 -10
- package/docs/feature/openapi-query.md +16 -11
- package/docs/feature/spec-loader.md +9 -8
- package/package.json +2 -2
- package/skills/use-openapi-mcp/SKILL.md +18 -17
package/README.md
CHANGED
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
|
|
12
12
|
## Key Capabilities
|
|
13
13
|
|
|
14
|
-
- **Monorepo
|
|
15
|
-
- **Indexed Endpoints &
|
|
16
|
-
- **Schema Index & Reverse References (`openapi://schemas/index`, `openapi://schemas/search`)** — Lists `components.schemas` / `definitions` with required fields, properties, `unusedSchemas`, source locations, and reverse `usedBy` operation references.
|
|
17
|
-
- **Single-Pass Contract Diagnostics (`openapi://spec/diagnostics`, `openapi-mcp check`)** — Reports broken `$ref`s, duplicate `operationId`s, undeclared path parameters, unknown security schemes,
|
|
18
|
-
- **Sandboxed Query Engine (`openapi_query`)** — Runs read-only JavaScript in QuickJS WASM against frozen `spec` and built-in `helpers` (`helpers.op`, `helpers.example`, `helpers.schemaRefs`).
|
|
19
|
-
- **Semantic Contract Diff (`openapi_diff`, `openapi-mcp diff`)** — Compares two local specifications and classifies changes into `breaking` and `nonBreaking
|
|
14
|
+
- **Monorepo & Dynamic Root Discovery (`openapi://specs/catalog`, `openapi_inspect`)** — Scans workspaces for OpenAPI entry files while skipping symlinks, unreadable directories (`EACCES`/`EPERM`), and build or dependency folders (`node_modules`, `vendor`, `dist`, `.git`, etc.). Supports MCP `roots/list` auto-binding (when `--root` is not pinned) plus per-request `?root=`/`root` overrides.
|
|
15
|
+
- **Indexed Endpoints & Lazy Subtree Expansion (`openapi_inspect`, `openapi://endpoints/index`, `openapi://endpoints/search`)** — Summarizes HTTP methods, paths, `2xx`/`4xx`/`5xx` status codes, error bodies, auth schemes, deprecation flags, and `{ file, line }` source locations (`openapi_inspect({ target: "endpoints" })` uses $O(\text{endpoints})$ lazy loading via `buildRawEndpointSummary`, while `openapi://endpoints/*` loads the full `$ref`-validated snapshot), plus lazy single-subtree `$ref` expansion via `openapi_inspect({ pointer: "/paths/~1users/get" })`.
|
|
16
|
+
- **Schema Index & Reverse References (`openapi://schemas/index`, `openapi://schemas/search`, `openapi_inspect`)** — Lists `components.schemas` / `definitions` with required fields, properties, `unusedSchemas`, source locations, and reverse `usedBy` operation references.
|
|
17
|
+
- **Single-Pass Contract Diagnostics (`openapi://spec/diagnostics`, `openapi_diagnostics`, `openapi-mcp check`)** — Reports broken `$ref`s, duplicate `operationId`s, undeclared path parameters (including external `$ref`s), unknown security schemes, missing error contracts, and protected operations missing `401`/`403` responses in one pass.
|
|
18
|
+
- **Sandboxed Query Engine (`openapi_query`)** — Runs read-only JavaScript in QuickJS WASM against frozen `spec` and built-in `helpers` (`helpers.op`, `helpers.example`, `helpers.schemaRefs`, `helpers.meta`).
|
|
19
|
+
- **Semantic Contract Diff (`openapi_diff`, `openapi-mcp diff`)** — Compares two local specifications and classifies changes into `breaking` and `nonBreaking`, preserving all `breaking` findings even when `nonBreaking` exceeds the default `16 KiB` budget (via graceful compaction or `include_non_breaking: false`).
|
|
20
20
|
- **MCP Prompts & Agent Skill** — Ships four guided prompts (`sync-frontend-api`, `audit-error-contracts`, `review-breaking-changes`, `generate-test-fixtures`) and a portable Agent Skill at [skills/use-openapi-mcp/SKILL.md](skills/use-openapi-mcp/SKILL.md).
|
|
21
21
|
|
|
22
22
|
## Installation
|
|
@@ -59,55 +59,69 @@ bunx @dimassetoid/openapi-mcp serve
|
|
|
59
59
|
|
|
60
60
|
## Quick Start
|
|
61
61
|
|
|
62
|
-
### MCP Client Setup
|
|
62
|
+
### MCP Client Setup (4 Supported Harnesses)
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
Only **Antigravity**, **Claude Code**, **Codex**, and **OpenCode** are supported. Omit `--root` to auto-bind via MCP `roots/list` (or pass `root` per call), or pin `--root` to enforce a workspace boundary:
|
|
65
|
+
|
|
66
|
+
**Antigravity** (`~/.gemini/config/mcp_config.json` / `~/.gemini/antigravity/mcp_config.json` / `~/.gemini/antigravity-cli/mcp_config.json`) & **Claude Code** (`.mcp.json`):
|
|
65
67
|
|
|
66
68
|
```json
|
|
67
69
|
{
|
|
68
70
|
"mcpServers": {
|
|
69
71
|
"openapi-mcp": {
|
|
70
72
|
"command": "openapi-mcp",
|
|
71
|
-
"args": ["serve"
|
|
73
|
+
"args": ["serve"]
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
```
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
**Codex** (`.codex/config.toml`):
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
```toml
|
|
82
|
+
[mcp_servers.openapi-mcp]
|
|
83
|
+
command = "openapi-mcp"
|
|
84
|
+
args = ["serve"]
|
|
85
|
+
```
|
|
80
86
|
|
|
81
|
-
|
|
87
|
+
**OpenCode** (`opencode.json`):
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"mcp": {
|
|
92
|
+
"openapi-mcp": {
|
|
93
|
+
"type": "local",
|
|
94
|
+
"command": ["openapi-mcp", "serve"]
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
82
99
|
|
|
83
|
-
|
|
100
|
+
Install the portable Agent Skill into `.agents/skills/use-openapi-mcp/SKILL.md` so all harnesses can discover it globally:
|
|
84
101
|
|
|
85
102
|
```sh
|
|
86
|
-
openapi-mcp
|
|
87
|
-
openapi-mcp diff openapi.yml openapi-v2.yml --fail-on-breaking
|
|
103
|
+
mkdir -p .agents/skills/use-openapi-mcp && cp skills/use-openapi-mcp/SKILL.md .agents/skills/use-openapi-mcp/SKILL.md
|
|
88
104
|
```
|
|
89
105
|
|
|
90
|
-
|
|
106
|
+
Verify the installation and ask your agent:
|
|
91
107
|
|
|
92
|
-
```
|
|
93
|
-
openapi-mcp
|
|
108
|
+
```sh
|
|
109
|
+
openapi-mcp check --root /path/to/repo
|
|
94
110
|
```
|
|
95
111
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
| `-h, --help` | Show help message (written to `stderr`) |
|
|
110
|
-
| `-v, --version` | Show version number (written to `stderr`) |
|
|
112
|
+
> Which endpoint creates an order, what does its `422` validation schema look like, and what is a valid example payload?
|
|
113
|
+
|
|
114
|
+
### CLI Quick Reference
|
|
115
|
+
|
|
116
|
+
```sh
|
|
117
|
+
openapi-mcp serve [--root <dir>] [--spec <path>]
|
|
118
|
+
openapi-mcp check --root . --spec openapi.yml --strict
|
|
119
|
+
openapi-mcp diff openapi.yml openapi-v2.yml --fail-on-breaking
|
|
120
|
+
openapi-mcp stats [--root <dir>] [--days <N>] [--json]
|
|
121
|
+
openapi-mcp update [version] [--check] [--json]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
See [Getting Started & CLI Reference](docs/feature/getting-started.md#cli-reference) for the full option table (`--json`, `-h`/`--help`, `-v`/`--version`) and monorepo setup.
|
|
111
125
|
|
|
112
126
|
## Documentation
|
|
113
127
|
|
|
@@ -115,18 +129,15 @@ openapi-mcp <command> [options]
|
|
|
115
129
|
- [Getting Started, MCP Setup & CLI Reference](docs/feature/getting-started.md)
|
|
116
130
|
- [Specification Loader, `$ref` Resolution & Source Mapping](docs/feature/spec-loader.md)
|
|
117
131
|
- [Indexes, Diagnostics & Workflow Prompts](docs/feature/index-and-prompts.md)
|
|
118
|
-
- [Code Mode Query (`openapi_query`) & Semantic Diff (`openapi_diff`)](docs/feature/openapi-query.md)
|
|
132
|
+
- [Code Mode Query (`openapi_query`), Diagnostics, Inspect & Semantic Diff (`openapi_diff`)](docs/feature/openapi-query.md)
|
|
119
133
|
- [Agent Skill Playbook (`use-openapi-mcp`)](skills/use-openapi-mcp/SKILL.md)
|
|
120
134
|
|
|
121
135
|
## Development
|
|
122
136
|
|
|
137
|
+
Run the local verification suite (see [Getting Started](docs/feature/getting-started.md#development--verification) for all packaging and binary targets):
|
|
138
|
+
|
|
123
139
|
```sh
|
|
124
|
-
bun install
|
|
125
|
-
bun run typecheck
|
|
126
|
-
bun test
|
|
127
|
-
bun run build
|
|
128
|
-
bun run compile:all # Build standalone binaries into release/
|
|
129
|
-
sh scripts/verify-package.sh # Verify npm tarball, TypeScript consumer, and stdio smoke test
|
|
140
|
+
bun install && bun run typecheck && bun test && bun run build
|
|
130
141
|
```
|
|
131
142
|
|
|
132
143
|
## License
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
export type InstallChannel = 'standalone' | 'bun-global' | 'npm-global';
|
|
3
|
+
export interface SelfUpdateOptions {
|
|
4
|
+
check?: boolean;
|
|
5
|
+
version?: string;
|
|
6
|
+
json?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface SelfUpdateResult {
|
|
9
|
+
package_name: string;
|
|
10
|
+
github_repo: string;
|
|
11
|
+
channel: InstallChannel;
|
|
12
|
+
current_version: string;
|
|
13
|
+
target_version: string | null;
|
|
14
|
+
update_available: boolean;
|
|
15
|
+
updated: boolean;
|
|
16
|
+
message: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SelfUpdateDeps {
|
|
19
|
+
execPath?: string;
|
|
20
|
+
entryPath?: string;
|
|
21
|
+
platform?: NodeJS.Platform;
|
|
22
|
+
arch?: string;
|
|
23
|
+
fetchFn?: typeof fetch;
|
|
24
|
+
runCommandFn?: (bin: string, args: string[]) => {
|
|
25
|
+
status: number;
|
|
26
|
+
stderr?: string;
|
|
27
|
+
stdout?: string;
|
|
28
|
+
};
|
|
29
|
+
fsOps?: Pick<typeof fs, 'writeFileSync' | 'chmodSync' | 'renameSync' | 'unlinkSync' | 'existsSync'>;
|
|
30
|
+
timeoutMs?: number;
|
|
31
|
+
}
|
|
32
|
+
export declare function normalizeVersion(raw: string): string;
|
|
33
|
+
export declare function parseSemver(v: string): [number, number, number];
|
|
34
|
+
export declare function isNewerVersion(current: string, latest: string): boolean;
|
|
35
|
+
export declare function detectInstallChannel(execPath?: string, entryPath?: string): InstallChannel;
|
|
36
|
+
export declare function resolveReleaseAssetName(binaryPrefix: string, platform?: NodeJS.Platform, arch?: string): string;
|
|
37
|
+
export declare function parseChecksumForAsset(checksumsText: string, assetName: string): string | null;
|
|
38
|
+
export declare function runOpenApiMcpUpdate(options?: SelfUpdateOptions, deps?: SelfUpdateDeps): Promise<SelfUpdateResult>;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import { OPENAPI_MCP_VERSION } from '../mcp/server.js';
|
|
6
|
+
const PACKAGE_NAME = '@dimassetoid/openapi-mcp';
|
|
7
|
+
const GITHUB_REPO = 'Shironim/openapi-mcp';
|
|
8
|
+
const BINARY_PREFIX = 'openapi-mcp';
|
|
9
|
+
export function normalizeVersion(raw) {
|
|
10
|
+
return raw.trim().replace(/^v/, '');
|
|
11
|
+
}
|
|
12
|
+
export function parseSemver(v) {
|
|
13
|
+
const clean = normalizeVersion(v).split('-')[0].split('+')[0];
|
|
14
|
+
const parts = clean.split('.').map((n) => parseInt(n, 10));
|
|
15
|
+
return [
|
|
16
|
+
Number.isFinite(parts[0]) ? parts[0] : 0,
|
|
17
|
+
Number.isFinite(parts[1]) ? parts[1] : 0,
|
|
18
|
+
Number.isFinite(parts[2]) ? parts[2] : 0,
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
export function isNewerVersion(current, latest) {
|
|
22
|
+
const [cMaj, cMin, cPatch] = parseSemver(current);
|
|
23
|
+
const [lMaj, lMin, lPatch] = parseSemver(latest);
|
|
24
|
+
if (lMaj !== cMaj)
|
|
25
|
+
return lMaj > cMaj;
|
|
26
|
+
if (lMin !== cMin)
|
|
27
|
+
return lMin > cMin;
|
|
28
|
+
return lPatch > cPatch;
|
|
29
|
+
}
|
|
30
|
+
export function detectInstallChannel(execPath = process.execPath, entryPath = process.argv[1] ?? '') {
|
|
31
|
+
const execBase = path.basename(execPath).toLowerCase();
|
|
32
|
+
const isRuntime = execBase === 'bun' ||
|
|
33
|
+
execBase === 'bun.exe' ||
|
|
34
|
+
execBase === 'node' ||
|
|
35
|
+
execBase === 'node.exe';
|
|
36
|
+
if (!isRuntime || entryPath.startsWith('/$bunfs/') || entryPath.startsWith('B:/~BUN/')) {
|
|
37
|
+
return 'standalone';
|
|
38
|
+
}
|
|
39
|
+
const normalizedEntry = entryPath.replace(/\\/g, '/');
|
|
40
|
+
if (execBase.startsWith('bun') || normalizedEntry.includes('/.bun/install/global/')) {
|
|
41
|
+
return 'bun-global';
|
|
42
|
+
}
|
|
43
|
+
return 'npm-global';
|
|
44
|
+
}
|
|
45
|
+
export function resolveReleaseAssetName(binaryPrefix, platform = process.platform, arch = process.arch) {
|
|
46
|
+
const osMap = {
|
|
47
|
+
linux: 'linux',
|
|
48
|
+
darwin: 'darwin',
|
|
49
|
+
win32: 'windows',
|
|
50
|
+
};
|
|
51
|
+
const archMap = { x64: 'x64', arm64: 'arm64' };
|
|
52
|
+
const targetOs = osMap[platform];
|
|
53
|
+
const targetArch = archMap[arch];
|
|
54
|
+
if (!targetOs || !targetArch) {
|
|
55
|
+
throw new Error(`Unsupported platform for standalone binary update: ${platform}/${arch}`);
|
|
56
|
+
}
|
|
57
|
+
if (platform === 'win32' && targetArch !== 'x64') {
|
|
58
|
+
throw new Error(`Unsupported Windows architecture: ${arch}`);
|
|
59
|
+
}
|
|
60
|
+
const ext = platform === 'win32' ? '.exe' : '';
|
|
61
|
+
return `${binaryPrefix}-${targetOs}-${targetArch}${ext}`;
|
|
62
|
+
}
|
|
63
|
+
export function parseChecksumForAsset(checksumsText, assetName) {
|
|
64
|
+
for (const line of checksumsText.split(/\r?\n/)) {
|
|
65
|
+
const trimmed = line.trim();
|
|
66
|
+
if (!trimmed)
|
|
67
|
+
continue;
|
|
68
|
+
const match = trimmed.match(/^([a-fA-F0-9]{64})\s+\*?(.+)$/);
|
|
69
|
+
if (match && path.basename(match[2].trim()) === assetName) {
|
|
70
|
+
return match[1].toLowerCase();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
async function fetchLatestNpmVersion(pkgName, fetchFn, timeoutMs) {
|
|
76
|
+
const encoded = pkgName.startsWith('@')
|
|
77
|
+
? `@${encodeURIComponent(pkgName.slice(1))}`
|
|
78
|
+
: encodeURIComponent(pkgName);
|
|
79
|
+
const controller = new AbortController();
|
|
80
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
81
|
+
try {
|
|
82
|
+
const res = await fetchFn(`https://registry.npmjs.org/${encoded}/latest`, {
|
|
83
|
+
signal: controller.signal,
|
|
84
|
+
headers: { Accept: 'application/json', 'User-Agent': `${BINARY_PREFIX}-self-update` },
|
|
85
|
+
});
|
|
86
|
+
if (!res.ok)
|
|
87
|
+
return null;
|
|
88
|
+
const data = (await res.json());
|
|
89
|
+
return typeof data.version === 'string' && data.version.trim()
|
|
90
|
+
? normalizeVersion(data.version)
|
|
91
|
+
: null;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
clearTimeout(timer);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function fetchLatestGithubReleaseVersion(repo, fetchFn, timeoutMs) {
|
|
101
|
+
const controller = new AbortController();
|
|
102
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
103
|
+
try {
|
|
104
|
+
const res = await fetchFn(`https://api.github.com/repos/${repo}/releases/latest`, {
|
|
105
|
+
signal: controller.signal,
|
|
106
|
+
headers: { Accept: 'application/vnd.github+json', 'User-Agent': `${BINARY_PREFIX}-self-update` },
|
|
107
|
+
});
|
|
108
|
+
if (!res.ok)
|
|
109
|
+
return null;
|
|
110
|
+
const data = (await res.json());
|
|
111
|
+
return typeof data.tag_name === 'string' && data.tag_name.trim()
|
|
112
|
+
? normalizeVersion(data.tag_name)
|
|
113
|
+
: null;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
clearTimeout(timer);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export async function runOpenApiMcpUpdate(options = {}, deps = {}) {
|
|
123
|
+
const execPath = deps.execPath ?? process.execPath;
|
|
124
|
+
const entryPath = deps.entryPath ?? process.argv[1] ?? '';
|
|
125
|
+
const platform = deps.platform ?? process.platform;
|
|
126
|
+
const arch = deps.arch ?? process.arch;
|
|
127
|
+
const fetchFn = deps.fetchFn ?? fetch;
|
|
128
|
+
const fsOps = deps.fsOps ?? fs;
|
|
129
|
+
const timeoutMs = deps.timeoutMs ?? 15000;
|
|
130
|
+
const channel = detectInstallChannel(execPath, entryPath);
|
|
131
|
+
const requestedVersion = options.version ? normalizeVersion(options.version) : null;
|
|
132
|
+
const targetVersion = requestedVersion ??
|
|
133
|
+
(channel === 'standalone'
|
|
134
|
+
? await fetchLatestGithubReleaseVersion(GITHUB_REPO, fetchFn, timeoutMs)
|
|
135
|
+
: await fetchLatestNpmVersion(PACKAGE_NAME, fetchFn, timeoutMs));
|
|
136
|
+
if (!targetVersion) {
|
|
137
|
+
throw new Error(`Unable to resolve latest version for ${PACKAGE_NAME} (${channel}).`);
|
|
138
|
+
}
|
|
139
|
+
const updateAvailable = requestedVersion
|
|
140
|
+
? requestedVersion !== normalizeVersion(OPENAPI_MCP_VERSION)
|
|
141
|
+
: isNewerVersion(OPENAPI_MCP_VERSION, targetVersion);
|
|
142
|
+
if (options.check || !updateAvailable) {
|
|
143
|
+
return {
|
|
144
|
+
package_name: PACKAGE_NAME,
|
|
145
|
+
github_repo: GITHUB_REPO,
|
|
146
|
+
channel,
|
|
147
|
+
current_version: OPENAPI_MCP_VERSION,
|
|
148
|
+
target_version: targetVersion,
|
|
149
|
+
update_available: updateAvailable,
|
|
150
|
+
updated: false,
|
|
151
|
+
message: updateAvailable
|
|
152
|
+
? `Update available: v${OPENAPI_MCP_VERSION} -> v${targetVersion} (${channel})`
|
|
153
|
+
: `Already up to date (v${OPENAPI_MCP_VERSION})`,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (channel === 'standalone') {
|
|
157
|
+
const assetName = resolveReleaseAssetName(BINARY_PREFIX, platform, arch);
|
|
158
|
+
const baseUrl = `https://github.com/${GITHUB_REPO}/releases/download/v${targetVersion}`;
|
|
159
|
+
const checksumRes = await fetchFn(`${baseUrl}/checksums.txt`);
|
|
160
|
+
if (!checksumRes.ok) {
|
|
161
|
+
throw new Error(`Failed to fetch checksums.txt for v${targetVersion} (HTTP ${checksumRes.status}).`);
|
|
162
|
+
}
|
|
163
|
+
const expectedHash = parseChecksumForAsset(await checksumRes.text(), assetName);
|
|
164
|
+
if (!expectedHash) {
|
|
165
|
+
throw new Error(`Checksum entry for ${assetName} not found in v${targetVersion} checksums.txt.`);
|
|
166
|
+
}
|
|
167
|
+
const binRes = await fetchFn(`${baseUrl}/${assetName}`);
|
|
168
|
+
if (!binRes.ok) {
|
|
169
|
+
throw new Error(`Failed to download ${assetName} for v${targetVersion} (HTTP ${binRes.status}).`);
|
|
170
|
+
}
|
|
171
|
+
const bytes = Buffer.from(await binRes.arrayBuffer());
|
|
172
|
+
const actualHash = createHash('sha256').update(bytes).digest('hex').toLowerCase();
|
|
173
|
+
if (actualHash !== expectedHash) {
|
|
174
|
+
throw new Error(`SHA-256 checksum mismatch for ${assetName}: expected ${expectedHash}, got ${actualHash}.`);
|
|
175
|
+
}
|
|
176
|
+
const tmpPath = `${execPath}.tmp-${process.pid}`;
|
|
177
|
+
try {
|
|
178
|
+
fsOps.writeFileSync(tmpPath, bytes);
|
|
179
|
+
if (platform !== 'win32') {
|
|
180
|
+
fsOps.chmodSync(tmpPath, 0o755);
|
|
181
|
+
}
|
|
182
|
+
else if (fsOps.existsSync(execPath)) {
|
|
183
|
+
const oldPath = `${execPath}.old`;
|
|
184
|
+
if (fsOps.existsSync(oldPath))
|
|
185
|
+
fsOps.unlinkSync(oldPath);
|
|
186
|
+
fsOps.renameSync(execPath, oldPath);
|
|
187
|
+
}
|
|
188
|
+
fsOps.renameSync(tmpPath, execPath);
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
if (fsOps.existsSync(tmpPath)) {
|
|
192
|
+
try {
|
|
193
|
+
fsOps.unlinkSync(tmpPath);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
// ignore cleanup failure
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
throw err;
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
package_name: PACKAGE_NAME,
|
|
203
|
+
github_repo: GITHUB_REPO,
|
|
204
|
+
channel,
|
|
205
|
+
current_version: OPENAPI_MCP_VERSION,
|
|
206
|
+
target_version: targetVersion,
|
|
207
|
+
update_available: true,
|
|
208
|
+
updated: true,
|
|
209
|
+
message: `Updated ${BINARY_PREFIX} standalone binary to v${targetVersion}`,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const pmBin = channel === 'bun-global' ? 'bun' : 'npm';
|
|
213
|
+
const pmArgs = channel === 'bun-global'
|
|
214
|
+
? ['add', '-g', `${PACKAGE_NAME}@${targetVersion}`]
|
|
215
|
+
: ['install', '-g', `${PACKAGE_NAME}@${targetVersion}`];
|
|
216
|
+
const runCmd = deps.runCommandFn ??
|
|
217
|
+
((bin, args) => {
|
|
218
|
+
const res = spawnSync(bin, args, { encoding: 'utf8' });
|
|
219
|
+
return { status: res.status ?? 1, stdout: res.stdout, stderr: res.stderr };
|
|
220
|
+
});
|
|
221
|
+
const proc = runCmd(pmBin, pmArgs);
|
|
222
|
+
if (proc.status !== 0) {
|
|
223
|
+
throw new Error(`Failed to update via '${pmBin} ${pmArgs.join(' ')}': ${proc.stderr || proc.stdout || `exit code ${proc.status}`}`);
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
package_name: PACKAGE_NAME,
|
|
227
|
+
github_repo: GITHUB_REPO,
|
|
228
|
+
channel,
|
|
229
|
+
current_version: OPENAPI_MCP_VERSION,
|
|
230
|
+
target_version: targetVersion,
|
|
231
|
+
update_available: true,
|
|
232
|
+
updated: true,
|
|
233
|
+
message: `Updated ${PACKAGE_NAME} to v${targetVersion} via ${pmBin}`,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isRecord } from './json.js';
|
|
2
|
+
import { mergeOperationParameters } from './openapi-utils.js';
|
|
2
3
|
import { escapeJsonPointer } from './source-map.js';
|
|
3
4
|
const DEFAULT_MAX_DEPTH = 8;
|
|
4
5
|
const DEFAULT_MAX_NODES = 256;
|
|
@@ -174,18 +175,7 @@ export function getMergedOperation(spec, method, path, sourceLocations) {
|
|
|
174
175
|
const operation = pathItem && isRecord(pathItem[lowerMethod]) ? pathItem[lowerMethod] : undefined;
|
|
175
176
|
if (!pathItem || !operation)
|
|
176
177
|
return null;
|
|
177
|
-
const mergedParams =
|
|
178
|
-
const addParams = (list) => {
|
|
179
|
-
if (!Array.isArray(list))
|
|
180
|
-
return;
|
|
181
|
-
for (const param of list) {
|
|
182
|
-
if (isRecord(param) && typeof param.name === 'string' && typeof param.in === 'string') {
|
|
183
|
-
mergedParams.set(`${param.in}:${param.name}`, param);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
addParams(pathItem.parameters);
|
|
188
|
-
addParams(operation.parameters);
|
|
178
|
+
const mergedParams = mergeOperationParameters(pathItem, operation);
|
|
189
179
|
const effectiveSecurity = Array.isArray(operation.security)
|
|
190
180
|
? operation.security
|
|
191
181
|
: Array.isArray(spec.security)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isRecord } from './json.js';
|
|
2
|
+
import { extractSecuritySchemeNames, extractSpecMetadata, isErrorStatusCode } from './openapi-utils.js';
|
|
2
3
|
import { escapeJsonPointer } from './source-map.js';
|
|
3
4
|
export const HTTP_METHODS = [
|
|
4
5
|
'get',
|
|
@@ -54,24 +55,6 @@ export function searchEndpoints(entries, filters) {
|
|
|
54
55
|
}
|
|
55
56
|
return { endpoints, totalMatches };
|
|
56
57
|
}
|
|
57
|
-
function extractSecuritySchemes(securityField) {
|
|
58
|
-
if (!Array.isArray(securityField))
|
|
59
|
-
return undefined;
|
|
60
|
-
const schemes = new Set();
|
|
61
|
-
for (const requirement of securityField) {
|
|
62
|
-
if (!isRecord(requirement))
|
|
63
|
-
continue;
|
|
64
|
-
for (const schemeName of Object.keys(requirement)) {
|
|
65
|
-
if (schemeName.trim())
|
|
66
|
-
schemes.add(schemeName);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return [...schemes].sort();
|
|
70
|
-
}
|
|
71
|
-
function isErrorStatusCode(code) {
|
|
72
|
-
const normalized = code.trim().toLowerCase();
|
|
73
|
-
return /^[45](?:\d{2}|xx)$/.test(normalized);
|
|
74
|
-
}
|
|
75
58
|
function extractSummary(operation) {
|
|
76
59
|
if (typeof operation.summary === 'string' && operation.summary.trim()) {
|
|
77
60
|
return operation.summary.trim().replace(/\s+/g, ' ');
|
|
@@ -92,16 +75,9 @@ function extractSummary(operation) {
|
|
|
92
75
|
* (including all 4xx/5xx error responses) from a resolved OpenAPI specification.
|
|
93
76
|
*/
|
|
94
77
|
export function buildEndpointIndex(spec, specPath, sourceLocations) {
|
|
95
|
-
const
|
|
96
|
-
const title = typeof info.title === 'string' && info.title.trim() ? info.title.trim() : 'Untitled API';
|
|
97
|
-
const version = typeof info.version === 'string' && info.version.trim() ? info.version.trim() : 'unknown';
|
|
98
|
-
const openapiVersion = typeof spec.openapi === 'string'
|
|
99
|
-
? spec.openapi
|
|
100
|
-
: typeof spec.swagger === 'string'
|
|
101
|
-
? spec.swagger
|
|
102
|
-
: 'unknown';
|
|
78
|
+
const { title, version, openapiVersion } = extractSpecMetadata(spec);
|
|
103
79
|
const pathsObj = isRecord(spec.paths) ? spec.paths : {};
|
|
104
|
-
const globalSecurity =
|
|
80
|
+
const globalSecurity = extractSecuritySchemeNames(spec.security);
|
|
105
81
|
const endpoints = [];
|
|
106
82
|
const endpointsMissingErrorContracts = [];
|
|
107
83
|
const allTags = new Set();
|
|
@@ -142,7 +118,7 @@ export function buildEndpointIndex(spec, specPath, sourceLocations) {
|
|
|
142
118
|
? operation.operationId.trim()
|
|
143
119
|
: undefined;
|
|
144
120
|
const deprecated = operation.deprecated === true;
|
|
145
|
-
const opSecurity =
|
|
121
|
+
const opSecurity = extractSecuritySchemeNames(operation.security);
|
|
146
122
|
const effectiveSecurity = opSecurity !== undefined ? opSecurity : globalSecurity;
|
|
147
123
|
const includeSecurity = effectiveSecurity !== undefined && (effectiveSecurity.length > 0 || (opSecurity !== undefined && (globalSecurity?.length ?? 0) > 0));
|
|
148
124
|
const sourceLocation = sourceLocations?.[`/paths/${escapeJsonPointer(pathKey)}/${httpMethod}`];
|
package/dist/engine/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export { DEFAULT_SPEC_CANDIDATES, clearSpecCache, deepFreeze, findOpenApiSpecFile, getSpecCacheStats, loadOpenApiSpec, resolveSafeSpecPath, type FileFingerprint, type LoadOpenApiSpecOptions, type LoadedOpenApiSpec, } from './spec-loader.js';
|
|
1
|
+
export { DEFAULT_SPEC_CANDIDATES, assertWorkspaceRoot, clearSpecCache, deepFreeze, findOpenApiSpecFile, getSpecCacheStats, loadOpenApiSpec, resolveSafeSpecPath, type FileFingerprint, type LoadOpenApiSpecOptions, type LoadedOpenApiSpec, } from './spec-loader.js';
|
|
2
|
+
export { buildRawEndpointSummary, clearLazySpecCache, expandPointerSubtree, loadRawOpenApiDocument, type LazySubtreeExpandResult, type RawOpenApiDocument, } from './lazy-expander.js';
|
|
3
|
+
export { extractSpecMetadata, type SpecMetadataSummary } from './openapi-utils.js';
|
|
2
4
|
export { HTTP_METHODS, buildEndpointIndex, searchEndpoints, type EndpointIndex, type EndpointSearchFilters, type EndpointSummaryItem, } from './index-builder.js';
|
|
3
5
|
export { DEFAULT_IGNORED_DIRS, listWorkspaceSpecs, scanWorkspaceSpecs, type WorkspaceSpecCatalog, } from './spec-catalog.js';
|
|
4
6
|
export { escapeJsonPointer, parseDocumentWithLocations, type ParsedDocumentWithLocations, type SourceLocation, } from './source-map.js';
|
|
5
7
|
export { buildSchemaIndex, searchSchemas, type SchemaIndex, type SchemaSearchFilters, type SchemaSummaryItem, type SchemaUsageRef, } from './schema-index.js';
|
|
6
|
-
export { DEFAULT_SANDBOX_TIMEOUT_MS, runSandboxQuery, validateSandboxCode, type SandboxMetadata, type SandboxQueryOptions, type SandboxQueryResult, } from './query-sandbox.js';
|
|
8
|
+
export { DEFAULT_SANDBOX_TIMEOUT_MS, runSandboxQuery, validateSandboxCode, type SandboxMetadata, type SandboxQueryOptions, type SandboxQueryResult, type SandboxSpecMeta, } from './query-sandbox.js';
|
|
7
9
|
export { generateOperationExamples, generateSchemaExample, getMergedOperation, type ExampleGeneratorOptions, type MergedOperationContract, } from './example-generator.js';
|
|
8
10
|
export { diagnoseOpenApiSpec, type DiagnosticSeverity, type SpecDiagnosticIssue, type SpecDiagnosticsReport, } from './spec-diagnostics.js';
|
|
9
11
|
export { diffOpenApiSpecs, type DiffClassification, type SpecDiffChange, type SpecDiffReport, } from './spec-diff.js';
|
package/dist/engine/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { DEFAULT_SPEC_CANDIDATES, clearSpecCache, deepFreeze, findOpenApiSpecFile, getSpecCacheStats, loadOpenApiSpec, resolveSafeSpecPath, } from './spec-loader.js';
|
|
1
|
+
export { DEFAULT_SPEC_CANDIDATES, assertWorkspaceRoot, clearSpecCache, deepFreeze, findOpenApiSpecFile, getSpecCacheStats, loadOpenApiSpec, resolveSafeSpecPath, } from './spec-loader.js';
|
|
2
|
+
export { buildRawEndpointSummary, clearLazySpecCache, expandPointerSubtree, loadRawOpenApiDocument, } from './lazy-expander.js';
|
|
3
|
+
export { extractSpecMetadata } from './openapi-utils.js';
|
|
2
4
|
export { HTTP_METHODS, buildEndpointIndex, searchEndpoints, } from './index-builder.js';
|
|
3
5
|
export { DEFAULT_IGNORED_DIRS, listWorkspaceSpecs, scanWorkspaceSpecs, } from './spec-catalog.js';
|
|
4
6
|
export { escapeJsonPointer, parseDocumentWithLocations, } from './source-map.js';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type EndpointIndex } from './index-builder.js';
|
|
2
|
+
import { type SourceLocation } from './source-map.js';
|
|
3
|
+
import { type FileFingerprint, type LoadOpenApiSpecOptions, type SpecLimits } from './spec-loader.js';
|
|
4
|
+
export interface RawOpenApiDocument {
|
|
5
|
+
entryPath: string;
|
|
6
|
+
rootDir: string;
|
|
7
|
+
entryDoc: Record<string, unknown>;
|
|
8
|
+
schema31: boolean;
|
|
9
|
+
entryFingerprint: FileFingerprint;
|
|
10
|
+
sourceLocations: Readonly<Record<string, SourceLocation>>;
|
|
11
|
+
parseFile: (canonicalPath: string) => unknown;
|
|
12
|
+
locations: Map<string, string>;
|
|
13
|
+
fromCache: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface LazySubtreeExpandResult {
|
|
16
|
+
pointer: string;
|
|
17
|
+
value: unknown;
|
|
18
|
+
nodeVisits: number;
|
|
19
|
+
expandedBytes: number;
|
|
20
|
+
fromCache: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function clearLazySpecCache(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Loads only the entry OpenAPI file without eagerly expanding nested or sibling $refs.
|
|
25
|
+
* External $ref files are parsed lazily on demand only when touched by a targeted subtree.
|
|
26
|
+
*/
|
|
27
|
+
export declare function loadRawOpenApiDocument(options?: LoadOpenApiSpecOptions): RawOpenApiDocument;
|
|
28
|
+
/**
|
|
29
|
+
* Builds the endpoint summary index from a raw OpenAPI document in O(endpoints) without
|
|
30
|
+
* expanding deep nested schemas on unrelated endpoints.
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildRawEndpointSummary(rawDoc: RawOpenApiDocument): EndpointIndex;
|
|
33
|
+
/**
|
|
34
|
+
* Lazily resolves and expands only the $refs reachable from the given JSON Pointer
|
|
35
|
+
* (e.g. `/paths/~1users/get` or `/components/schemas/Order`).
|
|
36
|
+
*/
|
|
37
|
+
export declare function expandPointerSubtree(rawDoc: RawOpenApiDocument, pointer: string, limits?: SpecLimits): LazySubtreeExpandResult;
|