codex-plugin-doctor 1.60.0 → 1.62.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 +31 -2
- package/dist/core/bounded-http-client.js +1 -0
- package/dist/core/mcp-discovery.d.ts +28 -0
- package/dist/core/mcp-discovery.js +161 -0
- package/dist/core/mcp-tool-catalog.d.ts +36 -0
- package/dist/core/mcp-tool-catalog.js +276 -0
- package/dist/core/mcp-tool-definition.d.ts +14 -0
- package/dist/core/mcp-tool-definition.js +116 -0
- package/dist/core/output-contract.js +73 -0
- package/dist/reporting/render-mcp-discovery-report.d.ts +2 -0
- package/dist/reporting/render-mcp-discovery-report.js +14 -0
- package/dist/reporting/render-mcp-tool-catalog-report.d.ts +2 -0
- package/dist/reporting/render-mcp-tool-catalog-report.js +25 -0
- package/dist/run-cli.d.ts +4 -0
- package/dist/run-cli.js +65 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,6 +81,35 @@ Runtime MCP validation with `--runtime`:
|
|
|
81
81
|
- optional runtime approval gating with a precomputed `doctor runtime-plan` digest
|
|
82
82
|
- optional Docker isolation for local Node.js stdio servers with `--sandbox docker`
|
|
83
83
|
|
|
84
|
+
### MCP Protocol Discovery
|
|
85
|
+
|
|
86
|
+
Inspect an HTTP MCP endpoint's advertised protocol versions using a bounded MCP
|
|
87
|
+
2026-07-28 `server/discover` request:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
codex-plugin-doctor doctor discover https://mcp.example.com/mcp --allow-network
|
|
91
|
+
codex-plugin-doctor doctor discover https://mcp.example.com/mcp --allow-network --json
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
This is an opt-in discovery-only check. A successful result validates the discovery
|
|
95
|
+
response, not full protocol conformance, tool behavior, or compatibility with a
|
|
96
|
+
particular client. Existing `check --runtime` remains on its 2025-11-25 baseline.
|
|
97
|
+
See [MCP Discovery](docs/guides/mcp-discovery.md) for consent, scope, and exit codes.
|
|
98
|
+
|
|
99
|
+
### HTTP MCP Tool Catalog
|
|
100
|
+
|
|
101
|
+
Inspect a modern HTTP MCP server's tool definitions without invoking them:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
codex-plugin-doctor doctor tools https://mcp.example.com/mcp --allow-network --json
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
This opt-in command performs discovery and bounded `tools/list` pagination. It
|
|
108
|
+
reports tool-definition and root-schema shape findings, explicit completion state,
|
|
109
|
+
and partial inspection limits. It does not claim full schema validation, tool
|
|
110
|
+
execution, or client compatibility. Existing `doctor discover` behavior is unchanged.
|
|
111
|
+
See [HTTP MCP Tool Catalog](docs/guides/mcp-tool-catalog.md).
|
|
112
|
+
|
|
84
113
|
### Remote MCP Readiness
|
|
85
114
|
|
|
86
115
|
Remote MCP runtime probing is disabled until you explicitly pass `--runtime --allow-network`. Loopback endpoints also require `--allow-local-network`:
|
|
@@ -499,9 +528,9 @@ jobs:
|
|
|
499
528
|
runs-on: ubuntu-latest
|
|
500
529
|
steps:
|
|
501
530
|
- uses: actions/checkout@v5
|
|
502
|
-
- uses: Esquetta/CodexPluginDoctor@v1.
|
|
531
|
+
- uses: Esquetta/CodexPluginDoctor@v1.62.0
|
|
503
532
|
with:
|
|
504
|
-
version: "1.
|
|
533
|
+
version: "1.62.0"
|
|
505
534
|
path: .
|
|
506
535
|
runtime: "true"
|
|
507
536
|
policy: codex-publish
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type BoundedHttpResponse } from "./bounded-http-client.js";
|
|
2
|
+
import { type RemoteLookup } from "./remote-network-policy.js";
|
|
3
|
+
import type { RemoteMcpRequest } from "./remote-mcp-probe.js";
|
|
4
|
+
import type { Finding } from "../domain/types.js";
|
|
5
|
+
export type McpJsonObject = Record<string, unknown>;
|
|
6
|
+
export interface McpDiscoveryOptions {
|
|
7
|
+
allowNetwork?: boolean;
|
|
8
|
+
allowLocalNetwork?: boolean;
|
|
9
|
+
requestTimeoutMs?: number;
|
|
10
|
+
lookup?: RemoteLookup;
|
|
11
|
+
request?: RemoteMcpRequest;
|
|
12
|
+
}
|
|
13
|
+
export interface McpDiscoveryReport {
|
|
14
|
+
schemaVersion: 1;
|
|
15
|
+
requestedVersion: "2026-07-28";
|
|
16
|
+
scope: "discovery-only";
|
|
17
|
+
status: "discovered" | "unsupported" | "blocked" | "failed";
|
|
18
|
+
supportedVersions: string[];
|
|
19
|
+
findings: Finding[];
|
|
20
|
+
coverage: {
|
|
21
|
+
discovery: "pass" | "fail" | "skipped";
|
|
22
|
+
runtime: "not-tested";
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare function findMcpSseResponse(body: Buffer, requestId?: string): McpJsonObject | null;
|
|
26
|
+
export declare function parseMcpResponse(response: BoundedHttpResponse, requestId?: string): McpJsonObject | null;
|
|
27
|
+
export declare function discoverMcpCapabilities(response: BoundedHttpResponse, requestId?: string): McpJsonObject | null;
|
|
28
|
+
export declare function discoverMcpServer(rawUrl: string, options?: McpDiscoveryOptions): Promise<McpDiscoveryReport>;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { BoundedHttpError, requestBoundedHttp } from "./bounded-http-client.js";
|
|
2
|
+
import { RemoteNetworkPolicyError } from "./remote-network-policy.js";
|
|
3
|
+
import { inspectRemoteMcpUrl } from "./remote-url-policy.js";
|
|
4
|
+
import { packageVersion } from "../version.js";
|
|
5
|
+
const REQUESTED_VERSION = "2026-07-28";
|
|
6
|
+
const REQUEST_ID = "discover-1";
|
|
7
|
+
function finding(id, severity, message, impact, suggestedFix) {
|
|
8
|
+
return { id, severity, message, impact, suggestedFix };
|
|
9
|
+
}
|
|
10
|
+
function report(status, discovery, findings = [], supportedVersions = []) {
|
|
11
|
+
return { schemaVersion: 1, requestedVersion: REQUESTED_VERSION, scope: "discovery-only", status, supportedVersions, findings, coverage: { discovery, runtime: "not-tested" } };
|
|
12
|
+
}
|
|
13
|
+
function isPlainObject(value) {
|
|
14
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
function parseJsonObject(source) {
|
|
17
|
+
try {
|
|
18
|
+
const parsed = JSON.parse(source);
|
|
19
|
+
return isPlainObject(parsed) ? parsed : null;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function mediaType(response) {
|
|
26
|
+
const contentType = response.headers["content-type"];
|
|
27
|
+
const value = Array.isArray(contentType) ? contentType[0] : contentType;
|
|
28
|
+
return typeof value === "string" ? value.split(";", 1)[0]?.trim().toLowerCase() ?? null : null;
|
|
29
|
+
}
|
|
30
|
+
export function findMcpSseResponse(body, requestId = REQUEST_ID) {
|
|
31
|
+
const text = body.toString("utf8").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
32
|
+
let offset = 0;
|
|
33
|
+
while (offset < text.length) {
|
|
34
|
+
const boundary = text.indexOf("\n\n", offset);
|
|
35
|
+
if (boundary === -1)
|
|
36
|
+
return null;
|
|
37
|
+
const data = text.slice(offset, boundary).split("\n")
|
|
38
|
+
.filter((line) => line.startsWith("data:"))
|
|
39
|
+
.map((line) => line.slice(5).replace(/^ /, ""));
|
|
40
|
+
const candidate = data.length === 0 ? null : parseJsonObject(data.join("\n"));
|
|
41
|
+
if (candidate?.id === requestId)
|
|
42
|
+
return candidate;
|
|
43
|
+
offset = boundary + 2;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
export function parseMcpResponse(response, requestId = REQUEST_ID) {
|
|
48
|
+
const contentType = mediaType(response);
|
|
49
|
+
return contentType === "application/json" ? parseJsonObject(response.body.toString("utf8"))
|
|
50
|
+
: contentType === "text/event-stream" ? findMcpSseResponse(response.body, requestId)
|
|
51
|
+
: null;
|
|
52
|
+
}
|
|
53
|
+
function isValidVersion(value) {
|
|
54
|
+
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value))
|
|
55
|
+
return false;
|
|
56
|
+
const [year, month, day] = value.split("-").map(Number);
|
|
57
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
58
|
+
return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
|
|
59
|
+
}
|
|
60
|
+
function validVersions(value) {
|
|
61
|
+
return Array.isArray(value) && value.length > 0 && value.length <= 32 && value.every(isValidVersion) && new Set(value).size === value.length;
|
|
62
|
+
}
|
|
63
|
+
function hasMatchingResponseEnvelope(message, requestId = REQUEST_ID) {
|
|
64
|
+
return message.jsonrpc === "2.0" && message.id === requestId
|
|
65
|
+
&& Object.hasOwn(message, "result") !== Object.hasOwn(message, "error");
|
|
66
|
+
}
|
|
67
|
+
function validDiscoverResult(value) {
|
|
68
|
+
return isPlainObject(value) && value.resultType === "complete" && validVersions(value.supportedVersions)
|
|
69
|
+
&& validCapabilities(value.capabilities) && typeof value.ttlMs === "number" && Number.isFinite(value.ttlMs) && value.ttlMs >= 0
|
|
70
|
+
&& (value.cacheScope === "public" || value.cacheScope === "private") && validOptionalServerInfo(value);
|
|
71
|
+
}
|
|
72
|
+
function validCapabilities(value) {
|
|
73
|
+
return isPlainObject(value) && ["tools", "resources", "prompts", "completions", "logging", "tasks", "extensions"]
|
|
74
|
+
.every((name) => !Object.hasOwn(value, name) || isPlainObject(value[name]));
|
|
75
|
+
}
|
|
76
|
+
function validOptionalServerInfo(value) {
|
|
77
|
+
if (!Object.hasOwn(value, "_meta"))
|
|
78
|
+
return true;
|
|
79
|
+
if (!isPlainObject(value._meta))
|
|
80
|
+
return false;
|
|
81
|
+
const serverInfo = value._meta["io.modelcontextprotocol/serverInfo"];
|
|
82
|
+
return serverInfo === undefined || (isPlainObject(serverInfo) && typeof serverInfo.name === "string" && typeof serverInfo.version === "string");
|
|
83
|
+
}
|
|
84
|
+
function validError(value) {
|
|
85
|
+
return isPlainObject(value) && typeof value.code === "number" && Number.isFinite(value.code) && typeof value.message === "string";
|
|
86
|
+
}
|
|
87
|
+
function unsupportedVersions(error) {
|
|
88
|
+
if (!validError(error) || error.code !== -32022 || !isPlainObject(error.data))
|
|
89
|
+
return null;
|
|
90
|
+
return error.data.requested === REQUESTED_VERSION && validVersions(error.data.supported) ? error.data.supported : null;
|
|
91
|
+
}
|
|
92
|
+
export function discoverMcpCapabilities(response, requestId = REQUEST_ID) {
|
|
93
|
+
const message = parseMcpResponse(response, requestId);
|
|
94
|
+
if (!message || !hasMatchingResponseEnvelope(message, requestId) || !Object.hasOwn(message, "result")) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
const result = message.result;
|
|
98
|
+
if (!validDiscoverResult(result))
|
|
99
|
+
return null;
|
|
100
|
+
const capabilities = result.capabilities;
|
|
101
|
+
if (!isPlainObject(capabilities))
|
|
102
|
+
return null;
|
|
103
|
+
return result.supportedVersions.includes(REQUESTED_VERSION) ? capabilities : null;
|
|
104
|
+
}
|
|
105
|
+
function failureReport(id, message) {
|
|
106
|
+
return report("failed", "fail", [finding(id, "fail", message, "The discovery response cannot safely establish modern MCP discovery support.", "Verify the endpoint returns a valid server/discover response for the requested protocol version.")]);
|
|
107
|
+
}
|
|
108
|
+
function unsupportedReport(id, message, versions = []) {
|
|
109
|
+
return report("unsupported", "skipped", [finding(id, "warn", message, "Discovery-only probing cannot establish support for the requested MCP protocol version.", "Configure a server that supports the requested protocol version, then run discovery again.")], versions);
|
|
110
|
+
}
|
|
111
|
+
export async function discoverMcpServer(rawUrl, options = {}) {
|
|
112
|
+
if (!options.allowNetwork) {
|
|
113
|
+
return report("blocked", "skipped", [finding("plugin.discovery.network_not_approved", "warn", "Remote MCP discovery was not contacted because network access is not approved.", "Discovery would create outbound network traffic without explicit approval.", "Enable network access only after reviewing the endpoint.")]);
|
|
114
|
+
}
|
|
115
|
+
if (inspectRemoteMcpUrl(rawUrl).issues.length > 0) {
|
|
116
|
+
return report("blocked", "skipped", [finding("plugin.discovery.url.invalid", "warn", "The MCP discovery endpoint is unsafe or unsupported.", "Unsafe endpoint URLs can bypass network controls or expose credentials.", "Use an absolute HTTP or HTTPS endpoint without credentials, query parameters, fragments, or IP literals.")]);
|
|
117
|
+
}
|
|
118
|
+
const request = options.request ?? requestBoundedHttp;
|
|
119
|
+
const body = JSON.stringify({ jsonrpc: "2.0", id: REQUEST_ID, method: "server/discover", params: { _meta: {
|
|
120
|
+
"io.modelcontextprotocol/protocolVersion": REQUESTED_VERSION,
|
|
121
|
+
"io.modelcontextprotocol/clientInfo": { name: "Codex Plugin Doctor", version: packageVersion },
|
|
122
|
+
"io.modelcontextprotocol/clientCapabilities": {}
|
|
123
|
+
} } });
|
|
124
|
+
let response;
|
|
125
|
+
try {
|
|
126
|
+
response = await request(rawUrl, {
|
|
127
|
+
allowLocalNetwork: options.allowLocalNetwork, lookup: options.lookup, timeoutMs: options.requestTimeoutMs,
|
|
128
|
+
method: "POST", body,
|
|
129
|
+
headers: { Accept: "application/json, text/event-stream", "Content-Type": "application/json", "MCP-Protocol-Version": REQUESTED_VERSION, "Mcp-Method": "server/discover" },
|
|
130
|
+
stopAfter: (received) => findMcpSseResponse(received) !== null
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (error instanceof RemoteNetworkPolicyError) {
|
|
135
|
+
return report("blocked", "skipped", [finding("plugin.discovery.network.blocked", "warn", "The MCP discovery target is blocked by the remote network policy.", "Discovery could not safely reach the configured target.", "Use an endpoint permitted by the remote network policy.")]);
|
|
136
|
+
}
|
|
137
|
+
return failureReport(error instanceof BoundedHttpError && error.code === "REMOTE_HTTP_TIMEOUT" ? "plugin.discovery.transport.timeout" : "plugin.discovery.transport.failed", "The MCP discovery request did not complete within the configured transport bounds.");
|
|
138
|
+
}
|
|
139
|
+
if (response.statusCode === 401 || response.statusCode === 403) {
|
|
140
|
+
return unsupportedReport("plugin.discovery.authorization.required", "The MCP endpoint requires authorization before discovery can be assessed.");
|
|
141
|
+
}
|
|
142
|
+
const message = parseMcpResponse(response);
|
|
143
|
+
if (!message || !hasMatchingResponseEnvelope(message))
|
|
144
|
+
return failureReport("plugin.discovery.response.invalid", "The MCP endpoint returned an invalid discovery response.");
|
|
145
|
+
if (Object.hasOwn(message, "error")) {
|
|
146
|
+
if (!validError(message.error))
|
|
147
|
+
return failureReport("plugin.discovery.response.error", "The MCP endpoint returned an invalid discovery error.");
|
|
148
|
+
const versions = unsupportedVersions(message.error);
|
|
149
|
+
if (versions !== null && response.statusCode === 400)
|
|
150
|
+
return unsupportedReport("plugin.discovery.protocol_version.unsupported", "The MCP endpoint does not support the requested protocol version.", versions);
|
|
151
|
+
if (message.error.code === -32601 && (response.statusCode === 200 || response.statusCode === 404))
|
|
152
|
+
return unsupportedReport("plugin.discovery.method.unsupported", "The MCP endpoint does not implement server discovery for this protocol version.");
|
|
153
|
+
return failureReport("plugin.discovery.response.error", "The MCP endpoint returned an unrecognized discovery error.");
|
|
154
|
+
}
|
|
155
|
+
if (response.statusCode !== 200 || !validDiscoverResult(message.result))
|
|
156
|
+
return failureReport("plugin.discovery.result.invalid", "The MCP endpoint returned an invalid discovery result.");
|
|
157
|
+
const versions = message.result.supportedVersions;
|
|
158
|
+
if (!versions.includes(REQUESTED_VERSION))
|
|
159
|
+
return unsupportedReport("plugin.discovery.protocol_version.inconsistent", "The MCP endpoint completed discovery without listing the requested protocol version.", versions);
|
|
160
|
+
return report("discovered", "pass", [], versions);
|
|
161
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type McpDiscoveryReport } from "./mcp-discovery.js";
|
|
2
|
+
import { type CatalogFinding } from "./mcp-tool-definition.js";
|
|
3
|
+
import { type RemoteLookup } from "./remote-network-policy.js";
|
|
4
|
+
import type { RemoteMcpRequest } from "./remote-mcp-probe.js";
|
|
5
|
+
type CatalogStatus = "pass" | "warn" | "fail" | "unsupported" | "not-applicable" | "incomplete" | "blocked";
|
|
6
|
+
type EnumerationCoverage = "complete" | "incomplete" | "not-tested";
|
|
7
|
+
export interface McpToolCatalogOptions {
|
|
8
|
+
allowNetwork?: boolean;
|
|
9
|
+
allowLocalNetwork?: boolean;
|
|
10
|
+
lookup?: RemoteLookup;
|
|
11
|
+
request?: RemoteMcpRequest;
|
|
12
|
+
now?: () => number;
|
|
13
|
+
}
|
|
14
|
+
export interface McpToolCatalogReport {
|
|
15
|
+
schemaVersion: 1;
|
|
16
|
+
scope: "tool-catalog-structure";
|
|
17
|
+
status: CatalogStatus;
|
|
18
|
+
discovery: McpDiscoveryReport;
|
|
19
|
+
catalog: {
|
|
20
|
+
complete: boolean;
|
|
21
|
+
pagesRead: number;
|
|
22
|
+
toolsChecked: number;
|
|
23
|
+
reason: string | null;
|
|
24
|
+
};
|
|
25
|
+
coverage: {
|
|
26
|
+
discovery: "pass" | "fail" | "skipped";
|
|
27
|
+
catalogEnumeration: EnumerationCoverage;
|
|
28
|
+
schema: "root-shape-only";
|
|
29
|
+
toolExecution: "not-tested";
|
|
30
|
+
fullConformance: "not-tested";
|
|
31
|
+
customHeaderAnnotations: "not-tested";
|
|
32
|
+
};
|
|
33
|
+
findings: CatalogFinding[];
|
|
34
|
+
}
|
|
35
|
+
export declare function inspectMcpToolCatalog(rawUrl: string, options?: McpToolCatalogOptions): Promise<McpToolCatalogReport>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { BoundedHttpError, requestBoundedHttp } from "./bounded-http-client.js";
|
|
2
|
+
import { discoverMcpCapabilities, discoverMcpServer, findMcpSseResponse, parseMcpResponse } from "./mcp-discovery.js";
|
|
3
|
+
import { inspectMcpToolDefinition } from "./mcp-tool-definition.js";
|
|
4
|
+
import { RemoteNetworkPolicyError } from "./remote-network-policy.js";
|
|
5
|
+
import { packageVersion } from "../version.js";
|
|
6
|
+
const REQUESTED_VERSION = "2026-07-28";
|
|
7
|
+
const MAX_PAGES = 5;
|
|
8
|
+
const MAX_TOOLS = 500;
|
|
9
|
+
const MAX_FINDINGS = 100;
|
|
10
|
+
const MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
11
|
+
const MAX_TOTAL_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
12
|
+
const REQUEST_TIMEOUT_MS = 3_000;
|
|
13
|
+
const TOTAL_TIMEOUT_MS = 15_000;
|
|
14
|
+
function isPlainObject(value) {
|
|
15
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
function finding(id, severity, message, impact, suggestedFix) {
|
|
18
|
+
return { id, severity, message, impact, suggestedFix };
|
|
19
|
+
}
|
|
20
|
+
function validError(value) {
|
|
21
|
+
return isPlainObject(value) && typeof value.code === "number" && Number.isFinite(value.code) && typeof value.message === "string";
|
|
22
|
+
}
|
|
23
|
+
function validCacheMetadata(value) {
|
|
24
|
+
return value.resultType === "complete"
|
|
25
|
+
&& typeof value.ttlMs === "number" && Number.isFinite(value.ttlMs) && value.ttlMs >= 0
|
|
26
|
+
&& (value.cacheScope === "public" || value.cacheScope === "private");
|
|
27
|
+
}
|
|
28
|
+
function hasMatchingEnvelope(message, requestId) {
|
|
29
|
+
return message.jsonrpc === "2.0" && message.id === requestId
|
|
30
|
+
&& Object.hasOwn(message, "result") !== Object.hasOwn(message, "error");
|
|
31
|
+
}
|
|
32
|
+
function parseToolsResult(message, requestId) {
|
|
33
|
+
if (!hasMatchingEnvelope(message, requestId)) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
if (!Object.hasOwn(message, "result") || !isPlainObject(message.result) || !validCacheMetadata(message.result) || !Array.isArray(message.result.tools)) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (Object.hasOwn(message.result, "nextCursor") && typeof message.result.nextCursor !== "string") {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return { tools: message.result.tools, cursor: message.result.nextCursor };
|
|
43
|
+
}
|
|
44
|
+
function catalogReport(discovery, status, catalog, catalogEnumeration, findings) {
|
|
45
|
+
return {
|
|
46
|
+
schemaVersion: 1,
|
|
47
|
+
scope: "tool-catalog-structure",
|
|
48
|
+
status,
|
|
49
|
+
discovery,
|
|
50
|
+
catalog,
|
|
51
|
+
coverage: {
|
|
52
|
+
discovery: discovery.coverage.discovery,
|
|
53
|
+
catalogEnumeration,
|
|
54
|
+
schema: "root-shape-only",
|
|
55
|
+
toolExecution: "not-tested",
|
|
56
|
+
fullConformance: "not-tested",
|
|
57
|
+
customHeaderAnnotations: "not-tested"
|
|
58
|
+
},
|
|
59
|
+
findings
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function finalStatus(findings) {
|
|
63
|
+
return findings.some((item) => item.severity === "fail")
|
|
64
|
+
? "fail"
|
|
65
|
+
: findings.some((item) => item.severity === "warn")
|
|
66
|
+
? "warn"
|
|
67
|
+
: "pass";
|
|
68
|
+
}
|
|
69
|
+
function isAuthorizationFinding(discovery) {
|
|
70
|
+
return discovery.findings.some((item) => item.id === "plugin.discovery.authorization.required");
|
|
71
|
+
}
|
|
72
|
+
function requestBody(id, cursor) {
|
|
73
|
+
return JSON.stringify({
|
|
74
|
+
jsonrpc: "2.0",
|
|
75
|
+
id,
|
|
76
|
+
method: "tools/list",
|
|
77
|
+
params: {
|
|
78
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
79
|
+
_meta: {
|
|
80
|
+
"io.modelcontextprotocol/protocolVersion": REQUESTED_VERSION,
|
|
81
|
+
"io.modelcontextprotocol/clientInfo": { name: "Codex Plugin Doctor", version: packageVersion },
|
|
82
|
+
"io.modelcontextprotocol/clientCapabilities": {}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
export async function inspectMcpToolCatalog(rawUrl, options = {}) {
|
|
88
|
+
const request = options.request ?? requestBoundedHttp;
|
|
89
|
+
const now = options.now ?? (() => performance.now());
|
|
90
|
+
const deadline = now() + TOTAL_TIMEOUT_MS;
|
|
91
|
+
let receivedBytes = 0;
|
|
92
|
+
let budgetReason = null;
|
|
93
|
+
const requestWithinBudget = async (url, requestOptions = {}) => {
|
|
94
|
+
const remainingTime = deadline - now();
|
|
95
|
+
const remainingBytes = MAX_TOTAL_RESPONSE_BYTES - receivedBytes;
|
|
96
|
+
const timeoutMs = Math.floor(Math.min(REQUEST_TIMEOUT_MS, remainingTime));
|
|
97
|
+
if (timeoutMs < 1) {
|
|
98
|
+
budgetReason = "total-time-limit";
|
|
99
|
+
throw new BoundedHttpError("REMOTE_HTTP_TIMEOUT", "Catalog time budget exhausted.");
|
|
100
|
+
}
|
|
101
|
+
if (remainingBytes <= 0) {
|
|
102
|
+
budgetReason = "total-response-byte-limit";
|
|
103
|
+
throw new BoundedHttpError("REMOTE_HTTP_RESPONSE_TOO_LARGE", "Catalog response byte budget exhausted.");
|
|
104
|
+
}
|
|
105
|
+
const maxResponseBytes = Math.min(MAX_RESPONSE_BYTES, remainingBytes);
|
|
106
|
+
const response = await request(url, {
|
|
107
|
+
...requestOptions,
|
|
108
|
+
timeoutMs,
|
|
109
|
+
maxResponseBytes
|
|
110
|
+
});
|
|
111
|
+
receivedBytes += response.body.length;
|
|
112
|
+
if (response.body.length > maxResponseBytes) {
|
|
113
|
+
budgetReason = receivedBytes > MAX_TOTAL_RESPONSE_BYTES ? "total-response-byte-limit" : "response-byte-limit";
|
|
114
|
+
throw new BoundedHttpError("REMOTE_HTTP_RESPONSE_TOO_LARGE", "Catalog response exceeded the byte budget.");
|
|
115
|
+
}
|
|
116
|
+
return response;
|
|
117
|
+
};
|
|
118
|
+
let discoveryResponse = null;
|
|
119
|
+
const discovery = await discoverMcpServer(rawUrl, {
|
|
120
|
+
allowNetwork: options.allowNetwork,
|
|
121
|
+
allowLocalNetwork: options.allowLocalNetwork,
|
|
122
|
+
lookup: options.lookup,
|
|
123
|
+
request: async (url, requestOptions) => {
|
|
124
|
+
const response = await requestWithinBudget(url, requestOptions);
|
|
125
|
+
discoveryResponse = response;
|
|
126
|
+
return response;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
const emptyCatalog = { complete: false, pagesRead: 0, toolsChecked: 0, reason: null };
|
|
130
|
+
if (discovery.status === "blocked") {
|
|
131
|
+
return catalogReport(discovery, "blocked", { ...emptyCatalog, reason: "network-blocked" }, "not-tested", []);
|
|
132
|
+
}
|
|
133
|
+
if (isAuthorizationFinding(discovery)) {
|
|
134
|
+
return catalogReport(discovery, "incomplete", { ...emptyCatalog, reason: "authorization-required" }, "not-tested", []);
|
|
135
|
+
}
|
|
136
|
+
if (discovery.status === "unsupported") {
|
|
137
|
+
return catalogReport(discovery, "unsupported", { ...emptyCatalog, reason: "discovery-unsupported" }, "not-tested", []);
|
|
138
|
+
}
|
|
139
|
+
if (discovery.status !== "discovered") {
|
|
140
|
+
return catalogReport(discovery, "incomplete", { ...emptyCatalog, reason: budgetReason ?? "discovery-failed" }, "not-tested", []);
|
|
141
|
+
}
|
|
142
|
+
const capabilities = discoveryResponse === null ? null : discoverMcpCapabilities(discoveryResponse);
|
|
143
|
+
if (capabilities === null) {
|
|
144
|
+
return catalogReport(discovery, "incomplete", { ...emptyCatalog, reason: "discovery-response-unavailable" }, "not-tested", []);
|
|
145
|
+
}
|
|
146
|
+
if (!Object.hasOwn(capabilities, "tools")) {
|
|
147
|
+
return catalogReport(discovery, "not-applicable", emptyCatalog, "not-tested", []);
|
|
148
|
+
}
|
|
149
|
+
const findings = [];
|
|
150
|
+
const names = new Map();
|
|
151
|
+
const seenCursors = new Set();
|
|
152
|
+
let pagesRead = 0;
|
|
153
|
+
let toolsChecked = 0;
|
|
154
|
+
let cursor;
|
|
155
|
+
let incompleteReason = null;
|
|
156
|
+
let blocked = false;
|
|
157
|
+
const addFindings = (items) => {
|
|
158
|
+
if (findings.length + items.length > MAX_FINDINGS) {
|
|
159
|
+
findings.push(...items.slice(0, MAX_FINDINGS - findings.length));
|
|
160
|
+
incompleteReason = "finding-limit";
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
findings.push(...items);
|
|
164
|
+
return true;
|
|
165
|
+
};
|
|
166
|
+
while (incompleteReason === null && !blocked) {
|
|
167
|
+
if (pagesRead >= MAX_PAGES) {
|
|
168
|
+
incompleteReason = "page-limit";
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
if (Math.floor(deadline - now()) < 1) {
|
|
172
|
+
incompleteReason = "total-time-limit";
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
const requestId = `tools-list-${pagesRead + 1}`;
|
|
176
|
+
let response;
|
|
177
|
+
try {
|
|
178
|
+
response = await requestWithinBudget(rawUrl, {
|
|
179
|
+
allowLocalNetwork: options.allowLocalNetwork,
|
|
180
|
+
lookup: options.lookup,
|
|
181
|
+
method: "POST",
|
|
182
|
+
body: requestBody(requestId, cursor),
|
|
183
|
+
headers: {
|
|
184
|
+
Accept: "application/json, text/event-stream",
|
|
185
|
+
"Content-Type": "application/json",
|
|
186
|
+
"MCP-Protocol-Version": REQUESTED_VERSION,
|
|
187
|
+
"Mcp-Method": "tools/list"
|
|
188
|
+
},
|
|
189
|
+
stopAfter: (received) => findMcpSseResponse(received, requestId) !== null
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
if (error instanceof RemoteNetworkPolicyError) {
|
|
194
|
+
blocked = true;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
incompleteReason = budgetReason ?? (error instanceof BoundedHttpError && error.code === "REMOTE_HTTP_TIMEOUT"
|
|
198
|
+
? "request-timeout"
|
|
199
|
+
: error instanceof BoundedHttpError && error.code === "REMOTE_HTTP_RESPONSE_TOO_LARGE"
|
|
200
|
+
? "response-byte-limit"
|
|
201
|
+
: "request-failed");
|
|
202
|
+
}
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
if (response.statusCode === 401 || response.statusCode === 403) {
|
|
206
|
+
incompleteReason = "authorization-required";
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
const message = parseMcpResponse(response, requestId);
|
|
210
|
+
if (message !== null && hasMatchingEnvelope(message, requestId) && Object.hasOwn(message, "error")
|
|
211
|
+
&& validError(message.error) && message.error.code === -32601 && (response.statusCode === 200 || response.statusCode === 404)) {
|
|
212
|
+
if (addFindings([finding("plugin.catalog.tools_list.method_unsupported", "warn", "The endpoint advertised tools but does not implement tools/list.", "Tool definitions cannot be enumerated from the advertised capability.", "Implement tools/list for the advertised modern MCP tools capability.")]))
|
|
213
|
+
incompleteReason = "tools-list-method-unsupported";
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
if (response.statusCode !== 200) {
|
|
217
|
+
if (addFindings([finding("plugin.catalog.http_status.invalid", "fail", "The endpoint returned an unexpected tools/list HTTP status.", "The tool catalog cannot be safely enumerated from this response.", "Return HTTP 200 for a tools/list response after authorization succeeds.")]))
|
|
218
|
+
incompleteReason = "http-status-invalid";
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
const page = message === null ? null : parseToolsResult(message, requestId);
|
|
222
|
+
if (page === null) {
|
|
223
|
+
if (addFindings([finding("plugin.catalog.response.invalid", "fail", "The endpoint returned an invalid tools/list response.", "The tool catalog cannot be safely enumerated from this response.", "Return a matching JSON-RPC complete result with valid tools and cache metadata.")]))
|
|
224
|
+
incompleteReason = "response-invalid";
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
pagesRead += 1;
|
|
228
|
+
for (const tool of page.tools) {
|
|
229
|
+
if (toolsChecked >= MAX_TOOLS) {
|
|
230
|
+
incompleteReason = "tool-limit";
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
toolsChecked += 1;
|
|
234
|
+
const location = { page: pagesRead, toolIndex: toolsChecked };
|
|
235
|
+
if (!addFindings(inspectMcpToolDefinition(tool, location))) {
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
if (isPlainObject(tool) && typeof tool.name === "string") {
|
|
239
|
+
const previous = names.get(tool.name);
|
|
240
|
+
if (previous !== undefined && !addFindings([{
|
|
241
|
+
...finding("plugin.catalog.tool.name.duplicate", "warn", "Two enumerated tools use the same name.", "Duplicate tool names can make client selection ambiguous.", "Use a unique MCP tool name for each definition."),
|
|
242
|
+
location: { ...location, relatedToolIndex: previous }
|
|
243
|
+
}])) {
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
if (previous === undefined)
|
|
247
|
+
names.set(tool.name, toolsChecked);
|
|
248
|
+
}
|
|
249
|
+
if (deadline - now() <= 0) {
|
|
250
|
+
incompleteReason = "total-time-limit";
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (incompleteReason !== null)
|
|
255
|
+
break;
|
|
256
|
+
if (page.cursor === undefined)
|
|
257
|
+
break;
|
|
258
|
+
if (seenCursors.has(page.cursor)) {
|
|
259
|
+
if (addFindings([finding("plugin.catalog.cursor.loop", "warn", "The endpoint repeated a tools/list cursor.", "The bounded catalog enumeration cannot determine a complete result set.", "Return each continuation cursor at most once for a single enumeration.")]))
|
|
260
|
+
incompleteReason = "cursor-loop";
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
seenCursors.add(page.cursor);
|
|
264
|
+
cursor = page.cursor;
|
|
265
|
+
}
|
|
266
|
+
if (blocked) {
|
|
267
|
+
return catalogReport(discovery, "blocked", { complete: false, pagesRead, toolsChecked, reason: "network-blocked" }, "incomplete", findings);
|
|
268
|
+
}
|
|
269
|
+
if (incompleteReason !== null) {
|
|
270
|
+
return catalogReport(discovery, "incomplete", { complete: false, pagesRead, toolsChecked, reason: incompleteReason }, "incomplete", findings);
|
|
271
|
+
}
|
|
272
|
+
if (deadline - now() <= 0) {
|
|
273
|
+
return catalogReport(discovery, "incomplete", { complete: false, pagesRead, toolsChecked, reason: "total-time-limit" }, "incomplete", findings);
|
|
274
|
+
}
|
|
275
|
+
return catalogReport(discovery, finalStatus(findings), { complete: true, pagesRead, toolsChecked, reason: null }, "complete", findings);
|
|
276
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Finding } from "../domain/types.js";
|
|
2
|
+
export interface CatalogLocation {
|
|
3
|
+
page: number;
|
|
4
|
+
toolIndex: number;
|
|
5
|
+
schema?: "inputSchema" | "outputSchema";
|
|
6
|
+
relatedToolIndex?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface CatalogFinding extends Finding {
|
|
9
|
+
location?: CatalogLocation;
|
|
10
|
+
}
|
|
11
|
+
export declare function inspectMcpToolDefinition(value: unknown, location: {
|
|
12
|
+
page: number;
|
|
13
|
+
toolIndex: number;
|
|
14
|
+
}): CatalogFinding[];
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
const CANONICAL_SCHEMA_DIALECT = "https://json-schema.org/draft/2020-12/schema";
|
|
2
|
+
const JSON_SCHEMA_TYPES = new Set([
|
|
3
|
+
"array",
|
|
4
|
+
"boolean",
|
|
5
|
+
"integer",
|
|
6
|
+
"null",
|
|
7
|
+
"number",
|
|
8
|
+
"object",
|
|
9
|
+
"string"
|
|
10
|
+
]);
|
|
11
|
+
const MCP_TOOL_NAME = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
12
|
+
function isJsonObject(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
function hasOwn(object, key) {
|
|
16
|
+
return Object.prototype.hasOwnProperty.call(object, key);
|
|
17
|
+
}
|
|
18
|
+
function isAbsoluteUri(value) {
|
|
19
|
+
try {
|
|
20
|
+
return new URL(value).protocol.length > 0;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function schemaLocation(location, schema) {
|
|
27
|
+
return { ...location, schema };
|
|
28
|
+
}
|
|
29
|
+
function addFinding(findings, id, message, impact, suggestedFix, location) {
|
|
30
|
+
const severity = id === "plugin.catalog.tool.name.recommended" ||
|
|
31
|
+
id === "plugin.catalog.schema.dialect.unsupported"
|
|
32
|
+
? "warn"
|
|
33
|
+
: "fail";
|
|
34
|
+
findings.push({ id, severity, message, impact, suggestedFix, location });
|
|
35
|
+
}
|
|
36
|
+
function inspectRootSchema(schema, schemaSlot, location, findings) {
|
|
37
|
+
const locator = schemaLocation(location, schemaSlot);
|
|
38
|
+
const hasDialect = hasOwn(schema, "$schema");
|
|
39
|
+
const dialect = hasDialect ? schema.$schema : undefined;
|
|
40
|
+
if (hasDialect && (typeof dialect !== "string" || !isAbsoluteUri(dialect))) {
|
|
41
|
+
addFinding(findings, "plugin.catalog.schema.dialect.invalid", "The root schema dialect must be an absolute URI string when provided.", "The validator cannot reliably select a schema dialect for this tool.", "Omit $schema or provide an absolute JSON Schema dialect URI.", locator);
|
|
42
|
+
}
|
|
43
|
+
if (typeof dialect === "string" &&
|
|
44
|
+
isAbsoluteUri(dialect) &&
|
|
45
|
+
dialect !== CANONICAL_SCHEMA_DIALECT &&
|
|
46
|
+
dialect !== `${CANONICAL_SCHEMA_DIALECT}#`) {
|
|
47
|
+
addFinding(findings, "plugin.catalog.schema.dialect.unsupported", "The root schema uses a dialect outside this validator's supported baseline.", "The schema may be valid, but its root keywords are outside this validator's bounded coverage.", "Use the JSON Schema 2020-12 dialect or validate this schema with a dialect-aware validator.", locator);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (hasOwn(schema, "properties") && !isJsonObject(schema.properties)) {
|
|
51
|
+
addFinding(findings, "plugin.catalog.schema.properties.invalid", "The root schema properties keyword must be an object when provided.", "Clients cannot reliably interpret the declared object properties.", "Set properties to an object or omit it.", locator);
|
|
52
|
+
}
|
|
53
|
+
if (hasOwn(schema, "required")) {
|
|
54
|
+
const required = schema.required;
|
|
55
|
+
const isValidRequired = Array.isArray(required) &&
|
|
56
|
+
required.every((entry) => typeof entry === "string") &&
|
|
57
|
+
new Set(required).size === required.length;
|
|
58
|
+
if (!isValidRequired) {
|
|
59
|
+
addFinding(findings, "plugin.catalog.schema.required.invalid", "The root schema required keyword must be an array of unique strings when provided.", "Clients cannot reliably determine which inputs are required.", "Set required to an array of unique property names or omit it.", locator);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (hasOwn(schema, "type")) {
|
|
63
|
+
const type = schema.type;
|
|
64
|
+
const isValidType = (typeof type === "string" && JSON_SCHEMA_TYPES.has(type)) ||
|
|
65
|
+
(Array.isArray(type) &&
|
|
66
|
+
type.length > 0 &&
|
|
67
|
+
type.every((entry) => typeof entry === "string" && JSON_SCHEMA_TYPES.has(entry)) &&
|
|
68
|
+
new Set(type).size === type.length);
|
|
69
|
+
if (!isValidType) {
|
|
70
|
+
addFinding(findings, "plugin.catalog.schema.type.invalid", "The root schema type keyword must be a supported type string or a non-empty array of unique supported type strings.", "Clients cannot reliably interpret the root value type.", "Use JSON Schema primitive types for type, or omit the keyword.", locator);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (hasOwn(schema, "additionalProperties") &&
|
|
74
|
+
typeof schema.additionalProperties !== "boolean" &&
|
|
75
|
+
!isJsonObject(schema.additionalProperties)) {
|
|
76
|
+
addFinding(findings, "plugin.catalog.schema.additional_properties.invalid", "The root schema additionalProperties keyword must be a boolean or object when provided.", "Clients cannot reliably interpret whether additional object properties are allowed.", "Set additionalProperties to a boolean or object, or omit it.", locator);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function inspectMcpToolDefinition(value, location) {
|
|
80
|
+
const findings = [];
|
|
81
|
+
const baseLocation = { page: location.page, toolIndex: location.toolIndex };
|
|
82
|
+
if (!isJsonObject(value)) {
|
|
83
|
+
addFinding(findings, "plugin.catalog.tool.invalid_object", "A catalog tool entry must be an object.", "The validator cannot inspect a tool definition that is not an object.", "Return each tools/list entry as an object.", baseLocation);
|
|
84
|
+
return findings;
|
|
85
|
+
}
|
|
86
|
+
const name = hasOwn(value, "name") ? value.name : undefined;
|
|
87
|
+
if (typeof name !== "string") {
|
|
88
|
+
addFinding(findings, "plugin.catalog.tool.name.invalid", "A catalog tool name must be a string.", "Clients cannot identify or invoke a tool without a string name.", "Provide a string name for the tool.", baseLocation);
|
|
89
|
+
}
|
|
90
|
+
else if (!MCP_TOOL_NAME.test(name)) {
|
|
91
|
+
addFinding(findings, "plugin.catalog.tool.name.recommended", "The tool name does not meet the MCP recommended ASCII length and character constraints.", "Some clients may not accept or consistently display this tool name.", "Use 1 to 128 ASCII letters, digits, dots, underscores, or hyphens for the tool name.", baseLocation);
|
|
92
|
+
}
|
|
93
|
+
if (hasOwn(value, "title") && typeof value.title !== "string") {
|
|
94
|
+
addFinding(findings, "plugin.catalog.tool.title.invalid", "A catalog tool title must be a string when provided.", "Clients cannot reliably display a non-string tool title.", "Provide a string title or omit the title field.", baseLocation);
|
|
95
|
+
}
|
|
96
|
+
if (hasOwn(value, "description") && typeof value.description !== "string") {
|
|
97
|
+
addFinding(findings, "plugin.catalog.tool.description.invalid", "A catalog tool description must be a string when provided.", "Clients cannot reliably display a non-string tool description.", "Provide a string description or omit the description field.", baseLocation);
|
|
98
|
+
}
|
|
99
|
+
const inputSchema = hasOwn(value, "inputSchema") ? value.inputSchema : undefined;
|
|
100
|
+
if (!isJsonObject(inputSchema)) {
|
|
101
|
+
addFinding(findings, "plugin.catalog.schema.input.invalid", "A catalog tool inputSchema must be a non-null object.", "Clients cannot reliably construct valid tool inputs without an object schema.", "Provide inputSchema as an object.", schemaLocation(baseLocation, "inputSchema"));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
inspectRootSchema(inputSchema, "inputSchema", baseLocation, findings);
|
|
105
|
+
}
|
|
106
|
+
if (hasOwn(value, "outputSchema")) {
|
|
107
|
+
const outputSchema = value.outputSchema;
|
|
108
|
+
if (!isJsonObject(outputSchema)) {
|
|
109
|
+
addFinding(findings, "plugin.catalog.schema.output.invalid", "A catalog tool outputSchema must be an object when provided.", "Clients cannot reliably interpret tool outputs without an object schema.", "Provide outputSchema as an object or omit it.", schemaLocation(baseLocation, "outputSchema"));
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
inspectRootSchema(outputSchema, "outputSchema", baseLocation, findings);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return findings;
|
|
116
|
+
}
|
|
@@ -641,6 +641,79 @@ const publicSchemaDefinitions = [
|
|
|
641
641
|
id: "doctor.snapshot.json",
|
|
642
642
|
command: "codex-plugin-doctor doctor snapshot --json",
|
|
643
643
|
required: ["schemaVersion", "generatedAt", "version", "environment", "clients", "installedPlugins", "nextCommands"]
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
id: "doctor.tools.json",
|
|
647
|
+
command: "codex-plugin-doctor doctor tools <url> --allow-network --json",
|
|
648
|
+
required: ["schemaVersion", "scope", "status", "discovery", "catalog", "coverage", "findings"],
|
|
649
|
+
properties: {
|
|
650
|
+
schemaVersion: { const: 1 },
|
|
651
|
+
scope: { const: "tool-catalog-structure" },
|
|
652
|
+
status: { enum: ["pass", "warn", "fail", "unsupported", "not-applicable", "incomplete", "blocked"] },
|
|
653
|
+
discovery: {
|
|
654
|
+
type: "object",
|
|
655
|
+
required: ["schemaVersion", "requestedVersion", "scope", "status", "supportedVersions", "findings", "coverage"],
|
|
656
|
+
properties: {
|
|
657
|
+
schemaVersion: { const: 1 },
|
|
658
|
+
requestedVersion: { const: "2026-07-28" },
|
|
659
|
+
scope: { const: "discovery-only" },
|
|
660
|
+
status: { enum: ["discovered", "unsupported", "blocked", "failed"] },
|
|
661
|
+
supportedVersions: { type: "array", maxItems: 32, uniqueItems: true, items: { type: "string", pattern: "^\\d{4}-\\d{2}-\\d{2}$" } },
|
|
662
|
+
findings: { type: "array" },
|
|
663
|
+
coverage: {
|
|
664
|
+
type: "object", required: ["discovery", "runtime"],
|
|
665
|
+
properties: { discovery: { enum: ["pass", "fail", "skipped"] }, runtime: { const: "not-tested" } },
|
|
666
|
+
additionalProperties: false
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
additionalProperties: false
|
|
670
|
+
},
|
|
671
|
+
catalog: {
|
|
672
|
+
type: "object", required: ["complete", "pagesRead", "toolsChecked", "reason"],
|
|
673
|
+
properties: {
|
|
674
|
+
complete: { type: "boolean" },
|
|
675
|
+
pagesRead: { type: "integer", minimum: 0, maximum: 5 },
|
|
676
|
+
toolsChecked: { type: "integer", minimum: 0, maximum: 500 },
|
|
677
|
+
reason: { type: ["string", "null"] }
|
|
678
|
+
},
|
|
679
|
+
additionalProperties: false
|
|
680
|
+
},
|
|
681
|
+
coverage: {
|
|
682
|
+
type: "object",
|
|
683
|
+
required: ["discovery", "catalogEnumeration", "schema", "toolExecution", "fullConformance", "customHeaderAnnotations"],
|
|
684
|
+
properties: {
|
|
685
|
+
discovery: { enum: ["pass", "fail", "skipped"] },
|
|
686
|
+
catalogEnumeration: { enum: ["complete", "incomplete", "not-tested"] },
|
|
687
|
+
schema: { const: "root-shape-only" },
|
|
688
|
+
toolExecution: { const: "not-tested" },
|
|
689
|
+
fullConformance: { const: "not-tested" },
|
|
690
|
+
customHeaderAnnotations: { const: "not-tested" }
|
|
691
|
+
},
|
|
692
|
+
additionalProperties: false
|
|
693
|
+
},
|
|
694
|
+
findings: {
|
|
695
|
+
type: "array", maxItems: 100,
|
|
696
|
+
items: {
|
|
697
|
+
type: "object", required: ["id", "severity", "message", "impact", "suggestedFix"],
|
|
698
|
+
properties: {
|
|
699
|
+
id: { type: "string", pattern: "^plugin\\.catalog\\." },
|
|
700
|
+
severity: { enum: ["warn", "fail"] },
|
|
701
|
+
message: { type: "string" }, impact: { type: "string" }, suggestedFix: { type: "string" },
|
|
702
|
+
location: {
|
|
703
|
+
type: "object", required: ["page", "toolIndex"],
|
|
704
|
+
properties: {
|
|
705
|
+
page: { type: "integer", minimum: 1, maximum: 5 },
|
|
706
|
+
toolIndex: { type: "integer", minimum: 1, maximum: 500 },
|
|
707
|
+
schema: { enum: ["inputSchema", "outputSchema"] },
|
|
708
|
+
relatedToolIndex: { type: "integer", minimum: 1, maximum: 500 }
|
|
709
|
+
},
|
|
710
|
+
additionalProperties: false
|
|
711
|
+
}
|
|
712
|
+
},
|
|
713
|
+
additionalProperties: false
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
644
717
|
}
|
|
645
718
|
];
|
|
646
719
|
function sha256(value) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function renderMcpDiscoveryReport(report) {
|
|
2
|
+
return [
|
|
3
|
+
"MCP Discovery",
|
|
4
|
+
"=============",
|
|
5
|
+
`Status: ${report.status}`,
|
|
6
|
+
`Scope: ${report.scope}`,
|
|
7
|
+
`Requested protocol: ${report.requestedVersion}`,
|
|
8
|
+
`Advertised versions: ${report.supportedVersions.join(", ") || "not available"}`,
|
|
9
|
+
`Discovery response: ${report.coverage.discovery}`,
|
|
10
|
+
`Runtime: ${report.coverage.runtime}`,
|
|
11
|
+
"Discovery does not establish full protocol conformance or client compatibility.",
|
|
12
|
+
...report.findings.map((finding) => `${finding.severity.toUpperCase()} ${finding.id}: ${finding.message}\n ${finding.suggestedFix}`)
|
|
13
|
+
].join("\n");
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function renderMcpToolCatalogReport(report) {
|
|
2
|
+
return [
|
|
3
|
+
"MCP Tool Catalog",
|
|
4
|
+
"================",
|
|
5
|
+
`Status: ${report.status}`,
|
|
6
|
+
`Scope: ${report.scope}`,
|
|
7
|
+
`Discovery: ${report.discovery.status}`,
|
|
8
|
+
`Catalog complete: ${report.catalog.complete}`,
|
|
9
|
+
`Pages read: ${report.catalog.pagesRead}`,
|
|
10
|
+
`Tools checked: ${report.catalog.toolsChecked}`,
|
|
11
|
+
...(report.catalog.reason === null ? [] : [`Reason: ${report.catalog.reason}`]),
|
|
12
|
+
`Enumeration: ${report.coverage.catalogEnumeration}`,
|
|
13
|
+
`Schema coverage: ${report.coverage.schema}`,
|
|
14
|
+
`Tool execution: ${report.coverage.toolExecution}`,
|
|
15
|
+
`Custom header annotations: ${report.coverage.customHeaderAnnotations}`,
|
|
16
|
+
`Full conformance: ${report.coverage.fullConformance}`,
|
|
17
|
+
"Counts describe inspected content, not a guaranteed server-wide inventory.",
|
|
18
|
+
...report.discovery.findings.map((finding) => `${finding.severity.toUpperCase()} ${finding.id}: ${finding.message}\n ${finding.suggestedFix}`),
|
|
19
|
+
...report.findings.map((finding) => {
|
|
20
|
+
const location = finding.location;
|
|
21
|
+
const locator = location ? ` [page ${location.page}, tool ${location.toolIndex}${location.schema ? `, ${location.schema}` : ""}${location.relatedToolIndex ? `, related tool ${location.relatedToolIndex}` : ""}]` : "";
|
|
22
|
+
return `${finding.severity.toUpperCase()} ${finding.id}${locator}: ${finding.message}\n ${finding.suggestedFix}`;
|
|
23
|
+
})
|
|
24
|
+
].join("\n");
|
|
25
|
+
}
|
package/dist/run-cli.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { discoverMcpServer } from "./core/mcp-discovery.js";
|
|
2
|
+
import { inspectMcpToolCatalog } from "./core/mcp-tool-catalog.js";
|
|
1
3
|
import { buildCorpusQualityMetricsDiffReport, buildCorpusQualityMetricsReport } from "./core/corpus-quality-metrics.js";
|
|
2
4
|
import { runCheck } from "./index.js";
|
|
3
5
|
import { writeRawDoctorConfig } from "./index.js";
|
|
@@ -13,6 +15,8 @@ export interface CliTerminalContext {
|
|
|
13
15
|
platform?: NodeJS.Platform;
|
|
14
16
|
}
|
|
15
17
|
export interface RunCliOptions {
|
|
18
|
+
inspectMcpToolCatalogImpl?: typeof inspectMcpToolCatalog;
|
|
19
|
+
discoverMcpServerImpl?: typeof discoverMcpServer;
|
|
16
20
|
terminalContext?: CliTerminalContext;
|
|
17
21
|
runCheckImpl?: typeof runCheck;
|
|
18
22
|
writeRawDoctorConfigImpl?: typeof writeRawDoctorConfig;
|
package/dist/run-cli.js
CHANGED
|
@@ -21,6 +21,10 @@ import { buildDoctorAttestation, renderDoctorAttestation, renderDoctorAttestatio
|
|
|
21
21
|
import { buildDoctorOutputContract, renderDoctorOutputContract, renderDoctorOutputContractJson } from "./core/output-contract.js";
|
|
22
22
|
import { buildSubmissionArchivePreflight, submissionArchiveExitCode } from "./core/submission-archive-preflight.js";
|
|
23
23
|
import { buildSubmissionPreflight } from "./core/submission-preflight.js";
|
|
24
|
+
import { discoverMcpServer } from "./core/mcp-discovery.js";
|
|
25
|
+
import { inspectMcpToolCatalog } from "./core/mcp-tool-catalog.js";
|
|
26
|
+
import { renderMcpToolCatalogReport } from "./reporting/render-mcp-tool-catalog-report.js";
|
|
27
|
+
import { renderMcpDiscoveryReport } from "./reporting/render-mcp-discovery-report.js";
|
|
24
28
|
import { buildDoctorValidationCorpusReport, renderDoctorValidationCorpusJson, renderDoctorValidationCorpusReport } from "./core/validation-corpus.js";
|
|
25
29
|
import { buildExternalValidationCorpusReport, ExternalCorpusManifestError } from "./core/external-validation-corpus.js";
|
|
26
30
|
import { buildCorpusQualityMetricsDiffReport, buildCorpusQualityMetricsReport, CorpusMetricsDiffError, CorpusMetricsManifestError, renderCorpusQualityMetricsDiffJson, renderCorpusQualityMetricsDiffMarkdown, renderCorpusQualityMetricsDiffText, renderCorpusQualityMetricsJson, renderCorpusQualityMetricsMarkdown, renderCorpusQualityMetricsText } from "./core/corpus-quality-metrics.js";
|
|
@@ -99,6 +103,8 @@ function writeExactStdout(io, message) {
|
|
|
99
103
|
}
|
|
100
104
|
class CliUsageError extends Error {
|
|
101
105
|
}
|
|
106
|
+
const toolsUsage = "Usage: codex-plugin-doctor doctor tools <url> --allow-network [--allow-local-network] [--json]";
|
|
107
|
+
const discoveryUsage = "Usage: codex-plugin-doctor doctor discover <url> --allow-network [--allow-local-network] [--json]";
|
|
102
108
|
function parseRuntimeSandbox(flags, options = { requireRuntime: true }) {
|
|
103
109
|
const index = flags.indexOf("--sandbox");
|
|
104
110
|
if (index === -1) {
|
|
@@ -181,6 +187,8 @@ function parseRemoteNetworkFlags(flags, runtime) {
|
|
|
181
187
|
}
|
|
182
188
|
function printUsage(io) {
|
|
183
189
|
io.writeStderr("Usage: codex-plugin-doctor check <path|--installed> [filter] [--policy codex-publish|mcp-strict|security] [--compat] [--json|--markdown|--badge-json|--badge-markdown] [--output <path>] [--history <path>] [--runtime [--allow-network [--allow-local-network]]] [--sandbox docker] [--require-runtime-approval --runtime-approval-digest <digest>] [--verbose-runtime] [--explain] [--no-animations] [--ascii] [--changed-since <ref>] [--fail-on <rule-id>]\n codex-plugin-doctor audit --installed [filter] [--policy codex-publish|mcp-strict|security] [--security] [--compat] [--json] [--output <path>] [--cache] [--changed]\n codex-plugin-doctor audit deps <path> [--policy codex-publish|mcp-strict|security] [--recommend] [--json|--sarif] [--output <path>]\n codex-plugin-doctor mcp <path> [--runtime [--allow-network [--allow-local-network]]] [--json] [--output <path>]\n codex-plugin-doctor security <path> [--policy security] [--json|--scorecard]\n codex-plugin-doctor compat <path> [--all|--client <client>] [--json] [--scorecard] [--output <path>] [--install-preview|--apply --backup]\n codex-plugin-doctor suppress add <path> [--fingerprint <sha256> --reason <text> --expires-at YYYY-MM-DD] [--config <path>] [--json]\n codex-plugin-doctor suppress list <path> [--config <path>] [--json]\n codex-plugin-doctor suppress remove <path> [--fingerprint <sha256>|--index <n>] [--config <path>] [--json]\n codex-plugin-doctor fix <path> (--dry-run|--interactive --backup|--apply --backup)\n codex-plugin-doctor history <history.jsonl> [--json] [--fail-on-regression]\n codex-plugin-doctor watch <path> [--runtime] [--json] [--output <path>] [--debounce-ms <ms>] [--max-iterations <n>] [--fail-fast] [--accumulate-json <path>]\n codex-plugin-doctor doctor [npm <package>|contract|corpus [--manifest <corpus.json>] [--json] [--output <path>]|corpus metrics --manifest <corpus.json> [--json|--markdown] [--output <path>] [--min-precision <0..1>] [--min-recall <0..1>] [--max-false-positive-rate <0..1>]|runtime-plan <path> [--sandbox docker] [--json|--markdown] [--output <path>]|runtime-policy <path> [--sandbox docker] [--json] [--output <path>]|review-bundle <path> --output <dir> --sign-key-env NAME [--json] [--allow-dirty] [--allow-untagged]|review-bundle verify <bundle-dir> --target <path> --sign-key-env NAME [--json] [--output <path>] [--failures-only]|review-bundle diff --before <dir> --after <dir> [--json]|attest <path> [--sign-key-env NAME]|attest verify <attestation.json> --target <path> --sign-key-env NAME|release-evidence <path> --sign-key-env NAME [--runtime [--allow-network [--allow-local-network]]] [--sandbox docker] [--allow-dirty] [--allow-untagged] [--require-runtime-approval --runtime-approval-digest <digest>]|release-evidence verify <evidence.json> --target <path> --sign-key-env NAME|release-evidence asset <path> --tag <tag> --output <evidence.json> --sign-key-env NAME [--runtime [--allow-network [--allow-local-network]]] [--sandbox docker] [--allow-dirty] [--allow-untagged] [--require-runtime-approval --runtime-approval-digest <digest>] [--upload]|mcp <path> [--runtime [--allow-network [--allow-local-network]]]|inspector <path>|diff --before <path> --after <path>|recommend <path>|trust <path>|perf <path> [--max-total-ms <ms>] [--max-stage-ms stage=ms]|export --bundle <path>|snapshot|clients|--json|--update-check]\n codex-plugin-doctor init [path] [--template skill-only|mcp-stdio|mcp-http|full-runtime]\n codex-plugin-doctor init-ci [path]\n codex-plugin-doctor init-git-hooks [path] [--force] [--json]\n codex-plugin-doctor init-git-hooks [path] --remove [--json]\n codex-plugin-doctor completion bash|zsh|fish\n codex-plugin-doctor config validate <path> [--json]\n codex-plugin-doctor release check <path> [--json] [--runtime [--allow-network [--allow-local-network]]] [--sandbox docker]\n codex-plugin-doctor self-test\n codex-plugin-doctor list --installed\n codex-plugin-doctor explain <finding-id>\n codex-plugin-doctor --version\n\nFirst run:\n codex-plugin-doctor doctor\n codex-plugin-doctor self-test\n codex-plugin-doctor init my-plugin\n codex-plugin-doctor check . --runtime --explain");
|
|
190
|
+
io.writeStderr(discoveryUsage);
|
|
191
|
+
io.writeStderr(toolsUsage);
|
|
184
192
|
io.writeStderr("Registry readiness: codex-plugin-doctor registry check <server.json|directory> [--json] [--output <path>] [--require-registry-readiness]\n"
|
|
185
193
|
+ " codex-plugin-doctor registry inspect <server-name> --allow-network [--json] [--output <path>] [--require-registry-readiness]\n"
|
|
186
194
|
+ "Registry publication preflight: codex-plugin-doctor registry preflight <server.json|directory> [--allow-network] [--json] [--output <path>] [--require-publish-ready]");
|
|
@@ -1191,6 +1199,63 @@ export async function runCli(args, io = defaultIo, options = {}) {
|
|
|
1191
1199
|
return 0;
|
|
1192
1200
|
}
|
|
1193
1201
|
if (command === "doctor") {
|
|
1202
|
+
if (maybePath === "tools") {
|
|
1203
|
+
if (remainingArgs.length === 1 && remainingArgs[0] === "--help") {
|
|
1204
|
+
io.writeStdout(`${toolsUsage}\nHTTP tool catalog structure only; tools are not executed.`);
|
|
1205
|
+
return 0;
|
|
1206
|
+
}
|
|
1207
|
+
const [url, ...flags] = remainingArgs;
|
|
1208
|
+
if (!url || url.startsWith("-")) {
|
|
1209
|
+
io.writeStderr(toolsUsage);
|
|
1210
|
+
return 2;
|
|
1211
|
+
}
|
|
1212
|
+
const allowedFlags = new Set(["--allow-network", "--allow-local-network", "--json"]);
|
|
1213
|
+
if (flags.some((flag) => !allowedFlags.has(flag)) || new Set(flags).size !== flags.length) {
|
|
1214
|
+
io.writeStderr(`Invalid or duplicate tool catalog arguments. ${toolsUsage}`);
|
|
1215
|
+
return 2;
|
|
1216
|
+
}
|
|
1217
|
+
if (!flags.includes("--allow-network")) {
|
|
1218
|
+
io.writeStderr("doctor tools requires explicit --allow-network consent.");
|
|
1219
|
+
return 2;
|
|
1220
|
+
}
|
|
1221
|
+
const report = await (options.inspectMcpToolCatalogImpl ?? inspectMcpToolCatalog)(url, {
|
|
1222
|
+
allowNetwork: true,
|
|
1223
|
+
allowLocalNetwork: flags.includes("--allow-local-network")
|
|
1224
|
+
});
|
|
1225
|
+
io.writeStdout(flags.includes("--json")
|
|
1226
|
+
? JSON.stringify(report, null, 2)
|
|
1227
|
+
: renderMcpToolCatalogReport(report));
|
|
1228
|
+
return report.status === "pass" ? 0
|
|
1229
|
+
: report.status === "incomplete" || report.status === "blocked" ? 2 : 1;
|
|
1230
|
+
}
|
|
1231
|
+
if (maybePath === "discover") {
|
|
1232
|
+
if (remainingArgs.length === 1 && remainingArgs[0] === "--help") {
|
|
1233
|
+
io.writeStdout(`${discoveryUsage}\nHTTP discovery only; runtime behavior is not tested.`);
|
|
1234
|
+
return 0;
|
|
1235
|
+
}
|
|
1236
|
+
const [url, ...flags] = remainingArgs;
|
|
1237
|
+
if (!url || url.startsWith("-")) {
|
|
1238
|
+
io.writeStderr(discoveryUsage);
|
|
1239
|
+
return 2;
|
|
1240
|
+
}
|
|
1241
|
+
const allowedFlags = new Set(["--allow-network", "--allow-local-network", "--json"]);
|
|
1242
|
+
if (flags.some((flag) => !allowedFlags.has(flag)) || new Set(flags).size !== flags.length) {
|
|
1243
|
+
io.writeStderr(`Invalid or duplicate discovery arguments. ${discoveryUsage}`);
|
|
1244
|
+
return 2;
|
|
1245
|
+
}
|
|
1246
|
+
if (!flags.includes("--allow-network")) {
|
|
1247
|
+
io.writeStderr("doctor discover requires explicit --allow-network consent.");
|
|
1248
|
+
return 2;
|
|
1249
|
+
}
|
|
1250
|
+
const report = await (options.discoverMcpServerImpl ?? discoverMcpServer)(url, {
|
|
1251
|
+
allowNetwork: true,
|
|
1252
|
+
allowLocalNetwork: flags.includes("--allow-local-network")
|
|
1253
|
+
});
|
|
1254
|
+
io.writeStdout(flags.includes("--json")
|
|
1255
|
+
? JSON.stringify(report, null, 2)
|
|
1256
|
+
: renderMcpDiscoveryReport(report));
|
|
1257
|
+
return report.status === "discovered" ? 0 : report.status === "unsupported" ? 1 : 2;
|
|
1258
|
+
}
|
|
1194
1259
|
const doctorFlags = maybePath?.startsWith("--")
|
|
1195
1260
|
? [maybePath, ...remainingArgs]
|
|
1196
1261
|
: remainingArgs;
|
package/package.json
CHANGED