agent-customs 0.0.0-stage → 1.0.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.md +341 -0
- package/README.md +592 -2
- package/bin/agent-customs.mjs +194 -0
- package/package.json +77 -4
- package/site/.well-known/agent-customs-key.json +13 -0
- package/site/certificate.js +944 -0
- package/site/customs/analyze.js +1224 -0
- package/site/customs/auto.js +83 -0
- package/site/customs/canary.js +270 -0
- package/site/customs/canonical.js +123 -0
- package/site/customs/capabilities.js +387 -0
- package/site/customs/diff.js +236 -0
- package/site/customs/english-words.js +153 -0
- package/site/customs/guard-notice.js +226 -0
- package/site/customs/guard-ui.js +105 -0
- package/site/customs/guard.js +259 -0
- package/site/customs/inspect.js +446 -0
- package/site/customs/judge.js +208 -0
- package/site/customs/languages.js +826 -0
- package/site/customs/locks.js +967 -0
- package/site/customs/pins.js +119 -0
- package/site/customs/protocols.js +621 -0
- package/site/customs/receipts.js +154 -0
- package/site/customs/rules.js +1470 -0
- package/site/customs/unicode.js +361 -0
- package/site/runtime/LICENSE.txt +176 -0
- package/site/runtime/generated/graph.gen.mjs +83 -0
- package/site/runtime/generated/validation.gen.mjs +70 -0
- package/site/runtime/hocon.js +262 -0
- package/site/runtime/kernel.js +237 -0
- package/site/runtime/model.js +44 -0
- package/tests/fixtures/official/NOTICE +3 -0
- package/tests/fixtures/official/guesthouse_agentified/agent-manifest.json +86 -0
- package/tests/fixtures/official/guesthouse_agentified/links.json +6 -0
- package/tests/fixtures/official/guesthouse_agentified/tidewhistle_guesthouse.network.json +56 -0
- package/tests/fixtures/official/harbor_tours_agentified/agent-manifest.json +86 -0
- package/tests/fixtures/official/harbor_tours_agentified/links.json +6 -0
- package/tests/fixtures/official/harbor_tours_agentified/marrow_point_harbor_tours.network.json +56 -0
- package/tests/fixtures/official/pizza_restaurant_agentified/agent-manifest.json +78 -0
- package/tests/fixtures/official/pizza_restaurant_agentified/links.json +6 -0
- package/tests/fixtures/official/pizza_restaurant_agentified/pizza_restaurant_website_assistant.network.json +156 -0
- package/tools/bench.mjs +731 -0
- package/tools/external-heldout.mjs +337 -0
- package/tools/fs-fetch.mjs +19 -0
- package/tools/heldout-corpus.mjs +135 -0
- package/tools/inspect-local.mjs +88 -0
- package/tools/round2-corpus.mjs +395 -0
- package/tools/round3-corpus.mjs +192 -0
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
// protocols.js: detect and normalize Google A2A Agent Cards and MCP tool catalogs
|
|
2
|
+
// into the unified structure analyzed by analyze.js, rules.js, canonical.js and diff.js.
|
|
3
|
+
//
|
|
4
|
+
// Everything stays pure (no network access): inspect.js fetches public files, passes
|
|
5
|
+
// parsed foreign specs here when appropriate, and analyze.js evaluates Papers,
|
|
6
|
+
// Contraband, Itinerary, Privacy, Identity and Capabilities uniformly across protocols.
|
|
7
|
+
|
|
8
|
+
export const PROTOCOL_PROFILES = {
|
|
9
|
+
"open-agentic-web": "Open Agentic Web MVP Profile 0.2 (6 Nov 2026)",
|
|
10
|
+
a2a: "Google A2A Agent Card",
|
|
11
|
+
mcp: "Model Context Protocol (MCP) Catalog",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const DESTRUCTIVE_NAME = /\b(delete|remove|drop|destroy|wipe|purge|exec|eval|run_command|shell|bash|write|overwrite|send_email|transfer|pay|charge|purchase|post_)\w*/i;
|
|
15
|
+
const SHELL_RUNNER = /(?:^|\s)(?:ba?sh|sh|zsh|cmd(?:\.exe)?|powershell(?:\.exe)?|pwsh)\b|(?:curl|wget)[^|\n]*\|/i;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Identify which agent protocol a fetched JSON document describes.
|
|
19
|
+
*
|
|
20
|
+
* :param doc: Parsed JSON value.
|
|
21
|
+
* :param url: Optional source URL to disambiguate minimal or malformed files.
|
|
22
|
+
* :return: "open-agentic-web", "a2a", "mcp", or null when unrecognized.
|
|
23
|
+
*/
|
|
24
|
+
export function detectProtocol(doc, url = "") {
|
|
25
|
+
if (!doc || typeof doc !== "object" || Array.isArray(doc)) return null;
|
|
26
|
+
if (Array.isArray(doc.networks)) return "open-agentic-web";
|
|
27
|
+
if (Array.isArray(doc.tools) && doc.tools.some((t) => t && typeof t === "object" && ("instructions" in t || "command" in t || "function" in t || "class" in t || "toolbox" in t))) {
|
|
28
|
+
return "open-agentic-web";
|
|
29
|
+
}
|
|
30
|
+
if (typeof doc.name === "string" && (Array.isArray(doc.skills) || Array.isArray(doc.supportedInterfaces) || doc.capabilities || doc.defaultInputModes || doc.preferredTransport)) {
|
|
31
|
+
return "a2a";
|
|
32
|
+
}
|
|
33
|
+
if (doc.mcpServers && typeof doc.mcpServers === "object" && !Array.isArray(doc.mcpServers)) {
|
|
34
|
+
return "mcp";
|
|
35
|
+
}
|
|
36
|
+
if (typeof doc.protocol === "string" && /model context protocol|\bmcp\b/i.test(doc.protocol)) {
|
|
37
|
+
return "mcp";
|
|
38
|
+
}
|
|
39
|
+
if ((typeof doc.$schema === "string" && /modelcontextprotocol\.io/i.test(doc.$schema)) || (typeof doc.name === "string" && (Array.isArray(doc.packages) || Array.isArray(doc.remotes)))) {
|
|
40
|
+
return "mcp";
|
|
41
|
+
}
|
|
42
|
+
const rpcTools = doc.result?.tools;
|
|
43
|
+
if (Array.isArray(rpcTools) || (Array.isArray(doc.tools) && doc.tools.some((t) => t && typeof t === "object" && ("inputSchema" in t || "annotations" in t)))) {
|
|
44
|
+
return "mcp";
|
|
45
|
+
}
|
|
46
|
+
if (doc.serverInfo || Array.isArray(doc.prompts) || Array.isArray(doc.resources) || Array.isArray(doc.result?.prompts)) {
|
|
47
|
+
return "mcp";
|
|
48
|
+
}
|
|
49
|
+
if (/(?:\/\.well-known\/agent(?:-card)?\.json|\/agent(?:-card)?\.json)$/i.test(url)) return "a2a";
|
|
50
|
+
if (/(?:\/\.well-known\/mcp\.json|\/mcp\.json|\/tools\/list)$/i.test(url)) return "mcp";
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Return fallback discovery URLs to probe when a site does not publish agent-manifest.json.
|
|
56
|
+
*
|
|
57
|
+
* :param baseUrl: Folder/root base URL without trailing slash.
|
|
58
|
+
* :return: Candidate {url, protocolHint} descriptors in priority order.
|
|
59
|
+
*/
|
|
60
|
+
export function foreignDiscoveryCandidates(baseUrl) {
|
|
61
|
+
const base = String(baseUrl || "").replace(/\/+$/, "");
|
|
62
|
+
if (!base) return [];
|
|
63
|
+
return [
|
|
64
|
+
{ url: `${base}/.well-known/agent.json`, protocolHint: "a2a" },
|
|
65
|
+
{ url: `${base}/.well-known/agent-card.json`, protocolHint: "a2a" },
|
|
66
|
+
{ url: `${base}/.well-known/mcp.json`, protocolHint: "mcp" },
|
|
67
|
+
{ url: `${base}/mcp.json`, protocolHint: "mcp" },
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Normalize an A2A Agent Card or MCP JSON catalog into analyzeNetwork() inputs.
|
|
73
|
+
*
|
|
74
|
+
* :param doc: Parsed JSON document.
|
|
75
|
+
* :param targetUrl: URL where the document was published.
|
|
76
|
+
* :param protocol: Optional explicit protocol ("a2a" or "mcp").
|
|
77
|
+
* :return: Normalized {protocol, profile, manifest, entry, config, frontMan, linkSlots, rawDoc}.
|
|
78
|
+
*/
|
|
79
|
+
export function normalizeForeignSpec(doc, targetUrl, protocol = detectProtocol(doc, targetUrl)) {
|
|
80
|
+
if (protocol === "a2a") return normalizeA2aCard(doc, targetUrl);
|
|
81
|
+
if (protocol === "mcp") return normalizeMcpCatalog(doc, targetUrl);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function a2aServiceUrls(card) {
|
|
86
|
+
const out = [];
|
|
87
|
+
if (typeof card?.url === "string" && card.url.trim()) out.push(card.url.trim());
|
|
88
|
+
for (const iface of [...(card?.supportedInterfaces || []), ...(card?.additionalInterfaces || [])]) {
|
|
89
|
+
if (typeof iface?.url === "string" && iface.url.trim()) out.push(iface.url.trim());
|
|
90
|
+
}
|
|
91
|
+
return [...new Set(out)];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function a2aServiceUrl(card) {
|
|
95
|
+
return a2aServiceUrls(card)[0] || "";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function normalizeA2aCard(doc, targetUrl) {
|
|
99
|
+
const card = doc && typeof doc === "object" ? doc : {};
|
|
100
|
+
const cardOrigin = originOf(targetUrl);
|
|
101
|
+
const serviceUrl = a2aServiceUrl(card);
|
|
102
|
+
const rpcOrigin = originOf(serviceUrl);
|
|
103
|
+
const entryName = safeSlug(card.name) || "a2a_agent";
|
|
104
|
+
const skills = Array.isArray(card.skills) ? card.skills : [];
|
|
105
|
+
const allExamples = [];
|
|
106
|
+
const frontTools = [];
|
|
107
|
+
const tools = [];
|
|
108
|
+
|
|
109
|
+
if (serviceUrl && rpcOrigin && cardOrigin && rpcOrigin !== cardOrigin) {
|
|
110
|
+
frontTools.push(serviceUrl);
|
|
111
|
+
}
|
|
112
|
+
for (const iface of [...(card.supportedInterfaces || []), ...(card.additionalInterfaces || [])]) {
|
|
113
|
+
if (typeof iface?.url === "string" && originOf(iface.url) && originOf(iface.url) !== cardOrigin) {
|
|
114
|
+
frontTools.push(iface.url);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
for (let i = 0; i < skills.length; i += 1) {
|
|
119
|
+
const s = skills[i] && typeof skills[i] === "object" ? skills[i] : { name: String(skills[i] || `skill_${i + 1}`) };
|
|
120
|
+
const skillName = safeSlug(s.id || s.name) || `skill_${i + 1}`;
|
|
121
|
+
frontTools.push(skillName);
|
|
122
|
+
const examples = (Array.isArray(s.examples) ? s.examples : [])
|
|
123
|
+
.map((ex) => (typeof ex === "string" ? ex : JSON.stringify(ex)))
|
|
124
|
+
.filter(Boolean);
|
|
125
|
+
allExamples.push(...examples);
|
|
126
|
+
const tags = Array.isArray(s.tags) ? s.tags.filter((t) => typeof t === "string") : [];
|
|
127
|
+
const schema = s.inputSchema && typeof s.inputSchema === "object"
|
|
128
|
+
? s.inputSchema
|
|
129
|
+
: (examples.length || tags.length)
|
|
130
|
+
? { type: "object", properties: { request: { type: "string", description: [...tags, ...examples].join(" | ") } } }
|
|
131
|
+
: { type: "object", properties: { request: { type: "string" } } };
|
|
132
|
+
|
|
133
|
+
tools.push({
|
|
134
|
+
name: skillName,
|
|
135
|
+
instructions: tags.length ? `Tags: ${tags.join(", ")}` : "",
|
|
136
|
+
command: [s.name, ...examples].filter(Boolean).join("\n"),
|
|
137
|
+
function: {
|
|
138
|
+
description: String(s.description || s.name || ""),
|
|
139
|
+
parameters: schema,
|
|
140
|
+
},
|
|
141
|
+
tools: [],
|
|
142
|
+
_skillId: s.id || "",
|
|
143
|
+
_rawProtocolItem: "a2a_skill",
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const versionSuffix = card.protocolVersion ? ` (${card.protocolVersion})` : card.version ? ` v${card.version}` : "";
|
|
148
|
+
const frontAgent = {
|
|
149
|
+
name: entryName,
|
|
150
|
+
instructions: String(card.description || ""),
|
|
151
|
+
command: "",
|
|
152
|
+
function: {
|
|
153
|
+
description: String(card.description || card.name || ""),
|
|
154
|
+
parameters: { type: "object", properties: { request: { type: "string" } }, required: ["request"] },
|
|
155
|
+
},
|
|
156
|
+
tools: [...new Set(frontTools)],
|
|
157
|
+
allow: card.capabilities?.pushNotifications ? { to_downstream: { push: true } } : undefined,
|
|
158
|
+
_rawProtocolItem: "a2a_card",
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const allowedPeers = [];
|
|
162
|
+
if (serviceUrl && rpcOrigin === cardOrigin) allowedPeers.push(rpcOrigin);
|
|
163
|
+
|
|
164
|
+
const manifest = {
|
|
165
|
+
brand: String(card.provider?.organization || card.name || ""),
|
|
166
|
+
networks: [{
|
|
167
|
+
name: entryName,
|
|
168
|
+
front_man: entryName,
|
|
169
|
+
description: String(card.description || ""),
|
|
170
|
+
sample_queries: allExamples,
|
|
171
|
+
}],
|
|
172
|
+
allowed_peers: allowedPeers,
|
|
173
|
+
peer_policy: { mode: "closed" },
|
|
174
|
+
a2a: card,
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
protocol: "a2a",
|
|
179
|
+
profile: `${PROTOCOL_PROFILES.a2a}${versionSuffix}`,
|
|
180
|
+
manifest,
|
|
181
|
+
entry: manifest.networks[0],
|
|
182
|
+
frontMan: entryName,
|
|
183
|
+
linkSlots: [],
|
|
184
|
+
config: {
|
|
185
|
+
metadata: {
|
|
186
|
+
name: String(card.name || ""),
|
|
187
|
+
description: String(card.description || ""),
|
|
188
|
+
sample_queries: allExamples,
|
|
189
|
+
},
|
|
190
|
+
tools: [frontAgent, ...tools],
|
|
191
|
+
},
|
|
192
|
+
rawDoc: card,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function normalizeMcpCatalog(doc, targetUrl) {
|
|
197
|
+
const root = doc?.result && typeof doc.result === "object" ? { ...doc, ...doc.result } : (doc || {});
|
|
198
|
+
const serverName = root.serverInfo?.name || root.name || "mcp_server";
|
|
199
|
+
const frontMan = safeSlug(serverName) || "mcp_server";
|
|
200
|
+
const rawTools = Array.isArray(root.tools) ? root.tools : [];
|
|
201
|
+
const rawPrompts = Array.isArray(root.prompts) ? root.prompts : [];
|
|
202
|
+
const rawResources = Array.isArray(root.resources) ? root.resources : [];
|
|
203
|
+
const rawServers = root.mcpServers && typeof root.mcpServers === "object" ? root.mcpServers : {};
|
|
204
|
+
const rawPackages = Array.isArray(root.packages) ? root.packages : [];
|
|
205
|
+
const rawRemotes = Array.isArray(root.remotes) ? root.remotes : [];
|
|
206
|
+
const targetOrigin = originOf(targetUrl);
|
|
207
|
+
|
|
208
|
+
const normalizedTools = [];
|
|
209
|
+
const frontRefs = [];
|
|
210
|
+
const allowedPeers = [];
|
|
211
|
+
|
|
212
|
+
for (const pkg of rawPackages) {
|
|
213
|
+
if (!pkg || typeof pkg !== "object") continue;
|
|
214
|
+
const pkgName = safeSlug(pkg.identifier || pkg.name) || "mcp_package";
|
|
215
|
+
frontRefs.push(pkgName);
|
|
216
|
+
normalizedTools.push({
|
|
217
|
+
name: pkgName,
|
|
218
|
+
instructions: pkg.transport?.type ? `Transport: ${pkg.transport.type}` : "",
|
|
219
|
+
command: "",
|
|
220
|
+
function: {
|
|
221
|
+
description: String(`${pkg.registryType || "package"} ${pkg.identifier || ""} ${pkg.version || ""}`.trim()),
|
|
222
|
+
parameters: { type: "object", properties: {} },
|
|
223
|
+
},
|
|
224
|
+
tools: [],
|
|
225
|
+
_rawProtocolItem: "mcp_package",
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
for (let i = 0; i < rawRemotes.length; i += 1) {
|
|
230
|
+
const rem = rawRemotes[i];
|
|
231
|
+
if (!rem || typeof rem !== "object") continue;
|
|
232
|
+
const remName = safeSlug(rem.name || `remote_${i + 1}`) || `remote_${i + 1}`;
|
|
233
|
+
frontRefs.push(remName);
|
|
234
|
+
const refs = [];
|
|
235
|
+
if (typeof rem.url === "string" && /^https?:\/\//i.test(rem.url)) {
|
|
236
|
+
refs.push({ url: rem.url, type: "mcp" });
|
|
237
|
+
if (originOf(rem.url) === targetOrigin) allowedPeers.push(targetOrigin);
|
|
238
|
+
}
|
|
239
|
+
normalizedTools.push({
|
|
240
|
+
name: remName,
|
|
241
|
+
instructions: rem.transportType ? `Remote transport: ${rem.transportType}` : "",
|
|
242
|
+
command: "",
|
|
243
|
+
function: { description: `Remote MCP endpoint (${rem.transportType || "http"})`, parameters: { type: "object", properties: {} } },
|
|
244
|
+
tools: refs,
|
|
245
|
+
_rawProtocolItem: "mcp_remote",
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
for (const [name, spec] of Object.entries(rawServers)) {
|
|
250
|
+
if (!spec || typeof spec !== "object") continue;
|
|
251
|
+
const entryName = safeSlug(name) || "mcp_endpoint";
|
|
252
|
+
frontRefs.push(entryName);
|
|
253
|
+
const serverRefs = [];
|
|
254
|
+
if (typeof spec.url === "string" && /^https?:\/\//i.test(spec.url)) {
|
|
255
|
+
serverRefs.push({ url: spec.url, type: "mcp" });
|
|
256
|
+
const o = originOf(spec.url);
|
|
257
|
+
if (o && o === targetOrigin) allowedPeers.push(o);
|
|
258
|
+
}
|
|
259
|
+
const cmdLine = [spec.command, ...(Array.isArray(spec.args) ? spec.args : [])].filter(Boolean).map(String).join(" ");
|
|
260
|
+
normalizedTools.push({
|
|
261
|
+
name: entryName,
|
|
262
|
+
instructions: cmdLine ? `Server command: ${cmdLine}` : "",
|
|
263
|
+
command: "",
|
|
264
|
+
function: {
|
|
265
|
+
description: String(spec.description || `Configured MCP server "${name}"`),
|
|
266
|
+
parameters: { type: "object", properties: {} },
|
|
267
|
+
},
|
|
268
|
+
tools: serverRefs,
|
|
269
|
+
_mcpServer: { name, command: spec.command || "", args: spec.args || [], url: spec.url || "", hasEnv: !!spec.env },
|
|
270
|
+
_rawProtocolItem: "mcp_server",
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
for (let i = 0; i < rawTools.length; i += 1) {
|
|
275
|
+
const raw = rawTools[i];
|
|
276
|
+
const t = raw && typeof raw === "object" ? raw : { name: typeof raw === "string" ? raw : `tool_${i + 1}` };
|
|
277
|
+
const name = String(t.name || `tool_${i + 1}`);
|
|
278
|
+
frontRefs.push(name);
|
|
279
|
+
const refs = [];
|
|
280
|
+
if (typeof t.url === "string" && /^https?:\/\//i.test(t.url)) refs.push({ url: t.url, type: "mcp" });
|
|
281
|
+
normalizedTools.push({
|
|
282
|
+
name,
|
|
283
|
+
instructions: "",
|
|
284
|
+
command: "",
|
|
285
|
+
function: {
|
|
286
|
+
description: String(t.description || ""),
|
|
287
|
+
parameters: t.inputSchema && typeof t.inputSchema === "object" ? t.inputSchema : null,
|
|
288
|
+
},
|
|
289
|
+
outputSchema: t.outputSchema && typeof t.outputSchema === "object" ? t.outputSchema : null,
|
|
290
|
+
tools: refs,
|
|
291
|
+
annotations: t.annotations && typeof t.annotations === "object" ? { ...t.annotations } : null,
|
|
292
|
+
_rawProtocolItem: "mcp_tool",
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
for (let i = 0; i < rawPrompts.length; i += 1) {
|
|
297
|
+
const p = rawPrompts[i] && typeof rawPrompts[i] === "object" ? rawPrompts[i] : { name: `prompt_${i + 1}` };
|
|
298
|
+
const argsProps = {};
|
|
299
|
+
for (const arg of Array.isArray(p.arguments) ? p.arguments : []) {
|
|
300
|
+
if (arg?.name) argsProps[arg.name] = { type: "string", description: String(arg.description || "") };
|
|
301
|
+
}
|
|
302
|
+
const promptTexts = [];
|
|
303
|
+
for (const msg of Array.isArray(p.messages) ? p.messages : []) {
|
|
304
|
+
if (!msg) continue;
|
|
305
|
+
if (typeof msg === "string") { promptTexts.push(msg); continue; }
|
|
306
|
+
const content = msg.content;
|
|
307
|
+
if (typeof content === "string") promptTexts.push(content);
|
|
308
|
+
else if (Array.isArray(content)) {
|
|
309
|
+
for (const part of content) {
|
|
310
|
+
if (typeof part === "string") promptTexts.push(part);
|
|
311
|
+
else if (typeof part?.text === "string") promptTexts.push(part.text);
|
|
312
|
+
}
|
|
313
|
+
} else if (content && typeof content === "object" && typeof content.text === "string") {
|
|
314
|
+
promptTexts.push(content.text);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
normalizedTools.push({
|
|
318
|
+
name: `prompt:${p.name || i + 1}`,
|
|
319
|
+
instructions: String(p.description || ""),
|
|
320
|
+
command: promptTexts.join("\n"),
|
|
321
|
+
function: {
|
|
322
|
+
description: String(p.description || ""),
|
|
323
|
+
parameters: { type: "object", properties: argsProps },
|
|
324
|
+
},
|
|
325
|
+
tools: [],
|
|
326
|
+
_rawProtocolItem: "mcp_prompt",
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const serverUrl = typeof root.url === "string" ? root.url : typeof root.endpoint === "string" ? root.endpoint : "";
|
|
331
|
+
if (serverUrl && /^https?:\/\//i.test(serverUrl)) {
|
|
332
|
+
const o = originOf(serverUrl);
|
|
333
|
+
if (o && targetOrigin && o === targetOrigin) allowedPeers.push(o);
|
|
334
|
+
if (o && targetOrigin && o !== targetOrigin) frontRefs.push({ url: serverUrl, type: "mcp" });
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const versionSuffix = root.protocolVersion ? ` (${root.protocolVersion})` : root.serverInfo?.version ? ` v${root.serverInfo.version}` : "";
|
|
338
|
+
const entryAgent = {
|
|
339
|
+
name: frontMan,
|
|
340
|
+
instructions: String(root.instructions || root.description || ""),
|
|
341
|
+
command: rawResources.map((r) => `${r?.name || ""} ${r?.description || ""} ${r?.uri || ""}`.trim()).filter(Boolean).join("\n"),
|
|
342
|
+
function: {
|
|
343
|
+
description: String(root.description || `MCP server exposing ${rawTools.length || Object.keys(rawServers).length} item(s).`),
|
|
344
|
+
parameters: { type: "object", properties: { request: { type: "string" } } },
|
|
345
|
+
},
|
|
346
|
+
tools: [...new Set(frontRefs)],
|
|
347
|
+
_rawProtocolItem: "mcp_entry",
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
// Avoid duplicating the entry name if a single tool has the same slug.
|
|
351
|
+
const deduped = normalizedTools.filter((t) => t.name !== frontMan);
|
|
352
|
+
const manifest = {
|
|
353
|
+
brand: String(root.serverInfo?.title || root.serverInfo?.name || root.name || ""),
|
|
354
|
+
networks: [{
|
|
355
|
+
name: frontMan,
|
|
356
|
+
front_man: frontMan,
|
|
357
|
+
description: String(root.description || ""),
|
|
358
|
+
}],
|
|
359
|
+
allowed_peers: [...new Set(allowedPeers)],
|
|
360
|
+
peer_policy: { mode: "closed" },
|
|
361
|
+
mcp: doc,
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
return {
|
|
365
|
+
protocol: "mcp",
|
|
366
|
+
profile: `${PROTOCOL_PROFILES.mcp}${versionSuffix}`,
|
|
367
|
+
manifest,
|
|
368
|
+
entry: manifest.networks[0],
|
|
369
|
+
frontMan,
|
|
370
|
+
linkSlots: [],
|
|
371
|
+
config: {
|
|
372
|
+
metadata: {
|
|
373
|
+
name: String(serverName),
|
|
374
|
+
description: String(root.description || ""),
|
|
375
|
+
},
|
|
376
|
+
tools: [entryAgent, ...deduped],
|
|
377
|
+
},
|
|
378
|
+
rawDoc: doc,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Evaluate Papers conformance and safety checks for Google A2A Agent Cards and MCP catalogs.
|
|
384
|
+
*/
|
|
385
|
+
export function evaluateForeignPapers({ protocol, target, rawDoc = {}, manifest = {}, config = {}, addFinding, addCheck, secretResult }) {
|
|
386
|
+
const { published = [], publishedList = "" } = secretResult || {};
|
|
387
|
+
addCheck({
|
|
388
|
+
id: "P-SECRETS",
|
|
389
|
+
section: protocol === "a2a" ? "A2A Security" : "MCP Security",
|
|
390
|
+
title: "No keys or passwords in public files",
|
|
391
|
+
status: published.length ? "fail" : "pass",
|
|
392
|
+
detail: published.length ? `${published.length} found: ${publishedList}.` : "None found.",
|
|
393
|
+
fix: "Remove secrets from public manifests and env maps, and rotate them immediately.",
|
|
394
|
+
});
|
|
395
|
+
if (published.length) {
|
|
396
|
+
addFinding({
|
|
397
|
+
rule: "S-SECRET",
|
|
398
|
+
category: "privacy",
|
|
399
|
+
severity: "medium",
|
|
400
|
+
title: "Publishes a key or password",
|
|
401
|
+
detail: `${published.length} in its public files: ${publishedList}. Shown shortened here.`,
|
|
402
|
+
where: { agent: published[0].agent, field: published[0].field },
|
|
403
|
+
why: "Anyone can read public manifests and copy published tokens or secrets.",
|
|
404
|
+
fix: "Remove credentials from public configs and supply tokens via runtime environment bindings.",
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const blocking = [];
|
|
409
|
+
|
|
410
|
+
if (protocol === "a2a") {
|
|
411
|
+
const hasName = typeof rawDoc.name === "string" && rawDoc.name.trim().length > 0;
|
|
412
|
+
const urlStr = a2aServiceUrl(rawDoc);
|
|
413
|
+
let urlValid = false;
|
|
414
|
+
let parsedUrl = null;
|
|
415
|
+
try {
|
|
416
|
+
if (urlStr) {
|
|
417
|
+
parsedUrl = new URL(urlStr, target.origin ? `${target.origin}/` : undefined);
|
|
418
|
+
urlValid = /^https?:$/.test(parsedUrl.protocol);
|
|
419
|
+
}
|
|
420
|
+
} catch { urlValid = false; }
|
|
421
|
+
|
|
422
|
+
const cardOk = hasName && urlValid;
|
|
423
|
+
addCheck({
|
|
424
|
+
id: "P-A2A-CARD",
|
|
425
|
+
section: "A2A §4",
|
|
426
|
+
title: "Agent Card declares name, description and URL",
|
|
427
|
+
status: cardOk ? (rawDoc.description ? "pass" : "warn") : "fail",
|
|
428
|
+
detail: !hasName ? "Missing required agent name." : !urlValid ? "Missing or invalid http/https service url." : rawDoc.description ? `Card "${rawDoc.name}" -> ${parsedUrl.origin}.` : "Valid card, but missing description.",
|
|
429
|
+
fix: "Provide valid name, description, and HTTPS url in the A2A Agent Card.",
|
|
430
|
+
});
|
|
431
|
+
if (!cardOk) blocking.push("its A2A card lacks a required name or valid URL");
|
|
432
|
+
|
|
433
|
+
if (urlValid && target.origin) {
|
|
434
|
+
const parsedAll = [];
|
|
435
|
+
for (const ifaceUrl of a2aServiceUrls(rawDoc)) {
|
|
436
|
+
try {
|
|
437
|
+
const u = new URL(ifaceUrl, target.origin ? `${target.origin}/` : undefined);
|
|
438
|
+
if (/^https?:$/.test(u.protocol)) parsedAll.push(u);
|
|
439
|
+
} catch { /* ignore invalid secondary */ }
|
|
440
|
+
}
|
|
441
|
+
const insecure = parsedAll.filter((u) => u.protocol !== "https:" && !target.loopback);
|
|
442
|
+
const offOrigin = parsedAll.filter((u) => u.origin !== target.origin);
|
|
443
|
+
addCheck({
|
|
444
|
+
id: "P-A2A-ENDPOINT",
|
|
445
|
+
section: "A2A §4, §7",
|
|
446
|
+
title: "A2A endpoint uses HTTPS on the expected origin",
|
|
447
|
+
status: insecure.length ? "fail" : offOrigin.length ? "warn" : "pass",
|
|
448
|
+
detail: insecure.length
|
|
449
|
+
? `Endpoint ${insecure[0].href} uses plain HTTP.`
|
|
450
|
+
: offOrigin.length
|
|
451
|
+
? `Points execution to another host (${[...new Set(offOrigin.map((u) => u.host))].join(", ")}).`
|
|
452
|
+
: "Matches publishing origin over HTTPS.",
|
|
453
|
+
fix: "Host all A2A JSON-RPC and interface endpoints on HTTPS on your own origin.",
|
|
454
|
+
});
|
|
455
|
+
if (offOrigin.length) {
|
|
456
|
+
const offHosts = [...new Set(offOrigin.map((u) => u.host))];
|
|
457
|
+
addFinding({
|
|
458
|
+
rule: "R-CROSS-ORIGIN-ENDPOINT",
|
|
459
|
+
category: "itinerary",
|
|
460
|
+
severity: "medium",
|
|
461
|
+
title: `Delegates execution to another origin (${offHosts.join(", ")})`,
|
|
462
|
+
detail: `The card published at ${target.host} declares interface URL(s) on ${offOrigin.map((u) => u.href).join(", ")}.`,
|
|
463
|
+
where: { field: "url / interfaces" },
|
|
464
|
+
why: "A card hosted on one domain can quietly route visitor requests to an unrelated server.",
|
|
465
|
+
fix: "Serve the Agent Card and all its RPC interface endpoints on the same origin.",
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const skills = Array.isArray(rawDoc.skills) ? rawDoc.skills : [];
|
|
471
|
+
const badSkills = skills.filter((s) => !s?.name || !s?.description);
|
|
472
|
+
addCheck({
|
|
473
|
+
id: "P-A2A-SKILLS",
|
|
474
|
+
section: "A2A §4.4",
|
|
475
|
+
title: "Declares skills with names and descriptions",
|
|
476
|
+
status: !skills.length ? "warn" : badSkills.length ? "warn" : "pass",
|
|
477
|
+
detail: !skills.length ? "No skills[] declared." : badSkills.length ? `${badSkills.length} skill(s) lack name or description.` : `${skills.length} skill(s) described.`,
|
|
478
|
+
fix: "Describe each entry in skills[] with id, name, and description.",
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
const hasAuth = !!(rawDoc.authentication || rawDoc.securitySchemes || rawDoc.security?.length);
|
|
482
|
+
addCheck({
|
|
483
|
+
id: "P-A2A-AUTH",
|
|
484
|
+
section: "A2A §4.5",
|
|
485
|
+
title: "Declares authentication requirements",
|
|
486
|
+
status: hasAuth ? "pass" : "warn",
|
|
487
|
+
detail: hasAuth ? "Authentication / securitySchemes declared." : "No authentication or securitySchemes field (public unauthenticated card).",
|
|
488
|
+
fix: "Declare securitySchemes or authentication modes required by callers.",
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
const hasModes = Array.isArray(rawDoc.defaultInputModes) || Array.isArray(rawDoc.defaultOutputModes);
|
|
492
|
+
addCheck({
|
|
493
|
+
id: "P-A2A-MODES",
|
|
494
|
+
section: "A2A §4",
|
|
495
|
+
title: "Declares supported input/output MIME modes",
|
|
496
|
+
status: hasModes ? "pass" : "warn",
|
|
497
|
+
detail: hasModes ? `Modes: ${(rawDoc.defaultInputModes || []).join(", ") || "default"}.` : "No defaultInputModes/defaultOutputModes.",
|
|
498
|
+
fix: 'Add defaultInputModes (e.g. ["text"]) and defaultOutputModes.',
|
|
499
|
+
});
|
|
500
|
+
return { blocking };
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// ---- MCP Catalog Checks --------------------------------------------------
|
|
504
|
+
const mcpRoot = rawDoc?.result && typeof rawDoc.result === "object" ? rawDoc.result : rawDoc;
|
|
505
|
+
const tools = Array.isArray(mcpRoot?.tools) ? mcpRoot.tools : [];
|
|
506
|
+
const servers = mcpRoot?.mcpServers && typeof mcpRoot.mcpServers === "object" ? Object.entries(mcpRoot.mcpServers) : [];
|
|
507
|
+
const packages = Array.isArray(mcpRoot?.packages) ? mcpRoot.packages : [];
|
|
508
|
+
const remotes = Array.isArray(mcpRoot?.remotes) ? mcpRoot.remotes : [];
|
|
509
|
+
const serverCount = servers.length + packages.length + remotes.length;
|
|
510
|
+
const hasItems = tools.length > 0 || serverCount > 0 || (Array.isArray(mcpRoot?.prompts) && mcpRoot.prompts.length > 0);
|
|
511
|
+
addCheck({
|
|
512
|
+
id: "P-MCP-SCHEMA",
|
|
513
|
+
section: "MCP Spec",
|
|
514
|
+
title: "Publishes valid MCP tools or server entries",
|
|
515
|
+
status: hasItems ? "pass" : "fail",
|
|
516
|
+
detail: hasItems ? `${tools.length} tool(s), ${serverCount} server/package ${serverCount === 1 ? "entry" : "entries"}.` : "No tools[], mcpServers, or packages[] found.",
|
|
517
|
+
fix: "Publish valid tools[], packages[], or mcpServers config entries.",
|
|
518
|
+
});
|
|
519
|
+
if (!hasItems) blocking.push("the MCP manifest lists no tools or servers");
|
|
520
|
+
|
|
521
|
+
const objectTools = tools.filter((t) => t && typeof t === "object");
|
|
522
|
+
const missingDesc = objectTools.filter((t) => !t.description).map((t) => t.name || "unnamed");
|
|
523
|
+
const missingSchema = objectTools.filter((t) => t.inputSchema?.type !== "object").map((t) => t.name || "unnamed");
|
|
524
|
+
const stringOnlyTools = tools.length > 0 && objectTools.length === 0;
|
|
525
|
+
addCheck({
|
|
526
|
+
id: "P-MCP-TOOLS",
|
|
527
|
+
section: "MCP Tools",
|
|
528
|
+
title: "Every MCP tool has a description and object inputSchema",
|
|
529
|
+
status: !tools.length ? (serverCount ? "pass" : "warn") : (stringOnlyTools || missingDesc.length || missingSchema.length) ? "warn" : "pass",
|
|
530
|
+
detail: !tools.length
|
|
531
|
+
? (packages.length ? `MCP registry manifest declaring ${packages.length} package(s).` : "No direct tools[] array (config manifest only).")
|
|
532
|
+
: stringOnlyTools
|
|
533
|
+
? `Lists ${tools.length} tool name(s) without inline JSON schemas.`
|
|
534
|
+
: (missingDesc.length || missingSchema.length)
|
|
535
|
+
? `Incomplete tool specs: ${[...new Set([...missingDesc, ...missingSchema])].slice(0, 5).join(", ")}.`
|
|
536
|
+
: `${tools.length} tool(s) expose structured JSON schemas.`,
|
|
537
|
+
fix: "Add clear description and type:\"object\" inputSchema for every MCP tool.",
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
const destructive = [];
|
|
541
|
+
const undocumentedPower = [];
|
|
542
|
+
for (const t of objectTools) {
|
|
543
|
+
const ann = t.annotations || {};
|
|
544
|
+
if (ann.destructiveHint === true) destructive.push(t.name);
|
|
545
|
+
else if (DESTRUCTIVE_NAME.test(String(t.name || "")) && ann.readOnlyHint !== true && ann.destructiveHint === undefined) {
|
|
546
|
+
undocumentedPower.push(t.name);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
addCheck({
|
|
550
|
+
id: "P-MCP-ANNOTATIONS",
|
|
551
|
+
section: "MCP 2025-03-26",
|
|
552
|
+
title: "Destructive or external tools declare behavior hints",
|
|
553
|
+
status: destructive.length ? "warn" : undocumentedPower.length ? "warn" : "pass",
|
|
554
|
+
detail: destructive.length
|
|
555
|
+
? `Destructive tool(s): ${destructive.join(", ")}.`
|
|
556
|
+
: undocumentedPower.length
|
|
557
|
+
? `State-changing names lack readOnlyHint/destructiveHint: ${undocumentedPower.join(", ")}.`
|
|
558
|
+
: "Safety annotations look consistent.",
|
|
559
|
+
fix: "Annotate tools with readOnlyHint, destructiveHint, and openWorldHint.",
|
|
560
|
+
});
|
|
561
|
+
if (destructive.length) {
|
|
562
|
+
addFinding({
|
|
563
|
+
rule: "M-DESTRUCTIVE",
|
|
564
|
+
category: "budget",
|
|
565
|
+
severity: "medium",
|
|
566
|
+
title: "Declares destructive MCP tool(s)",
|
|
567
|
+
detail: `Tool(s) marked destructiveHint: true — ${destructive.join(", ")}.`,
|
|
568
|
+
where: { agent: destructive[0], field: "annotations.destructiveHint" },
|
|
569
|
+
why: "Destructive tools can irreversibly modify or delete visitor or account state if invoked by a misled model.",
|
|
570
|
+
fix: "Require explicit user confirmation before invoking destructive tools.",
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
const shellServers = [];
|
|
575
|
+
const plainHttpServers = [];
|
|
576
|
+
for (const [name, spec] of servers) {
|
|
577
|
+
if (!spec || typeof spec !== "object") continue;
|
|
578
|
+
const cmdLine = [spec.command, ...(Array.isArray(spec.args) ? spec.args : [])].filter(Boolean).map(String).join(" ");
|
|
579
|
+
if (SHELL_RUNNER.test(cmdLine)) shellServers.push({ name, cmdLine });
|
|
580
|
+
if (typeof spec.url === "string" && /^http:\/\//i.test(spec.url) && !/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])/i.test(spec.url)) {
|
|
581
|
+
plainHttpServers.push({ name, url: spec.url });
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (shellServers.length) {
|
|
585
|
+
addFinding({
|
|
586
|
+
rule: "M-SHELL",
|
|
587
|
+
category: "itinerary",
|
|
588
|
+
severity: "high",
|
|
589
|
+
title: "MCP server config spawns an arbitrary shell command",
|
|
590
|
+
detail: `${shellServers.map((s) => `${s.name}: "${s.cmdLine.slice(0, 90)}"`).join("; ")}.`,
|
|
591
|
+
where: { agent: shellServers[0].name, field: "mcpServers.command" },
|
|
592
|
+
why: "Manifests running sh/bash/powershell or piping remote downloads run arbitrary OS commands on the host.",
|
|
593
|
+
fix: "Pin a specific non-shell binary/package and inspect arguments carefully.",
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
if (plainHttpServers.length) {
|
|
597
|
+
addCheck({
|
|
598
|
+
id: "P-MCP-TRANSPORT",
|
|
599
|
+
section: "MCP Auth",
|
|
600
|
+
title: "Remote MCP server endpoints use HTTPS",
|
|
601
|
+
status: "fail",
|
|
602
|
+
detail: `Plain HTTP endpoints: ${plainHttpServers.map((s) => s.url).join(", ")}.`,
|
|
603
|
+
fix: "Use HTTPS for remote MCP endpoints.",
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
return { blocking };
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
function safeSlug(value) {
|
|
611
|
+
return String(value ?? "").toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 48);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function originOf(url) {
|
|
615
|
+
try {
|
|
616
|
+
const u = new URL(String(url ?? ""));
|
|
617
|
+
return /^https?:$/.test(u.protocol) ? u.origin : "";
|
|
618
|
+
} catch {
|
|
619
|
+
return "";
|
|
620
|
+
}
|
|
621
|
+
}
|