@agent-vm/mcp-portal 0.0.92 → 0.0.94
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/dist/bin/mcp-portal.js +6 -6
- package/dist/cli/index.js +1 -1
- package/dist/core/index.js +4 -4
- package/dist/index.js +3 -3
- package/dist/mcp-proxy/index.js +1 -1
- package/dist/portal-config/index.js +2 -2
- package/dist/{portal-core-B8HZPw3z.js → portal-core-CYLdSvsL.js} +5 -5
- package/dist/{portal-core-B8HZPw3z.js.map → portal-core-CYLdSvsL.js.map} +1 -1
- package/dist/{portal-tools-fFyF72Nl.js → portal-tools-BhBrxlwi.js} +4 -4
- package/dist/{portal-tools-fFyF72Nl.js.map → portal-tools-BhBrxlwi.js.map} +1 -1
- package/dist/{resolve-agent-identity-BQNGUP66.js → resolve-agent-identity-BK4WlZgd.js} +3 -3
- package/dist/{resolve-agent-identity-BQNGUP66.js.map → resolve-agent-identity-BK4WlZgd.js.map} +1 -1
- package/dist/{serve-command-4BNOH14H.js → serve-command-B101-A2V.js} +4 -4
- package/dist/{serve-command-4BNOH14H.js.map → serve-command-B101-A2V.js.map} +1 -1
- package/dist/{typescript-artifact-EQH4tZ0C.js → typescript-artifact-CXxEYME7.js} +2 -2
- package/dist/{typescript-artifact-EQH4tZ0C.js.map → typescript-artifact-CXxEYME7.js.map} +1 -1
- package/dist/{upstream-mcp-client-runtime-vu2TiTUw.js → upstream-mcp-client-runtime-Bzy0aa0o.js} +3 -3
- package/dist/{upstream-mcp-client-runtime-vu2TiTUw.js.map → upstream-mcp-client-runtime-Bzy0aa0o.js.map} +1 -1
- package/dist/{upstream-response-middleware-_dthoE1r.js → upstream-response-middleware-fcJSrSEo.js} +2 -2
- package/dist/{upstream-response-middleware-_dthoE1r.js.map → upstream-response-middleware-fcJSrSEo.js.map} +1 -1
- package/dist/zod-schema-loader-BubVafy-.d.ts.map +1 -1
- package/dist/{zod-schema-loader-C3I-MnWq.js → zod-schema-loader-DI7JliBn.js} +141 -3
- package/dist/zod-schema-loader-DI7JliBn.js.map +1 -0
- package/package.json +4 -4
- package/dist/zod-schema-loader-C3I-MnWq.js.map +0 -1
|
@@ -100,6 +100,13 @@ function decodeToolRef(toolRef) {
|
|
|
100
100
|
}
|
|
101
101
|
//#endregion
|
|
102
102
|
//#region src/zod-schema-loader.ts
|
|
103
|
+
const normalizableTypeNames = new Set([
|
|
104
|
+
"array",
|
|
105
|
+
"boolean",
|
|
106
|
+
"integer",
|
|
107
|
+
"number",
|
|
108
|
+
"object"
|
|
109
|
+
]);
|
|
103
110
|
const unsupportedFeatures = new Set([
|
|
104
111
|
"contains",
|
|
105
112
|
"dependentSchemas",
|
|
@@ -113,6 +120,9 @@ const unsupportedFeatures = new Set([
|
|
|
113
120
|
function isJsonObject(value) {
|
|
114
121
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
115
122
|
}
|
|
123
|
+
function isJsonSchemaObject(value) {
|
|
124
|
+
return value !== void 0 && isJsonObject(value);
|
|
125
|
+
}
|
|
116
126
|
function findUnsupportedFeature(value, path = []) {
|
|
117
127
|
if (Array.isArray(value)) {
|
|
118
128
|
for (const [index, childValue] of value.entries()) {
|
|
@@ -156,6 +166,133 @@ function valueAtPath(value, path) {
|
|
|
156
166
|
function isJsonObjectValue(value) {
|
|
157
167
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
158
168
|
}
|
|
169
|
+
function schemaTypeName(schema) {
|
|
170
|
+
const type = schema.type;
|
|
171
|
+
if (typeof type === "string") return type;
|
|
172
|
+
if (!Array.isArray(type)) return;
|
|
173
|
+
const concreteTypeNames = type.filter((entry) => typeof entry === "string" && entry !== "null");
|
|
174
|
+
if (concreteTypeNames.length !== 1) return;
|
|
175
|
+
const concreteTypeName = concreteTypeNames[0];
|
|
176
|
+
if (concreteTypeName === void 0) return;
|
|
177
|
+
return normalizableTypeNames.has(concreteTypeName) ? concreteTypeName : void 0;
|
|
178
|
+
}
|
|
179
|
+
function localReferencePath(reference) {
|
|
180
|
+
if (!reference.startsWith("#/")) return null;
|
|
181
|
+
return reference.slice(2).split("/").map((part) => part.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
182
|
+
}
|
|
183
|
+
function schemaAtPath(rootSchema, path) {
|
|
184
|
+
let currentSchema = rootSchema;
|
|
185
|
+
for (const pathPart of path) {
|
|
186
|
+
if (!isJsonObject(currentSchema)) return null;
|
|
187
|
+
const nextSchema = currentSchema[pathPart];
|
|
188
|
+
if (nextSchema === void 0) return null;
|
|
189
|
+
currentSchema = nextSchema;
|
|
190
|
+
}
|
|
191
|
+
return isJsonObject(currentSchema) ? currentSchema : null;
|
|
192
|
+
}
|
|
193
|
+
function resolveLocalSchemaReference(rootSchema, reference) {
|
|
194
|
+
if (typeof reference !== "string") return null;
|
|
195
|
+
const path = localReferencePath(reference);
|
|
196
|
+
return path === null ? null : schemaAtPath(rootSchema, path);
|
|
197
|
+
}
|
|
198
|
+
function allOfSchemas(schema) {
|
|
199
|
+
const allOf = schema.allOf;
|
|
200
|
+
if (!Array.isArray(allOf)) return [];
|
|
201
|
+
return allOf.filter((entry) => isJsonObject(entry));
|
|
202
|
+
}
|
|
203
|
+
function isObjectLikeSchema(schema, type) {
|
|
204
|
+
return type === "object" || isJsonSchemaObject(schema.properties) || isJsonSchemaObject(schema.patternProperties) || isJsonSchemaObject(schema.additionalProperties);
|
|
205
|
+
}
|
|
206
|
+
function isArrayLikeSchema(schema, type) {
|
|
207
|
+
return type === "array" || Array.isArray(schema.prefixItems) || schema.items !== void 0;
|
|
208
|
+
}
|
|
209
|
+
function parseJsonString(value) {
|
|
210
|
+
try {
|
|
211
|
+
return {
|
|
212
|
+
ok: true,
|
|
213
|
+
value: JSON.parse(value)
|
|
214
|
+
};
|
|
215
|
+
} catch {
|
|
216
|
+
return { ok: false };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function parseStringNumber(value, props) {
|
|
220
|
+
const trimmedValue = value.trim();
|
|
221
|
+
if (!/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:e[+-]?\d+)?$/iu.test(trimmedValue)) return null;
|
|
222
|
+
const parsedValue = Number(trimmedValue);
|
|
223
|
+
if (!Number.isFinite(parsedValue)) return null;
|
|
224
|
+
if (props.integer && !Number.isInteger(parsedValue)) return null;
|
|
225
|
+
return parsedValue;
|
|
226
|
+
}
|
|
227
|
+
function parseStringBoolean(value) {
|
|
228
|
+
const trimmedValue = value.trim();
|
|
229
|
+
if (trimmedValue === "true") return true;
|
|
230
|
+
if (trimmedValue === "false") return false;
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
function normalizeObjectValueForJsonSchema(schema, value, rootSchema) {
|
|
234
|
+
const normalizedValue = { ...value };
|
|
235
|
+
const properties = schema.properties;
|
|
236
|
+
if (isJsonSchemaObject(properties)) {
|
|
237
|
+
for (const [propertyName, propertySchema] of Object.entries(properties)) if (propertyName in normalizedValue && isJsonSchemaObject(propertySchema)) normalizedValue[propertyName] = normalizeValueForJsonSchema(propertySchema, normalizedValue[propertyName], rootSchema);
|
|
238
|
+
}
|
|
239
|
+
const patternProperties = schema.patternProperties;
|
|
240
|
+
const matchedPatternProperties = /* @__PURE__ */ new Set();
|
|
241
|
+
if (isJsonSchemaObject(patternProperties)) for (const [pattern, patternSchema] of Object.entries(patternProperties)) {
|
|
242
|
+
if (!isJsonSchemaObject(patternSchema)) continue;
|
|
243
|
+
let regex;
|
|
244
|
+
try {
|
|
245
|
+
regex = new RegExp(pattern, "u");
|
|
246
|
+
} catch {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
for (const propertyName of Object.keys(normalizedValue)) if (regex.test(propertyName)) {
|
|
250
|
+
normalizedValue[propertyName] = normalizeValueForJsonSchema(patternSchema, normalizedValue[propertyName], rootSchema);
|
|
251
|
+
matchedPatternProperties.add(propertyName);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const additionalProperties = schema.additionalProperties;
|
|
255
|
+
if (isJsonSchemaObject(additionalProperties)) for (const propertyName of Object.keys(normalizedValue)) {
|
|
256
|
+
if (isJsonSchemaObject(properties) && propertyName in properties) continue;
|
|
257
|
+
if (matchedPatternProperties.has(propertyName)) continue;
|
|
258
|
+
normalizedValue[propertyName] = normalizeValueForJsonSchema(additionalProperties, normalizedValue[propertyName], rootSchema);
|
|
259
|
+
}
|
|
260
|
+
return normalizedValue;
|
|
261
|
+
}
|
|
262
|
+
function normalizeArrayValueForJsonSchema(schema, value, rootSchema) {
|
|
263
|
+
const items = schema.items;
|
|
264
|
+
const prefixItems = schema.prefixItems;
|
|
265
|
+
if (Array.isArray(prefixItems)) return value.map((entry, index) => {
|
|
266
|
+
const itemSchema = prefixItems[index];
|
|
267
|
+
if (isJsonSchemaObject(itemSchema)) return normalizeValueForJsonSchema(itemSchema, entry, rootSchema);
|
|
268
|
+
if (isJsonSchemaObject(items)) return normalizeValueForJsonSchema(items, entry, rootSchema);
|
|
269
|
+
return entry;
|
|
270
|
+
});
|
|
271
|
+
if (Array.isArray(items)) return value.map((entry, index) => {
|
|
272
|
+
const itemSchema = items[index];
|
|
273
|
+
return isJsonSchemaObject(itemSchema) ? normalizeValueForJsonSchema(itemSchema, entry, rootSchema) : entry;
|
|
274
|
+
});
|
|
275
|
+
if (isJsonSchemaObject(items)) return value.map((entry) => normalizeValueForJsonSchema(items, entry, rootSchema));
|
|
276
|
+
return value;
|
|
277
|
+
}
|
|
278
|
+
function normalizeValueForJsonSchema(schema, value, rootSchema = schema) {
|
|
279
|
+
const referencedSchema = resolveLocalSchemaReference(rootSchema, schema.$ref);
|
|
280
|
+
if (referencedSchema !== null) return normalizeValueForJsonSchema(referencedSchema, value, rootSchema);
|
|
281
|
+
let normalizedValue = value;
|
|
282
|
+
for (const allOfSchema of allOfSchemas(schema)) normalizedValue = normalizeValueForJsonSchema(allOfSchema, normalizedValue, rootSchema);
|
|
283
|
+
const type = schemaTypeName(schema);
|
|
284
|
+
const isObjectLike = isObjectLikeSchema(schema, type);
|
|
285
|
+
const isArrayLike = isArrayLikeSchema(schema, type);
|
|
286
|
+
if ((type === "number" || type === "integer") && typeof normalizedValue === "string") return parseStringNumber(normalizedValue, { integer: type === "integer" }) ?? normalizedValue;
|
|
287
|
+
if (type === "boolean" && typeof normalizedValue === "string") return parseStringBoolean(normalizedValue) ?? normalizedValue;
|
|
288
|
+
if ((isObjectLike || isArrayLike) && typeof normalizedValue === "string") {
|
|
289
|
+
const parsedValue = parseJsonString(normalizedValue);
|
|
290
|
+
if (parsedValue.ok && (isObjectLike && isJsonObjectValue(parsedValue.value) || isArrayLike && Array.isArray(parsedValue.value))) normalizedValue = parsedValue.value;
|
|
291
|
+
}
|
|
292
|
+
if (isObjectLike && isJsonObjectValue(normalizedValue)) return normalizeObjectValueForJsonSchema(schema, normalizedValue, rootSchema);
|
|
293
|
+
if (isArrayLike && Array.isArray(normalizedValue)) return normalizeArrayValueForJsonSchema(schema, normalizedValue, rootSchema);
|
|
294
|
+
return normalizedValue;
|
|
295
|
+
}
|
|
159
296
|
function jsonTypeName(value) {
|
|
160
297
|
if (value === void 0) return "undefined";
|
|
161
298
|
if (value === null) return "null";
|
|
@@ -229,7 +366,8 @@ function buildZodValidatorFromJsonSchema(jsonSchema) {
|
|
|
229
366
|
return {
|
|
230
367
|
ok: true,
|
|
231
368
|
validate(value) {
|
|
232
|
-
const
|
|
369
|
+
const normalizedValue = normalizeValueForJsonSchema(jsonSchema, value);
|
|
370
|
+
const parsed = zodSchema.safeParse(normalizedValue);
|
|
233
371
|
if (parsed.success) return {
|
|
234
372
|
ok: true,
|
|
235
373
|
value: parsed.data
|
|
@@ -237,7 +375,7 @@ function buildZodValidatorFromJsonSchema(jsonSchema) {
|
|
|
237
375
|
return {
|
|
238
376
|
error: {
|
|
239
377
|
kind: "input_validation",
|
|
240
|
-
issues: parsed.error.issues.map((issue) => toValidationIssue(issue,
|
|
378
|
+
issues: parsed.error.issues.map((issue) => toValidationIssue(issue, normalizedValue))
|
|
241
379
|
},
|
|
242
380
|
ok: false
|
|
243
381
|
};
|
|
@@ -258,4 +396,4 @@ function buildZodValidatorFromJsonSchema(jsonSchema) {
|
|
|
258
396
|
//#endregion
|
|
259
397
|
export { portalToolRecordSchema as a, isJsonObject$1 as c, portalToolAnnotationsSchema as i, jsonObjectSchema as l, decodeToolRef as n, safeToolMetadataSchema as o, encodeToolRef as r, assertJsonObject as s, buildZodValidatorFromJsonSchema as t, jsonValueSchema as u };
|
|
260
398
|
|
|
261
|
-
//# sourceMappingURL=zod-schema-loader-
|
|
399
|
+
//# sourceMappingURL=zod-schema-loader-DI7JliBn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-schema-loader-DI7JliBn.js","names":["isJsonObject"],"sources":["../src/json-schema.ts","../src/catalog-types.ts","../src/tool-ref.ts","../src/zod-schema-loader.ts"],"sourcesContent":["import { z } from 'zod';\n\nexport type JsonPrimitive = boolean | null | number | string;\nexport type JsonArray = JsonValue[];\nexport type JsonObject = { [key: string]: JsonValue };\nexport type JsonValue = JsonArray | JsonObject | JsonPrimitive;\n\nexport const jsonValueSchema: z.ZodType<JsonValue> = z.lazy(() =>\n\tz.union([\n\t\tz.string(),\n\t\tz.number().finite(),\n\t\tz.boolean(),\n\t\tz.null(),\n\t\tz.array(jsonValueSchema),\n\t\tjsonObjectSchema,\n\t]),\n);\n\nexport const jsonObjectSchema: z.ZodType<JsonObject> = z.record(z.string(), jsonValueSchema);\n\nexport function isJsonObject(value: unknown): value is JsonObject {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function assertJsonObject(value: unknown, label: string): JsonObject {\n\tif (!isJsonObject(value)) {\n\t\tthrow new Error(`${label} must be a JSON object.`);\n\t}\n\n\treturn jsonObjectSchema.parse(value);\n}\n","import { z } from 'zod';\n\nimport { jsonObjectSchema, type JsonObject, type JsonValue } from './json-schema.js';\n\nconst forbiddenMetadataKeys = new Set([\n\t'agentid',\n\t'authprofile',\n\t'bindingid',\n\t'runid',\n\t'sessionid',\n]);\n\nfunction findForbiddenMetadataKey(value: JsonObject): string | null {\n\tconst stack: JsonValue[] = [value];\n\n\twhile (stack.length > 0) {\n\t\tconst current = stack.pop();\n\t\tif (!current) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (Array.isArray(current)) {\n\t\t\tstack.push(...current);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (typeof current !== 'object' || current === null) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (const [key, childValue] of Object.entries(current)) {\n\t\t\tif (forbiddenMetadataKeys.has(key.toLowerCase())) {\n\t\t\t\treturn key;\n\t\t\t}\n\t\t\tif (typeof childValue === 'object' && childValue !== null) {\n\t\t\t\tstack.push(childValue);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport const portalToolAnnotationsSchema = z\n\t.object({\n\t\tdestructiveHint: z.boolean().optional(),\n\t\tidempotentHint: z.boolean().optional(),\n\t\topenWorldHint: z.boolean().optional(),\n\t\treadOnlyHint: z.boolean().optional(),\n\t\ttitle: z.string().optional(),\n\t})\n\t.catchall(jsonObjectSchema.or(z.string()).or(z.number()).or(z.boolean()).or(z.null()))\n\t.optional();\n\nexport const safeToolMetadataSchema = jsonObjectSchema\n\t.optional()\n\t.superRefine((metadata, context) => {\n\t\tif (!metadata) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst forbiddenKey = findForbiddenMetadataKey(metadata);\n\t\tif (forbiddenKey) {\n\t\t\tcontext.addIssue({\n\t\t\t\tcode: 'custom',\n\t\t\t\tmessage: `metadata contains forbidden key \"${forbiddenKey}\"`,\n\t\t\t});\n\t\t}\n\t});\n\nexport const portalToolRecordSchema = z\n\t.object({\n\t\tannotations: portalToolAnnotationsSchema,\n\t\tdescription: z.string().optional(),\n\t\tinputSchema: jsonObjectSchema,\n\t\tmetadata: safeToolMetadataSchema,\n\t\tnamespace: z.string().min(1),\n\t\toutputSchema: jsonObjectSchema.optional(),\n\t\ttitle: z.string().optional(),\n\t\ttoolName: z.string().min(1),\n\t})\n\t.strict();\n\nexport type PortalToolRecord = z.infer<typeof portalToolRecordSchema>;\nexport type PortalToolAnnotations = z.infer<typeof portalToolAnnotationsSchema>;\n","import { z } from 'zod';\n\nexport interface ToolIdentity {\n\treadonly namespace: string;\n\treadonly toolName: string;\n}\n\nconst toolIdentitySchema = z\n\t.object({\n\t\tnamespace: z.string().min(1),\n\t\ttoolName: z.string().min(1),\n\t})\n\t.strict();\nconst toolRefSchema = z.string().startsWith('mcp:').brand<'ToolRef'>();\n\nexport type ToolRef = z.infer<typeof toolRefSchema>;\n\nfunction decodeToolRefSegment(segment: string): string {\n\tif (!/^[A-Za-z0-9_-]+$/.test(segment)) {\n\t\tthrow new Error('Invalid MCP toolRef.');\n\t}\n\n\tconst decoded = Buffer.from(segment, 'base64url').toString('utf-8');\n\tconst canonicalSegment = Buffer.from(decoded, 'utf-8').toString('base64url');\n\tif (canonicalSegment !== segment) {\n\t\tthrow new Error('Invalid MCP toolRef.');\n\t}\n\n\treturn decoded;\n}\n\nexport function encodeToolRef(identity: ToolIdentity): ToolRef {\n\tconst parsed = toolIdentitySchema.parse(identity);\n\tconst encodedNamespace = Buffer.from(parsed.namespace, 'utf-8').toString('base64url');\n\tconst encodedToolName = Buffer.from(parsed.toolName, 'utf-8').toString('base64url');\n\n\treturn toolRefSchema.parse(`mcp:${encodedNamespace}:${encodedToolName}`);\n}\n\nexport function decodeToolRef(toolRef: string | ToolRef): ToolIdentity {\n\tconst [scheme, encodedNamespace, encodedToolName, ...extraParts] = toolRef.split(':');\n\tif (scheme !== 'mcp' || !encodedNamespace || !encodedToolName || extraParts.length > 0) {\n\t\tthrow new Error('Invalid MCP toolRef.');\n\t}\n\n\ttry {\n\t\treturn toolIdentitySchema.parse({\n\t\t\tnamespace: decodeToolRefSegment(encodedNamespace),\n\t\t\ttoolName: decodeToolRefSegment(encodedToolName),\n\t\t});\n\t} catch {\n\t\tthrow new Error('Invalid MCP toolRef.');\n\t}\n}\n","import { z } from 'zod';\n\nimport type { JsonObject, JsonValue } from './json-schema.js';\n\nexport interface InputValidationIssue {\n\treadonly code: string;\n\treadonly expected?: string;\n\treadonly keys?: readonly string[];\n\treadonly message: string;\n\treadonly path: readonly (number | string)[];\n\treadonly received?: {\n\t\treadonly preview?: string;\n\t\treadonly type: string;\n\t};\n\treadonly values?: readonly JsonValue[];\n}\n\nexport interface InputValidationError {\n\treadonly kind: 'input_validation';\n\treadonly issues: readonly InputValidationIssue[];\n}\n\nexport interface SchemaValidationUnavailableError {\n\treadonly feature: string;\n\treadonly kind: 'schema_validation_unavailable';\n\treadonly message: string;\n\treadonly path: readonly (number | string)[];\n}\n\nexport type PortalValidationResult =\n\t| { readonly ok: true; readonly value: unknown }\n\t| { readonly error: InputValidationError; readonly ok: false };\n\nexport type BuiltZodValidator =\n\t| {\n\t\t\treadonly ok: true;\n\t\t\treadonly validate: (value: unknown) => PortalValidationResult;\n\t }\n\t| {\n\t\t\treadonly error: SchemaValidationUnavailableError;\n\t\t\treadonly ok: false;\n\t };\n\ninterface UnsupportedFeature {\n\treadonly feature: string;\n\treadonly path: readonly (number | string)[];\n}\n\ntype JsonStringParseResult =\n\t| { readonly ok: true; readonly value: unknown }\n\t| { readonly ok: false };\n\nconst normalizableTypeNames = new Set(['array', 'boolean', 'integer', 'number', 'object']);\nconst unsupportedFeatures = new Set([\n\t'contains',\n\t'dependentSchemas',\n\t'else',\n\t'if',\n\t'not',\n\t'then',\n\t'unevaluatedProperties',\n\t'uniqueItems',\n]);\n\nfunction isJsonObject(value: JsonValue): value is JsonObject {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isJsonSchemaObject(value: JsonValue | undefined): value is JsonObject {\n\treturn value !== undefined && isJsonObject(value);\n}\n\nfunction findUnsupportedFeature(\n\tvalue: JsonValue,\n\tpath: readonly (number | string)[] = [],\n): UnsupportedFeature | null {\n\tif (Array.isArray(value)) {\n\t\tfor (const [index, childValue] of value.entries()) {\n\t\t\tconst childUnsupported = findUnsupportedFeature(childValue, [...path, index]);\n\t\t\tif (childUnsupported) {\n\t\t\t\treturn childUnsupported;\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\n\tif (!isJsonObject(value)) {\n\t\treturn null;\n\t}\n\n\tfor (const [key, childValue] of Object.entries(value)) {\n\t\tif (unsupportedFeatures.has(key)) {\n\t\t\treturn { feature: key, path: [...path, key] };\n\t\t}\n\t\tconst childUnsupported = findUnsupportedFeature(childValue, [...path, key]);\n\t\tif (childUnsupported) {\n\t\t\treturn childUnsupported;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nfunction unavailableError(\n\tfeature: string,\n\tpath: readonly (number | string)[],\n): SchemaValidationUnavailableError {\n\treturn {\n\t\tfeature,\n\t\tkind: 'schema_validation_unavailable',\n\t\tmessage: `JSON Schema feature \"${feature}\" is not supported by the portal validator.`,\n\t\tpath,\n\t};\n}\n\nfunction valueAtPath(value: unknown, path: readonly (number | string)[]): unknown {\n\tlet currentValue = value;\n\tfor (const pathPart of path) {\n\t\tif (typeof pathPart === 'number') {\n\t\t\tif (!Array.isArray(currentValue)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tcurrentValue = currentValue[pathPart];\n\t\t\tcontinue;\n\t\t}\n\t\tif (!isJsonObjectValue(currentValue)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tcurrentValue = currentValue[pathPart];\n\t}\n\treturn currentValue;\n}\n\nfunction isJsonObjectValue(value: unknown): value is Readonly<Record<string, unknown>> {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction schemaTypeName(schema: JsonObject): string | undefined {\n\tconst type = schema.type;\n\tif (typeof type === 'string') {\n\t\treturn type;\n\t}\n\tif (!Array.isArray(type)) {\n\t\treturn undefined;\n\t}\n\tconst concreteTypeNames = type.filter(\n\t\t(entry): entry is string => typeof entry === 'string' && entry !== 'null',\n\t);\n\tif (concreteTypeNames.length !== 1) {\n\t\treturn undefined;\n\t}\n\tconst concreteTypeName = concreteTypeNames[0];\n\tif (concreteTypeName === undefined) {\n\t\treturn undefined;\n\t}\n\treturn normalizableTypeNames.has(concreteTypeName) ? concreteTypeName : undefined;\n}\n\nfunction localReferencePath(reference: string): readonly string[] | null {\n\tif (!reference.startsWith('#/')) {\n\t\treturn null;\n\t}\n\treturn reference\n\t\t.slice(2)\n\t\t.split('/')\n\t\t.map((part) => part.replaceAll('~1', '/').replaceAll('~0', '~'));\n}\n\nfunction schemaAtPath(rootSchema: JsonObject, path: readonly string[]): JsonObject | null {\n\tlet currentSchema: JsonValue = rootSchema;\n\tfor (const pathPart of path) {\n\t\tif (!isJsonObject(currentSchema)) {\n\t\t\treturn null;\n\t\t}\n\t\tconst nextSchema: JsonValue | undefined = currentSchema[pathPart];\n\t\tif (nextSchema === undefined) {\n\t\t\treturn null;\n\t\t}\n\t\tcurrentSchema = nextSchema;\n\t}\n\treturn isJsonObject(currentSchema) ? currentSchema : null;\n}\n\nfunction resolveLocalSchemaReference(\n\trootSchema: JsonObject,\n\treference: JsonValue | undefined,\n): JsonObject | null {\n\tif (typeof reference !== 'string') {\n\t\treturn null;\n\t}\n\tconst path = localReferencePath(reference);\n\treturn path === null ? null : schemaAtPath(rootSchema, path);\n}\n\nfunction allOfSchemas(schema: JsonObject): readonly JsonObject[] {\n\tconst allOf = schema.allOf;\n\tif (!Array.isArray(allOf)) {\n\t\treturn [];\n\t}\n\treturn allOf.filter((entry): entry is JsonObject => isJsonObject(entry));\n}\n\nfunction isObjectLikeSchema(schema: JsonObject, type: string | undefined): boolean {\n\treturn (\n\t\ttype === 'object' ||\n\t\tisJsonSchemaObject(schema.properties) ||\n\t\tisJsonSchemaObject(schema.patternProperties) ||\n\t\tisJsonSchemaObject(schema.additionalProperties)\n\t);\n}\n\nfunction isArrayLikeSchema(schema: JsonObject, type: string | undefined): boolean {\n\treturn type === 'array' || Array.isArray(schema.prefixItems) || schema.items !== undefined;\n}\n\nfunction parseJsonString(value: string): JsonStringParseResult {\n\ttry {\n\t\tconst parsedValue: unknown = JSON.parse(value);\n\t\treturn { ok: true, value: parsedValue };\n\t} catch {\n\t\treturn { ok: false };\n\t}\n}\n\nfunction parseStringNumber(value: string, props: { readonly integer: boolean }): number | null {\n\tconst trimmedValue = value.trim();\n\tif (!/^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:e[+-]?\\d+)?$/iu.test(trimmedValue)) {\n\t\treturn null;\n\t}\n\tconst parsedValue = Number(trimmedValue);\n\tif (!Number.isFinite(parsedValue)) {\n\t\treturn null;\n\t}\n\tif (props.integer && !Number.isInteger(parsedValue)) {\n\t\treturn null;\n\t}\n\treturn parsedValue;\n}\n\nfunction parseStringBoolean(value: string): boolean | null {\n\tconst trimmedValue = value.trim();\n\tif (trimmedValue === 'true') {\n\t\treturn true;\n\t}\n\tif (trimmedValue === 'false') {\n\t\treturn false;\n\t}\n\treturn null;\n}\n\nfunction normalizeObjectValueForJsonSchema(\n\tschema: JsonObject,\n\tvalue: Readonly<Record<string, unknown>>,\n\trootSchema: JsonObject,\n): Record<string, unknown> {\n\tconst normalizedValue: Record<string, unknown> = { ...value };\n\tconst properties = schema.properties;\n\tif (isJsonSchemaObject(properties)) {\n\t\tfor (const [propertyName, propertySchema] of Object.entries(properties)) {\n\t\t\tif (propertyName in normalizedValue && isJsonSchemaObject(propertySchema)) {\n\t\t\t\tnormalizedValue[propertyName] = normalizeValueForJsonSchema(\n\t\t\t\t\tpropertySchema,\n\t\t\t\t\tnormalizedValue[propertyName],\n\t\t\t\t\trootSchema,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst patternProperties = schema.patternProperties;\n\tconst matchedPatternProperties = new Set<string>();\n\tif (isJsonSchemaObject(patternProperties)) {\n\t\tfor (const [pattern, patternSchema] of Object.entries(patternProperties)) {\n\t\t\tif (!isJsonSchemaObject(patternSchema)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet regex: RegExp;\n\t\t\ttry {\n\t\t\t\tregex = new RegExp(pattern, 'u');\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const propertyName of Object.keys(normalizedValue)) {\n\t\t\t\tif (regex.test(propertyName)) {\n\t\t\t\t\tnormalizedValue[propertyName] = normalizeValueForJsonSchema(\n\t\t\t\t\t\tpatternSchema,\n\t\t\t\t\t\tnormalizedValue[propertyName],\n\t\t\t\t\t\trootSchema,\n\t\t\t\t\t);\n\t\t\t\t\tmatchedPatternProperties.add(propertyName);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst additionalProperties = schema.additionalProperties;\n\tif (isJsonSchemaObject(additionalProperties)) {\n\t\tfor (const propertyName of Object.keys(normalizedValue)) {\n\t\t\tif (isJsonSchemaObject(properties) && propertyName in properties) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (matchedPatternProperties.has(propertyName)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tnormalizedValue[propertyName] = normalizeValueForJsonSchema(\n\t\t\t\tadditionalProperties,\n\t\t\t\tnormalizedValue[propertyName],\n\t\t\t\trootSchema,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn normalizedValue;\n}\n\nfunction normalizeArrayValueForJsonSchema(\n\tschema: JsonObject,\n\tvalue: readonly unknown[],\n\trootSchema: JsonObject,\n): readonly unknown[] {\n\tconst items = schema.items;\n\tconst prefixItems = schema.prefixItems;\n\tif (Array.isArray(prefixItems)) {\n\t\treturn value.map((entry, index) => {\n\t\t\tconst itemSchema = prefixItems[index];\n\t\t\tif (isJsonSchemaObject(itemSchema)) {\n\t\t\t\treturn normalizeValueForJsonSchema(itemSchema, entry, rootSchema);\n\t\t\t}\n\t\t\tif (isJsonSchemaObject(items)) {\n\t\t\t\treturn normalizeValueForJsonSchema(items, entry, rootSchema);\n\t\t\t}\n\t\t\treturn entry;\n\t\t});\n\t}\n\n\tif (Array.isArray(items)) {\n\t\treturn value.map((entry, index) => {\n\t\t\tconst itemSchema = items[index];\n\t\t\treturn isJsonSchemaObject(itemSchema)\n\t\t\t\t? normalizeValueForJsonSchema(itemSchema, entry, rootSchema)\n\t\t\t\t: entry;\n\t\t});\n\t}\n\tif (isJsonSchemaObject(items)) {\n\t\treturn value.map((entry) => normalizeValueForJsonSchema(items, entry, rootSchema));\n\t}\n\treturn value;\n}\n\nfunction normalizeValueForJsonSchema(\n\tschema: JsonObject,\n\tvalue: unknown,\n\trootSchema: JsonObject = schema,\n): unknown {\n\tconst referencedSchema = resolveLocalSchemaReference(rootSchema, schema.$ref);\n\tif (referencedSchema !== null) {\n\t\treturn normalizeValueForJsonSchema(referencedSchema, value, rootSchema);\n\t}\n\n\tlet normalizedValue = value;\n\tfor (const allOfSchema of allOfSchemas(schema)) {\n\t\tnormalizedValue = normalizeValueForJsonSchema(allOfSchema, normalizedValue, rootSchema);\n\t}\n\n\tconst type = schemaTypeName(schema);\n\tconst isObjectLike = isObjectLikeSchema(schema, type);\n\tconst isArrayLike = isArrayLikeSchema(schema, type);\n\tif ((type === 'number' || type === 'integer') && typeof normalizedValue === 'string') {\n\t\treturn parseStringNumber(normalizedValue, { integer: type === 'integer' }) ?? normalizedValue;\n\t}\n\tif (type === 'boolean' && typeof normalizedValue === 'string') {\n\t\treturn parseStringBoolean(normalizedValue) ?? normalizedValue;\n\t}\n\n\tif ((isObjectLike || isArrayLike) && typeof normalizedValue === 'string') {\n\t\tconst parsedValue = parseJsonString(normalizedValue);\n\t\tif (\n\t\t\tparsedValue.ok &&\n\t\t\t((isObjectLike && isJsonObjectValue(parsedValue.value)) ||\n\t\t\t\t(isArrayLike && Array.isArray(parsedValue.value)))\n\t\t) {\n\t\t\tnormalizedValue = parsedValue.value;\n\t\t}\n\t}\n\n\tif (isObjectLike && isJsonObjectValue(normalizedValue)) {\n\t\treturn normalizeObjectValueForJsonSchema(schema, normalizedValue, rootSchema);\n\t}\n\tif (isArrayLike && Array.isArray(normalizedValue)) {\n\t\treturn normalizeArrayValueForJsonSchema(schema, normalizedValue, rootSchema);\n\t}\n\treturn normalizedValue;\n}\n\nfunction jsonTypeName(value: unknown): string {\n\tif (value === undefined) {\n\t\treturn 'undefined';\n\t}\n\tif (value === null) {\n\t\treturn 'null';\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn 'array';\n\t}\n\treturn typeof value;\n}\n\nfunction jsonValuePreview(value: unknown): string | undefined {\n\tif (value === undefined) {\n\t\treturn undefined;\n\t}\n\tif (typeof value === 'string') {\n\t\treturn value.length > 80 ? `${value.slice(0, 77)}...` : value;\n\t}\n\tif (typeof value === 'number' || typeof value === 'boolean' || value === null) {\n\t\treturn String(value);\n\t}\n\tconst serialized = JSON.stringify(value);\n\tif (serialized === undefined) {\n\t\treturn undefined;\n\t}\n\treturn serialized.length > 80 ? `${serialized.slice(0, 77)}...` : serialized;\n}\n\nfunction keysFromIssue(issue: z.core.$ZodIssue): readonly string[] | undefined {\n\tif (!('keys' in issue)) {\n\t\treturn undefined;\n\t}\n\tconst value = issue.keys;\n\tif (!Array.isArray(value) || !value.every((entry) => typeof entry === 'string')) {\n\t\treturn undefined;\n\t}\n\treturn value;\n}\n\nfunction valuesFromIssue(issue: z.core.$ZodIssue): readonly JsonValue[] | undefined {\n\tif (!('values' in issue)) {\n\t\treturn undefined;\n\t}\n\tconst value: unknown = issue.values;\n\tif (!Array.isArray(value)) {\n\t\treturn undefined;\n\t}\n\tconst values: JsonValue[] = [];\n\tfor (const entry of value) {\n\t\tif (!isJsonValue(entry)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tvalues.push(entry);\n\t}\n\treturn values;\n}\n\nfunction isJsonValue(value: unknown): value is JsonValue {\n\treturn (\n\t\tvalue === null ||\n\t\ttypeof value === 'string' ||\n\t\ttypeof value === 'number' ||\n\t\ttypeof value === 'boolean' ||\n\t\t(Array.isArray(value) && value.every((entry) => isJsonValue(entry))) ||\n\t\t(isJsonObjectValue(value) && Object.values(value).every((entry) => isJsonValue(entry)))\n\t);\n}\n\nfunction expectedFromIssue(issue: z.core.$ZodIssue): string | undefined {\n\tif (!('expected' in issue)) {\n\t\treturn undefined;\n\t}\n\tconst expected = issue.expected;\n\treturn typeof expected === 'string' ? expected : undefined;\n}\n\nfunction toValidationIssue(issue: z.core.$ZodIssue, inputValue: unknown): InputValidationIssue {\n\tconst path = issue.path.map((pathPart) =>\n\t\ttypeof pathPart === 'symbol' ? String(pathPart) : pathPart,\n\t);\n\tconst receivedValue = valueAtPath(inputValue, path);\n\tconst preview = jsonValuePreview(receivedValue);\n\tconst result: InputValidationIssue = {\n\t\tcode: issue.code,\n\t\tmessage: issue.message,\n\t\tpath,\n\t\treceived: {\n\t\t\ttype: jsonTypeName(receivedValue),\n\t\t\t...(preview === undefined ? {} : { preview }),\n\t\t},\n\t};\n\tconst expected = expectedFromIssue(issue);\n\tconst keys = keysFromIssue(issue);\n\tconst values = valuesFromIssue(issue);\n\treturn {\n\t\t...result,\n\t\t...(expected === undefined ? {} : { expected }),\n\t\t...(keys === undefined ? {} : { keys }),\n\t\t...(values === undefined ? {} : { values }),\n\t};\n}\n\nexport function buildZodValidatorFromJsonSchema(jsonSchema: JsonObject): BuiltZodValidator {\n\tconst unsupported = findUnsupportedFeature(jsonSchema);\n\tif (unsupported) {\n\t\treturn {\n\t\t\terror: unavailableError(unsupported.feature, unsupported.path),\n\t\t\tok: false,\n\t\t};\n\t}\n\n\ttry {\n\t\tconst zodSchema = z.fromJSONSchema(jsonSchema);\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\tvalidate(value: unknown): PortalValidationResult {\n\t\t\t\tconst normalizedValue = normalizeValueForJsonSchema(jsonSchema, value);\n\t\t\t\tconst parsed = zodSchema.safeParse(normalizedValue);\n\t\t\t\tif (parsed.success) {\n\t\t\t\t\treturn { ok: true, value: parsed.data };\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\terror: {\n\t\t\t\t\t\tkind: 'input_validation',\n\t\t\t\t\t\tissues: parsed.error.issues.map((issue) => toValidationIssue(issue, normalizedValue)),\n\t\t\t\t\t},\n\t\t\t\t\tok: false,\n\t\t\t\t};\n\t\t\t},\n\t\t};\n\t} catch (error) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\tfeature: 'conversion_failed',\n\t\t\t\tkind: 'schema_validation_unavailable',\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\tpath: [],\n\t\t\t},\n\t\t\tok: false,\n\t\t};\n\t}\n}\n"],"mappings":";;AAOA,MAAa,kBAAwC,EAAE,WACtD,EAAE,MAAM;CACP,EAAE,QAAQ;CACV,EAAE,QAAQ,CAAC,QAAQ;CACnB,EAAE,SAAS;CACX,EAAE,MAAM;CACR,EAAE,MAAM,gBAAgB;CACxB;CACA,CAAC,CACF;AAED,MAAa,mBAA0C,EAAE,OAAO,EAAE,QAAQ,EAAE,gBAAgB;AAE5F,SAAgBA,eAAa,OAAqC;CACjE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;AAG5E,SAAgB,iBAAiB,OAAgB,OAA2B;CAC3E,IAAI,CAACA,eAAa,MAAM,EACvB,MAAM,IAAI,MAAM,GAAG,MAAM,yBAAyB;CAGnD,OAAO,iBAAiB,MAAM,MAAM;;;;ACzBrC,MAAM,wBAAwB,IAAI,IAAI;CACrC;CACA;CACA;CACA;CACA;CACA,CAAC;AAEF,SAAS,yBAAyB,OAAkC;CACnE,MAAM,QAAqB,CAAC,MAAM;CAElC,OAAO,MAAM,SAAS,GAAG;EACxB,MAAM,UAAU,MAAM,KAAK;EAC3B,IAAI,CAAC,SACJ;EAGD,IAAI,MAAM,QAAQ,QAAQ,EAAE;GAC3B,MAAM,KAAK,GAAG,QAAQ;GACtB;;EAGD,IAAI,OAAO,YAAY,YAAY,YAAY,MAC9C;EAGD,KAAK,MAAM,CAAC,KAAK,eAAe,OAAO,QAAQ,QAAQ,EAAE;GACxD,IAAI,sBAAsB,IAAI,IAAI,aAAa,CAAC,EAC/C,OAAO;GAER,IAAI,OAA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;EACH,MAAM,YAAY,EAAE,eAAe,WAAW;EAE9C,OAAO;GACN,IAAI;GACJ,SAAS,OAAwC;IAChD,MAAM,kBAAkB,4BAA4B,YAAY,MAAM;IACtE,MAAM,SAAS,UAAU,UAAU,gBAAgB;IACnD,IAAI,OAAO,SACV,OAAO;KAAE,IAAI;KAAM,OAAO,OAAO;KAAM;IAGxC,OAAO;KACN,OAAO;MACN,MAAM;MACN,QAAQ,OAAO,MAAM,OAAO,KAAK,UAAU,kBAAkB,OAAO,gBAAgB,CAAC;MACrF;KACD,IAAI;KACJ;;GAEF;UACO,OAAO;EACf,OAAO;GACN,OAAO;IACN,SAAS;IACT,MAAM;IACN,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;IAC/D,MAAM,EAAE;IACR;GACD,IAAI;GACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-vm/mcp-portal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.94",
|
|
4
4
|
"description": "Agent-scoped MCP Portal server and TypeScript helpers for composable upstream MCP tools.",
|
|
5
5
|
"homepage": "https://github.com/ShravanSunder/agent-vm#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
70
70
|
"hono": "^4.12.18",
|
|
71
71
|
"zod": "^4.4.3",
|
|
72
|
-
"@agent-vm/
|
|
73
|
-
"@agent-vm/
|
|
72
|
+
"@agent-vm/secret-management": "0.0.94",
|
|
73
|
+
"@agent-vm/config-contracts": "0.0.94"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"vitest": "^4.1.5"
|
|
@@ -79,6 +79,6 @@
|
|
|
79
79
|
"build": "tsdown",
|
|
80
80
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
81
81
|
"test": "pnpm test:unit",
|
|
82
|
-
"test:unit": "vitest run --root ../../ --config vitest.config.ts packages/mcp-portal/src"
|
|
82
|
+
"test:unit": "vitest run --root ../../ --config vitest.config.ts --project unit packages/mcp-portal/src"
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zod-schema-loader-C3I-MnWq.js","names":["isJsonObject"],"sources":["../src/json-schema.ts","../src/catalog-types.ts","../src/tool-ref.ts","../src/zod-schema-loader.ts"],"sourcesContent":["import { z } from 'zod';\n\nexport type JsonPrimitive = boolean | null | number | string;\nexport type JsonArray = JsonValue[];\nexport type JsonObject = { [key: string]: JsonValue };\nexport type JsonValue = JsonArray | JsonObject | JsonPrimitive;\n\nexport const jsonValueSchema: z.ZodType<JsonValue> = z.lazy(() =>\n\tz.union([\n\t\tz.string(),\n\t\tz.number().finite(),\n\t\tz.boolean(),\n\t\tz.null(),\n\t\tz.array(jsonValueSchema),\n\t\tjsonObjectSchema,\n\t]),\n);\n\nexport const jsonObjectSchema: z.ZodType<JsonObject> = z.record(z.string(), jsonValueSchema);\n\nexport function isJsonObject(value: unknown): value is JsonObject {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function assertJsonObject(value: unknown, label: string): JsonObject {\n\tif (!isJsonObject(value)) {\n\t\tthrow new Error(`${label} must be a JSON object.`);\n\t}\n\n\treturn jsonObjectSchema.parse(value);\n}\n","import { z } from 'zod';\n\nimport { jsonObjectSchema, type JsonObject, type JsonValue } from './json-schema.js';\n\nconst forbiddenMetadataKeys = new Set([\n\t'agentid',\n\t'authprofile',\n\t'bindingid',\n\t'runid',\n\t'sessionid',\n]);\n\nfunction findForbiddenMetadataKey(value: JsonObject): string | null {\n\tconst stack: JsonValue[] = [value];\n\n\twhile (stack.length > 0) {\n\t\tconst current = stack.pop();\n\t\tif (!current) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (Array.isArray(current)) {\n\t\t\tstack.push(...current);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (typeof current !== 'object' || current === null) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (const [key, childValue] of Object.entries(current)) {\n\t\t\tif (forbiddenMetadataKeys.has(key.toLowerCase())) {\n\t\t\t\treturn key;\n\t\t\t}\n\t\t\tif (typeof childValue === 'object' && childValue !== null) {\n\t\t\t\tstack.push(childValue);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport const portalToolAnnotationsSchema = z\n\t.object({\n\t\tdestructiveHint: z.boolean().optional(),\n\t\tidempotentHint: z.boolean().optional(),\n\t\topenWorldHint: z.boolean().optional(),\n\t\treadOnlyHint: z.boolean().optional(),\n\t\ttitle: z.string().optional(),\n\t})\n\t.catchall(jsonObjectSchema.or(z.string()).or(z.number()).or(z.boolean()).or(z.null()))\n\t.optional();\n\nexport const safeToolMetadataSchema = jsonObjectSchema\n\t.optional()\n\t.superRefine((metadata, context) => {\n\t\tif (!metadata) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst forbiddenKey = findForbiddenMetadataKey(metadata);\n\t\tif (forbiddenKey) {\n\t\t\tcontext.addIssue({\n\t\t\t\tcode: 'custom',\n\t\t\t\tmessage: `metadata contains forbidden key \"${forbiddenKey}\"`,\n\t\t\t});\n\t\t}\n\t});\n\nexport const portalToolRecordSchema = z\n\t.object({\n\t\tannotations: portalToolAnnotationsSchema,\n\t\tdescription: z.string().optional(),\n\t\tinputSchema: jsonObjectSchema,\n\t\tmetadata: safeToolMetadataSchema,\n\t\tnamespace: z.string().min(1),\n\t\toutputSchema: jsonObjectSchema.optional(),\n\t\ttitle: z.string().optional(),\n\t\ttoolName: z.string().min(1),\n\t})\n\t.strict();\n\nexport type PortalToolRecord = z.infer<typeof portalToolRecordSchema>;\nexport type PortalToolAnnotations = z.infer<typeof portalToolAnnotationsSchema>;\n","import { z } from 'zod';\n\nexport interface ToolIdentity {\n\treadonly namespace: string;\n\treadonly toolName: string;\n}\n\nconst toolIdentitySchema = z\n\t.object({\n\t\tnamespace: z.string().min(1),\n\t\ttoolName: z.string().min(1),\n\t})\n\t.strict();\nconst toolRefSchema = z.string().startsWith('mcp:').brand<'ToolRef'>();\n\nexport type ToolRef = z.infer<typeof toolRefSchema>;\n\nfunction decodeToolRefSegment(segment: string): string {\n\tif (!/^[A-Za-z0-9_-]+$/.test(segment)) {\n\t\tthrow new Error('Invalid MCP toolRef.');\n\t}\n\n\tconst decoded = Buffer.from(segment, 'base64url').toString('utf-8');\n\tconst canonicalSegment = Buffer.from(decoded, 'utf-8').toString('base64url');\n\tif (canonicalSegment !== segment) {\n\t\tthrow new Error('Invalid MCP toolRef.');\n\t}\n\n\treturn decoded;\n}\n\nexport function encodeToolRef(identity: ToolIdentity): ToolRef {\n\tconst parsed = toolIdentitySchema.parse(identity);\n\tconst encodedNamespace = Buffer.from(parsed.namespace, 'utf-8').toString('base64url');\n\tconst encodedToolName = Buffer.from(parsed.toolName, 'utf-8').toString('base64url');\n\n\treturn toolRefSchema.parse(`mcp:${encodedNamespace}:${encodedToolName}`);\n}\n\nexport function decodeToolRef(toolRef: string | ToolRef): ToolIdentity {\n\tconst [scheme, encodedNamespace, encodedToolName, ...extraParts] = toolRef.split(':');\n\tif (scheme !== 'mcp' || !encodedNamespace || !encodedToolName || extraParts.length > 0) {\n\t\tthrow new Error('Invalid MCP toolRef.');\n\t}\n\n\ttry {\n\t\treturn toolIdentitySchema.parse({\n\t\t\tnamespace: decodeToolRefSegment(encodedNamespace),\n\t\t\ttoolName: decodeToolRefSegment(encodedToolName),\n\t\t});\n\t} catch {\n\t\tthrow new Error('Invalid MCP toolRef.');\n\t}\n}\n","import { z } from 'zod';\n\nimport type { JsonObject, JsonValue } from './json-schema.js';\n\nexport interface InputValidationIssue {\n\treadonly code: string;\n\treadonly expected?: string;\n\treadonly keys?: readonly string[];\n\treadonly message: string;\n\treadonly path: readonly (number | string)[];\n\treadonly received?: {\n\t\treadonly preview?: string;\n\t\treadonly type: string;\n\t};\n\treadonly values?: readonly JsonValue[];\n}\n\nexport interface InputValidationError {\n\treadonly kind: 'input_validation';\n\treadonly issues: readonly InputValidationIssue[];\n}\n\nexport interface SchemaValidationUnavailableError {\n\treadonly feature: string;\n\treadonly kind: 'schema_validation_unavailable';\n\treadonly message: string;\n\treadonly path: readonly (number | string)[];\n}\n\nexport type PortalValidationResult =\n\t| { readonly ok: true; readonly value: unknown }\n\t| { readonly error: InputValidationError; readonly ok: false };\n\nexport type BuiltZodValidator =\n\t| {\n\t\t\treadonly ok: true;\n\t\t\treadonly validate: (value: unknown) => PortalValidationResult;\n\t }\n\t| {\n\t\t\treadonly error: SchemaValidationUnavailableError;\n\t\t\treadonly ok: false;\n\t };\n\ninterface UnsupportedFeature {\n\treadonly feature: string;\n\treadonly path: readonly (number | string)[];\n}\n\nconst unsupportedFeatures = new Set([\n\t'contains',\n\t'dependentSchemas',\n\t'else',\n\t'if',\n\t'not',\n\t'then',\n\t'unevaluatedProperties',\n\t'uniqueItems',\n]);\n\nfunction isJsonObject(value: JsonValue): value is JsonObject {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction findUnsupportedFeature(\n\tvalue: JsonValue,\n\tpath: readonly (number | string)[] = [],\n): UnsupportedFeature | null {\n\tif (Array.isArray(value)) {\n\t\tfor (const [index, childValue] of value.entries()) {\n\t\t\tconst childUnsupported = findUnsupportedFeature(childValue, [...path, index]);\n\t\t\tif (childUnsupported) {\n\t\t\t\treturn childUnsupported;\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\n\tif (!isJsonObject(value)) {\n\t\treturn null;\n\t}\n\n\tfor (const [key, childValue] of Object.entries(value)) {\n\t\tif (unsupportedFeatures.has(key)) {\n\t\t\treturn { feature: key, path: [...path, key] };\n\t\t}\n\t\tconst childUnsupported = findUnsupportedFeature(childValue, [...path, key]);\n\t\tif (childUnsupported) {\n\t\t\treturn childUnsupported;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nfunction unavailableError(\n\tfeature: string,\n\tpath: readonly (number | string)[],\n): SchemaValidationUnavailableError {\n\treturn {\n\t\tfeature,\n\t\tkind: 'schema_validation_unavailable',\n\t\tmessage: `JSON Schema feature \"${feature}\" is not supported by the portal validator.`,\n\t\tpath,\n\t};\n}\n\nfunction valueAtPath(value: unknown, path: readonly (number | string)[]): unknown {\n\tlet currentValue = value;\n\tfor (const pathPart of path) {\n\t\tif (typeof pathPart === 'number') {\n\t\t\tif (!Array.isArray(currentValue)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tcurrentValue = currentValue[pathPart];\n\t\t\tcontinue;\n\t\t}\n\t\tif (!isJsonObjectValue(currentValue)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tcurrentValue = currentValue[pathPart];\n\t}\n\treturn currentValue;\n}\n\nfunction isJsonObjectValue(value: unknown): value is Readonly<Record<string, unknown>> {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction jsonTypeName(value: unknown): string {\n\tif (value === undefined) {\n\t\treturn 'undefined';\n\t}\n\tif (value === null) {\n\t\treturn 'null';\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn 'array';\n\t}\n\treturn typeof value;\n}\n\nfunction jsonValuePreview(value: unknown): string | undefined {\n\tif (value === undefined) {\n\t\treturn undefined;\n\t}\n\tif (typeof value === 'string') {\n\t\treturn value.length > 80 ? `${value.slice(0, 77)}...` : value;\n\t}\n\tif (typeof value === 'number' || typeof value === 'boolean' || value === null) {\n\t\treturn String(value);\n\t}\n\tconst serialized = JSON.stringify(value);\n\tif (serialized === undefined) {\n\t\treturn undefined;\n\t}\n\treturn serialized.length > 80 ? `${serialized.slice(0, 77)}...` : serialized;\n}\n\nfunction keysFromIssue(issue: z.core.$ZodIssue): readonly string[] | undefined {\n\tif (!('keys' in issue)) {\n\t\treturn undefined;\n\t}\n\tconst value = issue.keys;\n\tif (!Array.isArray(value) || !value.every((entry) => typeof entry === 'string')) {\n\t\treturn undefined;\n\t}\n\treturn value;\n}\n\nfunction valuesFromIssue(issue: z.core.$ZodIssue): readonly JsonValue[] | undefined {\n\tif (!('values' in issue)) {\n\t\treturn undefined;\n\t}\n\tconst value: unknown = issue.values;\n\tif (!Array.isArray(value)) {\n\t\treturn undefined;\n\t}\n\tconst values: JsonValue[] = [];\n\tfor (const entry of value) {\n\t\tif (!isJsonValue(entry)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tvalues.push(entry);\n\t}\n\treturn values;\n}\n\nfunction isJsonValue(value: unknown): value is JsonValue {\n\treturn (\n\t\tvalue === null ||\n\t\ttypeof value === 'string' ||\n\t\ttypeof value === 'number' ||\n\t\ttypeof value === 'boolean' ||\n\t\t(Array.isArray(value) && value.every((entry) => isJsonValue(entry))) ||\n\t\t(isJsonObjectValue(value) && Object.values(value).every((entry) => isJsonValue(entry)))\n\t);\n}\n\nfunction expectedFromIssue(issue: z.core.$ZodIssue): string | undefined {\n\tif (!('expected' in issue)) {\n\t\treturn undefined;\n\t}\n\tconst expected = issue.expected;\n\treturn typeof expected === 'string' ? expected : undefined;\n}\n\nfunction toValidationIssue(issue: z.core.$ZodIssue, inputValue: unknown): InputValidationIssue {\n\tconst path = issue.path.map((pathPart) =>\n\t\ttypeof pathPart === 'symbol' ? String(pathPart) : pathPart,\n\t);\n\tconst receivedValue = valueAtPath(inputValue, path);\n\tconst preview = jsonValuePreview(receivedValue);\n\tconst result: InputValidationIssue = {\n\t\tcode: issue.code,\n\t\tmessage: issue.message,\n\t\tpath,\n\t\treceived: {\n\t\t\ttype: jsonTypeName(receivedValue),\n\t\t\t...(preview === undefined ? {} : { preview }),\n\t\t},\n\t};\n\tconst expected = expectedFromIssue(issue);\n\tconst keys = keysFromIssue(issue);\n\tconst values = valuesFromIssue(issue);\n\treturn {\n\t\t...result,\n\t\t...(expected === undefined ? {} : { expected }),\n\t\t...(keys === undefined ? {} : { keys }),\n\t\t...(values === undefined ? {} : { values }),\n\t};\n}\n\nexport function buildZodValidatorFromJsonSchema(jsonSchema: JsonObject): BuiltZodValidator {\n\tconst unsupported = findUnsupportedFeature(jsonSchema);\n\tif (unsupported) {\n\t\treturn {\n\t\t\terror: unavailableError(unsupported.feature, unsupported.path),\n\t\t\tok: false,\n\t\t};\n\t}\n\n\ttry {\n\t\tconst zodSchema = z.fromJSONSchema(jsonSchema);\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\tvalidate(value: unknown): PortalValidationResult {\n\t\t\t\tconst parsed = zodSchema.safeParse(value);\n\t\t\t\tif (parsed.success) {\n\t\t\t\t\treturn { ok: true, value: parsed.data };\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\terror: {\n\t\t\t\t\t\tkind: 'input_validation',\n\t\t\t\t\t\tissues: parsed.error.issues.map((issue) => toValidationIssue(issue, value)),\n\t\t\t\t\t},\n\t\t\t\t\tok: false,\n\t\t\t\t};\n\t\t\t},\n\t\t};\n\t} catch (error) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\tfeature: 'conversion_failed',\n\t\t\t\tkind: 'schema_validation_unavailable',\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\tpath: [],\n\t\t\t},\n\t\t\tok: false,\n\t\t};\n\t}\n}\n"],"mappings":";;AAOA,MAAa,kBAAwC,EAAE,WACtD,EAAE,MAAM;CACP,EAAE,QAAQ;CACV,EAAE,QAAQ,CAAC,QAAQ;CACnB,EAAE,SAAS;CACX,EAAE,MAAM;CACR,EAAE,MAAM,gBAAgB;CACxB;CACA,CAAC,CACF;AAED,MAAa,mBAA0C,EAAE,OAAO,EAAE,QAAQ,EAAE,gBAAgB;AAE5F,SAAgBA,eAAa,OAAqC;CACjE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;AAG5E,SAAgB,iBAAiB,OAAgB,OAA2B;CAC3E,IAAI,CAACA,eAAa,MAAM,EACvB,MAAM,IAAI,MAAM,GAAG,MAAM,yBAAyB;CAGnD,OAAO,iBAAiB,MAAM,MAAM;;;;ACzBrC,MAAM,wBAAwB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