@agent-vm/mcp-portal 0.0.68 → 0.0.70
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 +42 -11
- package/dist/agent-bearer-token-DCtpDPCZ.js +59 -0
- package/dist/agent-bearer-token-DCtpDPCZ.js.map +1 -0
- package/dist/bin/mcp-portal.d.ts +28 -0
- package/dist/bin/mcp-portal.d.ts.map +1 -0
- package/dist/bin/mcp-portal.js +318 -0
- package/dist/bin/mcp-portal.js.map +1 -0
- package/dist/{catalog-types--gUGFPpN.d.ts → catalog-types-BVuB4Ynx.d.ts} +1 -1
- package/dist/{catalog-types--gUGFPpN.d.ts.map → catalog-types-BVuB4Ynx.d.ts.map} +1 -1
- package/dist/cli/index.d.ts +101 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +2 -0
- package/dist/core/index.d.ts +40 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +5 -0
- package/dist/hmac-env-B4shpRRB.js +20 -0
- package/dist/hmac-env-B4shpRRB.js.map +1 -0
- package/dist/hmac-token-DBqWY3-w.js +100 -0
- package/dist/hmac-token-DBqWY3-w.js.map +1 -0
- package/dist/index.d.ts +5 -485
- package/dist/index.js +4 -5
- package/dist/mcp-proxy/index.d.ts +24 -0
- package/dist/mcp-proxy/index.d.ts.map +1 -0
- package/dist/mcp-proxy/index.js +2 -0
- package/dist/portal-auth/agent-bearer-token.d.ts +22 -0
- package/dist/portal-auth/agent-bearer-token.d.ts.map +1 -0
- package/dist/portal-auth/agent-bearer-token.js +2 -0
- package/dist/portal-auth/hmac-env.d.ts +6 -0
- package/dist/portal-auth/hmac-env.d.ts.map +1 -0
- package/dist/portal-auth/hmac-env.js +2 -0
- package/dist/portal-auth/hmac-token.d.ts +40 -0
- package/dist/portal-auth/hmac-token.d.ts.map +1 -0
- package/dist/portal-auth/hmac-token.js +2 -0
- package/dist/portal-config/index.d.ts +11 -0
- package/dist/portal-config/index.d.ts.map +1 -0
- package/dist/{tool-vm → portal-config}/index.js +2 -3
- package/dist/portal-core-CZQI7Ob6.d.ts +264 -0
- package/dist/portal-core-CZQI7Ob6.d.ts.map +1 -0
- package/dist/portal-core-Cgu714CL.js +416 -0
- package/dist/portal-core-Cgu714CL.js.map +1 -0
- package/dist/portal-session-DG2CUjIo.d.ts +184 -0
- package/dist/portal-session-DG2CUjIo.d.ts.map +1 -0
- package/dist/portal-tools-DKci1szO.js +528 -0
- package/dist/portal-tools-DKci1szO.js.map +1 -0
- package/dist/resolve-agent-identity-DnC_Pmnh.js +550 -0
- package/dist/resolve-agent-identity-DnC_Pmnh.js.map +1 -0
- package/dist/resolve-agent-identity-FQL02YdW.d.ts +81 -0
- package/dist/resolve-agent-identity-FQL02YdW.d.ts.map +1 -0
- package/dist/serve-command-CnSMUybd.js +358 -0
- package/dist/serve-command-CnSMUybd.js.map +1 -0
- package/dist/testing/fake-upstream-mcp-server.d.ts +5 -2
- package/dist/testing/fake-upstream-mcp-server.d.ts.map +1 -1
- package/dist/testing/fake-upstream-mcp-server.js +14 -4
- package/dist/testing/fake-upstream-mcp-server.js.map +1 -1
- package/dist/typescript-artifact-BVLt3Ifd.js +60 -0
- package/dist/typescript-artifact-BVLt3Ifd.js.map +1 -0
- package/dist/upstream-mcp-client-runtime-JlsfTm7_.js +760 -0
- package/dist/upstream-mcp-client-runtime-JlsfTm7_.js.map +1 -0
- package/dist/upstream-response-middleware-1MZnAD9C.d.ts +115 -0
- package/dist/upstream-response-middleware-1MZnAD9C.d.ts.map +1 -0
- package/dist/upstream-response-middleware-BjUWZ2G8.js +172 -0
- package/dist/upstream-response-middleware-BjUWZ2G8.js.map +1 -0
- package/dist/{index-BcI9c8sg.d.ts → zod-schema-loader-DLGQpYFD.d.ts} +3 -9
- package/dist/zod-schema-loader-DLGQpYFD.d.ts.map +1 -0
- package/dist/{typescript-artifact-BqU8okQy.js → zod-schema-loader-yNekKNpm.js} +85 -55
- package/dist/zod-schema-loader-yNekKNpm.js.map +1 -0
- package/package.json +30 -13
- package/dist/bin/agent-vm-mcp-portal.d.ts +0 -10
- package/dist/bin/agent-vm-mcp-portal.d.ts.map +0 -1
- package/dist/bin/agent-vm-mcp-portal.js +0 -56
- package/dist/bin/agent-vm-mcp-portal.js.map +0 -1
- package/dist/bin/portal-server.d.ts +0 -55
- package/dist/bin/portal-server.d.ts.map +0 -1
- package/dist/bin/portal-server.js +0 -289
- package/dist/bin/portal-server.js.map +0 -1
- package/dist/index-BcI9c8sg.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/tool-vm/index.d.ts +0 -2
- package/dist/tool-vm-ihnzDyjJ.js +0 -3
- package/dist/typescript-artifact-BqU8okQy.js.map +0 -1
- package/dist/upstream-mcp-client-runtime-DiBCBsDj.js +0 -1729
- package/dist/upstream-mcp-client-runtime-DiBCBsDj.js.map +0 -1
- package/dist/zod-schema-loader-CDDtoRE1.js +0 -90
- package/dist/zod-schema-loader-CDDtoRE1.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstream-mcp-client-runtime-JlsfTm7_.js","names":[],"sources":["../src/search-index.ts","../src/tool-graph.ts","../src/portal-session.ts","../src/upstream-mcp-client-runtime.ts"],"sourcesContent":["import { portalToolRecordSchema, type PortalToolRecord } from './catalog-types.js';\nimport type { JsonObject, JsonValue } from './json-schema.js';\nimport type { ToolGraph, ToolRelationship } from './tool-graph.js';\nimport { createToolSummary, type ToolSummary } from './tool-summary.js';\n\nexport interface SearchQuery {\n\treadonly limit: number;\n\treadonly namespaces?: readonly string[];\n\treadonly query?: string;\n}\n\nexport interface SearchResultSet {\n\treadonly results: readonly ToolSearchResult[];\n}\n\nexport interface SearchIndex {\n\treadonly search: (query: SearchQuery) => SearchResultSet;\n}\n\ninterface SearchEntry {\n\treadonly inputFields: readonly string[];\n\treadonly relationshipHints: readonly ToolRelationshipHint[];\n\treadonly searchText: string;\n\treadonly summary: ToolSearchResult;\n}\n\nexport interface ToolRelationshipHint {\n\treadonly field?: string;\n\treadonly reason: string;\n\treadonly sourceToolRef: string;\n\treadonly type: ToolRelationship['type'];\n}\n\nexport interface ToolSearchResult extends ToolSummary {\n\treadonly relationshipHints?: readonly ToolRelationshipHint[];\n\treadonly schemaFieldMatches?: readonly string[];\n}\n\nfunction collectSchemaText(value: JsonValue, parts: string[]): void {\n\tif (Array.isArray(value)) {\n\t\tfor (const item of value) {\n\t\t\tcollectSchemaText(item, parts);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof value !== 'object' || value === null) {\n\t\tif (typeof value === 'string') {\n\t\t\tparts.push(value);\n\t\t}\n\t\treturn;\n\t}\n\n\tfor (const [key, childValue] of Object.entries(value)) {\n\t\tparts.push(key);\n\t\tcollectSchemaText(childValue, parts);\n\t}\n}\n\nfunction normalizeSearchText(text: string): string {\n\treturn text.toLowerCase().replace(/[_-]/g, ' ');\n}\n\nfunction buildSearchText(tool: PortalToolRecord): string {\n\tconst parts = [tool.namespace, tool.toolName, tool.title ?? '', tool.description ?? ''];\n\tcollectSchemaText(tool.inputSchema, parts);\n\tif (tool.outputSchema) {\n\t\tcollectSchemaText(tool.outputSchema, parts);\n\t}\n\n\treturn normalizeSearchText(parts.join(' '));\n}\n\nfunction propertiesFromSchema(schema: JsonObject): readonly string[] {\n\tconst properties = schema.properties;\n\tif (typeof properties !== 'object' || properties === null || Array.isArray(properties)) {\n\t\treturn [];\n\t}\n\n\treturn Object.keys(properties).toSorted();\n}\n\nfunction createRelationshipHints(\n\ttool: PortalToolRecord,\n\trelationships: readonly ToolRelationship[],\n): readonly ToolRelationshipHint[] {\n\tconst targetToolRef = createToolSummary(tool).toolRef;\n\n\treturn relationships\n\t\t.filter((relationship) => relationship.to.toolRef === targetToolRef)\n\t\t.map((relationship) =>\n\t\t\trelationship.field === undefined\n\t\t\t\t? {\n\t\t\t\t\t\treason: relationship.reason,\n\t\t\t\t\t\tsourceToolRef: relationship.from.toolRef,\n\t\t\t\t\t\ttype: relationship.type,\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\tfield: relationship.field,\n\t\t\t\t\t\treason: relationship.reason,\n\t\t\t\t\t\tsourceToolRef: relationship.from.toolRef,\n\t\t\t\t\t\ttype: relationship.type,\n\t\t\t\t\t},\n\t\t)\n\t\t.toSorted((left, right) => {\n\t\t\tconst typeOrder = left.type.localeCompare(right.type);\n\t\t\tif (typeOrder !== 0) {\n\t\t\t\treturn typeOrder;\n\t\t\t}\n\t\t\treturn left.sourceToolRef.localeCompare(right.sourceToolRef);\n\t\t});\n}\n\nfunction scopedSkillText(toolRef: string, graph?: ToolGraph): string {\n\tif (!graph) {\n\t\treturn '';\n\t}\n\n\treturn graph.skills\n\t\t.filter((skill) => skill.toolRefs.includes(toolRef))\n\t\t.map((skill) => [skill.title, skill.description ?? '', ...skill.tags].join(' '))\n\t\t.join(' ');\n}\n\nfunction scoreEntry(entry: SearchEntry, terms: readonly string[]): number {\n\tlet score = 0;\n\tfor (const term of terms) {\n\t\tif (entry.searchText.includes(term)) {\n\t\t\tscore += 1;\n\t\t}\n\t}\n\n\treturn score;\n}\n\nfunction compareSummaries(left: ToolSummary, right: ToolSummary): number {\n\tconst namespaceOrder = left.namespace.localeCompare(right.namespace);\n\tif (namespaceOrder !== 0) {\n\t\treturn namespaceOrder;\n\t}\n\n\treturn left.toolName.localeCompare(right.toolName);\n}\n\nfunction withRelationshipHints(\n\tsummary: ToolSummary,\n\trelationshipHints: readonly ToolRelationshipHint[],\n): ToolSearchResult {\n\tif (relationshipHints.length === 0) {\n\t\treturn summary;\n\t}\n\n\treturn {\n\t\t...(summary.description !== undefined ? { description: summary.description } : {}),\n\t\tinput: summary.input,\n\t\tnamespace: summary.namespace,\n\t\t...(summary.output !== undefined ? { output: summary.output } : {}),\n\t\trelationshipHints,\n\t\tsafety: summary.safety,\n\t\t...(summary.title !== undefined ? { title: summary.title } : {}),\n\t\ttoolName: summary.toolName,\n\t\ttoolRef: summary.toolRef,\n\t};\n}\n\nfunction withSchemaFieldMatches(\n\tsummary: ToolSearchResult,\n\tschemaFieldMatches: readonly string[],\n): ToolSearchResult {\n\tif (schemaFieldMatches.length === 0) {\n\t\treturn summary;\n\t}\n\n\treturn {\n\t\t...(summary.description !== undefined ? { description: summary.description } : {}),\n\t\tinput: summary.input,\n\t\tnamespace: summary.namespace,\n\t\t...(summary.output !== undefined ? { output: summary.output } : {}),\n\t\t...(summary.relationshipHints !== undefined\n\t\t\t? { relationshipHints: summary.relationshipHints }\n\t\t\t: {}),\n\t\tsafety: summary.safety,\n\t\tschemaFieldMatches,\n\t\t...(summary.title !== undefined ? { title: summary.title } : {}),\n\t\ttoolName: summary.toolName,\n\t\ttoolRef: summary.toolRef,\n\t};\n}\n\nexport function createSearchIndex(\n\ttools: readonly PortalToolRecord[],\n\tgraph?: ToolGraph,\n): SearchIndex {\n\tconst entries = tools\n\t\t.map((tool) => portalToolRecordSchema.parse(tool))\n\t\t.map((tool) => {\n\t\t\tconst summary = createToolSummary(tool);\n\t\t\tconst relationshipHints = createRelationshipHints(tool, graph?.relationships ?? []);\n\t\t\tconst inputFields = propertiesFromSchema(tool.inputSchema);\n\t\t\tconst relationText = relationshipHints\n\t\t\t\t.map((hint) => [hint.field ?? '', hint.reason, hint.sourceToolRef, hint.type].join(' '))\n\t\t\t\t.join(' ');\n\t\t\tconst skillText = scopedSkillText(summary.toolRef, graph);\n\n\t\t\treturn {\n\t\t\t\tinputFields,\n\t\t\t\trelationshipHints,\n\t\t\t\tsearchText: normalizeSearchText([buildSearchText(tool), relationText, skillText].join(' ')),\n\t\t\t\tsummary: withRelationshipHints(summary, relationshipHints),\n\t\t\t};\n\t\t})\n\t\t.toSorted((left, right) => compareSummaries(left.summary, right.summary));\n\n\treturn {\n\t\tsearch(query: SearchQuery): SearchResultSet {\n\t\t\tconst limit = Math.max(0, Math.floor(query.limit));\n\t\t\tconst namespaceFilter = new Set(query.namespaces ?? []);\n\t\t\tconst terms = normalizeSearchText(query.query ?? '')\n\t\t\t\t.split(/\\s+/)\n\t\t\t\t.map((term) => term.trim())\n\t\t\t\t.filter(Boolean);\n\t\t\tconst scoredEntries = entries\n\t\t\t\t.filter(\n\t\t\t\t\t(entry) => namespaceFilter.size === 0 || namespaceFilter.has(entry.summary.namespace),\n\t\t\t\t)\n\t\t\t\t.map((entry) => ({ entry, score: terms.length === 0 ? 1 : scoreEntry(entry, terms) }))\n\t\t\t\t.filter(({ score }) => score > 0)\n\t\t\t\t.toSorted((left, right) => {\n\t\t\t\t\tif (right.score !== left.score) {\n\t\t\t\t\t\treturn right.score - left.score;\n\t\t\t\t\t}\n\t\t\t\t\treturn compareSummaries(left.entry.summary, right.entry.summary);\n\t\t\t\t});\n\n\t\t\tconst results = scoredEntries.slice(0, limit).map(({ entry }) => {\n\t\t\t\tconst schemaFieldMatches = entry.inputFields\n\t\t\t\t\t.filter((fieldName) =>\n\t\t\t\t\t\tterms.some((term) => normalizeSearchText(fieldName).includes(term)),\n\t\t\t\t\t)\n\t\t\t\t\t.toSorted();\n\n\t\t\t\treturn withSchemaFieldMatches(entry.summary, schemaFieldMatches);\n\t\t\t});\n\n\t\t\treturn { results };\n\t\t},\n\t};\n}\n","import { portalToolRecordSchema, type PortalToolRecord } from './catalog-types.js';\nimport type { JsonObject } from './json-schema.js';\nimport { encodeToolRef, type ToolIdentity } from './tool-ref.js';\n\nexport type ToolRelationshipType = 'entity' | 'schema-field' | 'skill';\n\nexport interface ToolRelationshipEndpoint extends ToolIdentity {\n\treadonly toolRef: string;\n}\n\nexport interface ToolRelationship {\n\treadonly field?: string;\n\treadonly from: ToolRelationshipEndpoint;\n\treadonly reason: string;\n\treadonly to: ToolRelationshipEndpoint;\n\treadonly type: ToolRelationshipType;\n}\n\nexport interface SkillGraphInput {\n\treadonly description?: string;\n\treadonly tags?: readonly string[];\n\treadonly title: string;\n\treadonly toolRefs: readonly string[];\n}\n\nexport interface ScopedSkillGraphEntry {\n\treadonly description?: string;\n\treadonly tags: readonly string[];\n\treadonly title: string;\n\treadonly toolRefs: readonly string[];\n}\n\nexport interface ToolGraphInput {\n\treadonly skills?: readonly SkillGraphInput[];\n\treadonly tools: readonly PortalToolRecord[];\n}\n\nexport interface ToolGraph {\n\treadonly relationships: readonly ToolRelationship[];\n\treadonly skills: readonly ScopedSkillGraphEntry[];\n}\n\ninterface GraphTool {\n\treadonly entityNames: readonly string[];\n\treadonly inputFields: readonly string[];\n\treadonly outputFields: readonly string[];\n\treadonly record: PortalToolRecord;\n\treadonly ref: ToolRelationshipEndpoint;\n}\n\nconst genericLinkFields = new Set(['id', 'name', 'title', 'url', 'uri']);\n\nfunction compareCodePoint(left: string, right: string): number {\n\tif (left < right) {\n\t\treturn -1;\n\t}\n\tif (left > right) {\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\nfunction objectPropertiesFromSchema(schema: JsonObject | undefined): readonly string[] {\n\tif (!schema) {\n\t\treturn [];\n\t}\n\n\tconst properties = schema.properties;\n\tif (typeof properties !== 'object' || properties === null || Array.isArray(properties)) {\n\t\treturn [];\n\t}\n\n\treturn Object.keys(properties).toSorted();\n}\n\nfunction collectEntityNames(schema: JsonObject | undefined): readonly string[] {\n\tif (!schema) {\n\t\treturn [];\n\t}\n\n\tconst names: string[] = [];\n\tconst schemaId = schema.$id;\n\tconst title = schema.title;\n\tconst entityName = schema.entityName;\n\tif (typeof schemaId === 'string' && schemaId.length > 0) {\n\t\tnames.push(schemaId);\n\t}\n\tif (typeof title === 'string' && title.length > 0) {\n\t\tnames.push(title);\n\t}\n\tif (typeof entityName === 'string' && entityName.length > 0) {\n\t\tnames.push(entityName);\n\t}\n\n\treturn names.map((name) => name.toLowerCase()).toSorted();\n}\n\nfunction createGraphTool(tool: PortalToolRecord): GraphTool {\n\tconst record = portalToolRecordSchema.parse(tool);\n\tconst toolRef = encodeToolRef({ namespace: record.namespace, toolName: record.toolName });\n\n\treturn {\n\t\tentityNames: [\n\t\t\t...collectEntityNames(record.inputSchema),\n\t\t\t...collectEntityNames(record.outputSchema),\n\t\t].toSorted(),\n\t\tinputFields: objectPropertiesFromSchema(record.inputSchema),\n\t\toutputFields: objectPropertiesFromSchema(record.outputSchema),\n\t\trecord,\n\t\tref: {\n\t\t\tnamespace: record.namespace,\n\t\t\ttoolName: record.toolName,\n\t\t\ttoolRef,\n\t\t},\n\t};\n}\n\nfunction sharesEntity(left: GraphTool, right: GraphTool): boolean {\n\tconst rightEntities = new Set(right.entityNames);\n\treturn left.entityNames.some((entityName) => rightEntities.has(entityName));\n}\n\nfunction shouldLinkField(field: string, fromTool: GraphTool, toTool: GraphTool): boolean {\n\tif (!genericLinkFields.has(field.toLowerCase())) {\n\t\treturn true;\n\t}\n\n\treturn fromTool.record.namespace === toTool.record.namespace && sharesEntity(fromTool, toTool);\n}\n\nfunction createSchemaRelationships(tools: readonly GraphTool[]): readonly ToolRelationship[] {\n\tconst relationships: ToolRelationship[] = [];\n\n\tfor (const fromTool of tools) {\n\t\tfor (const toTool of tools) {\n\t\t\tif (fromTool.ref.toolRef === toTool.ref.toolRef) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst inputFields = new Set(toTool.inputFields);\n\t\t\tfor (const field of fromTool.outputFields) {\n\t\t\t\tif (!inputFields.has(field) || !shouldLinkField(field, fromTool, toTool)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\trelationships.push({\n\t\t\t\t\tfield,\n\t\t\t\t\tfrom: fromTool.ref,\n\t\t\t\t\treason: `Output field \"${field}\" matches input field \"${field}\".`,\n\t\t\t\t\tto: toTool.ref,\n\t\t\t\t\ttype: 'schema-field',\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\treturn relationships;\n}\n\nfunction createEntityRelationships(tools: readonly GraphTool[]): readonly ToolRelationship[] {\n\tconst relationships: ToolRelationship[] = [];\n\tfor (const fromTool of tools) {\n\t\tfor (const toTool of tools) {\n\t\t\tif (fromTool.ref.toolRef === toTool.ref.toolRef || !sharesEntity(fromTool, toTool)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\trelationships.push({\n\t\t\t\tfrom: fromTool.ref,\n\t\t\t\treason: 'Tools declare a shared schema entity through title, $id, or entityName.',\n\t\t\t\tto: toTool.ref,\n\t\t\t\ttype: 'entity',\n\t\t\t});\n\t\t}\n\t}\n\treturn relationships;\n}\n\nfunction createSkillEntries(\n\tskills: readonly SkillGraphInput[],\n\tallowedToolRefs: ReadonlySet<string>,\n): readonly ScopedSkillGraphEntry[] {\n\tconst entries: ScopedSkillGraphEntry[] = [];\n\tfor (const skill of skills) {\n\t\tconst scopedToolRefs = skill.toolRefs\n\t\t\t.filter((toolRef) => allowedToolRefs.has(toolRef))\n\t\t\t.toSorted();\n\t\tif (scopedToolRefs.length === 0) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tentries.push({\n\t\t\t...(skill.description !== undefined ? { description: skill.description } : {}),\n\t\t\ttags: [...(skill.tags ?? [])].toSorted(),\n\t\t\ttitle: skill.title,\n\t\t\ttoolRefs: scopedToolRefs,\n\t\t});\n\t}\n\n\treturn entries.toSorted((left, right) => left.title.localeCompare(right.title));\n}\n\nfunction createSkillRelationships(\n\tskills: readonly ScopedSkillGraphEntry[],\n\ttoolsByRef: ReadonlyMap<string, GraphTool>,\n): readonly ToolRelationship[] {\n\tconst relationships: ToolRelationship[] = [];\n\tfor (const skill of skills) {\n\t\tfor (const fromToolRef of skill.toolRefs) {\n\t\t\tfor (const toToolRef of skill.toolRefs) {\n\t\t\t\tif (fromToolRef === toToolRef) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst fromTool = toolsByRef.get(fromToolRef);\n\t\t\t\tconst toTool = toolsByRef.get(toToolRef);\n\t\t\t\tif (!fromTool || !toTool) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\trelationships.push({\n\t\t\t\t\tfrom: fromTool.ref,\n\t\t\t\t\treason: `Both tools are referenced by skill \"${skill.title}\".`,\n\t\t\t\t\tto: toTool.ref,\n\t\t\t\t\ttype: 'skill',\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\treturn relationships;\n}\n\nfunction compareRelationships(left: ToolRelationship, right: ToolRelationship): number {\n\tconst typeOrder = compareCodePoint(left.type, right.type);\n\tif (typeOrder !== 0) {\n\t\treturn typeOrder;\n\t}\n\n\tconst targetOrder = compareCodePoint(left.to.toolRef, right.to.toolRef);\n\tif (targetOrder !== 0) {\n\t\treturn targetOrder;\n\t}\n\n\treturn compareCodePoint(left.from.toolRef, right.from.toolRef);\n}\n\nexport function buildToolGraph(input: ToolGraphInput): ToolGraph {\n\tconst tools = input.tools\n\t\t.map((tool) => createGraphTool(tool))\n\t\t.toSorted((left, right) => compareCodePoint(left.ref.toolRef, right.ref.toolRef));\n\tconst allowedToolRefs = new Set(tools.map((tool) => tool.ref.toolRef));\n\tconst skills = createSkillEntries(input.skills ?? [], allowedToolRefs);\n\tconst toolsByRef = new Map(tools.map((tool) => [tool.ref.toolRef, tool]));\n\n\treturn {\n\t\trelationships: [\n\t\t\t...createEntityRelationships(tools),\n\t\t\t...createSchemaRelationships(tools),\n\t\t\t...createSkillRelationships(skills, toolsByRef),\n\t\t].toSorted(compareRelationships),\n\t\tskills,\n\t};\n}\n","import { createHash } from 'node:crypto';\n\nimport type { Tool } from '@modelcontextprotocol/sdk/types.js';\n\nimport { portalToolRecordSchema, type PortalToolRecord } from './catalog-types.js';\nimport {\n\tresolvePortalAccessPolicy,\n\tportalAgentScopeKey,\n\ttype PortalAccessPolicyConfig,\n\ttype PortalAgentIdentity,\n\ttype PortalToolSelector,\n} from './portal-access-policy.js';\nimport { createSearchIndex, type SearchIndex } from './search-index.js';\nimport { buildToolGraph, type SkillGraphInput, type ToolGraph } from './tool-graph.js';\n\nexport interface PortalCatalogSnapshot {\n\treadonly agentScopeId: string;\n\treadonly discoveryFailures: readonly PortalDiscoveryFailure[];\n\treadonly generatedAt: string;\n\treadonly sourceHash: string;\n\treadonly tools: readonly PortalToolRecord[];\n}\n\nexport interface PortalDiscoveryFailure {\n\treadonly message: string;\n\treadonly namespace: string;\n}\n\nexport interface PortalSession {\n\treadonly catalog: PortalCatalogSnapshot;\n\treadonly graph: ToolGraph;\n\treadonly identity: PortalAgentIdentity;\n\treadonly searchIndex: SearchIndex;\n}\n\nexport interface PortalSessionRuntime {\n\treadonly closeAgentScope: (agentScopeId: string) => Promise<void> | void;\n\treadonly closeSession?: (scopeKey: string) => Promise<void> | void;\n\treadonly listTools: (call: {\n\t\treadonly agentScopeId: string;\n\t\treadonly namespace: string;\n\t}) => Promise<readonly Tool[]>;\n}\n\nexport interface PortalSessionManagerOptions {\n\treadonly accessPolicy: PortalAccessPolicyConfig;\n\treadonly catalogTtlMs: number;\n\treadonly discoveryFailures?: readonly PortalDiscoveryFailure[];\n\treadonly now?: () => number;\n\treadonly runtime: PortalSessionRuntime;\n\treadonly skills?: readonly SkillGraphInput[];\n\treadonly upstreamNamespaces: readonly string[];\n}\n\nexport interface PortalSessionManager {\n\treadonly getSession: (identity: PortalAgentIdentity) => Promise<PortalSession>;\n\treadonly invalidateAgentScope: (agentScopeId: string) => Promise<void>;\n\treadonly invalidateSession: (identity: PortalAgentIdentity) => Promise<void>;\n}\n\ninterface CachedPortalSession {\n\treadonly expiresAt: number;\n\treadonly session: PortalSession;\n}\n\nfunction isHiddenTool(tool: PortalToolRecord, hiddenTools: readonly PortalToolSelector[]): boolean {\n\treturn hiddenTools.some(\n\t\t(hiddenTool) =>\n\t\t\thiddenTool.namespace === tool.namespace && hiddenTool.toolName === tool.toolName,\n\t);\n}\n\nfunction isEnabledTool(\n\ttool: PortalToolRecord,\n\tenabledTools: readonly PortalToolSelector[],\n): boolean {\n\tif (enabledTools.length === 0) {\n\t\treturn true;\n\t}\n\treturn enabledTools.some(\n\t\t(enabledTool) =>\n\t\t\tenabledTool.namespace === tool.namespace && enabledTool.toolName === tool.toolName,\n\t);\n}\n\nfunction portalToolFromMcpTool(namespace: string, tool: Tool): PortalToolRecord {\n\treturn portalToolRecordSchema.parse({\n\t\t...(tool.annotations !== undefined ? { annotations: tool.annotations } : {}),\n\t\t...(tool.description !== undefined ? { description: tool.description } : {}),\n\t\tinputSchema: tool.inputSchema,\n\t\tnamespace,\n\t\t...(tool.outputSchema !== undefined ? { outputSchema: tool.outputSchema } : {}),\n\t\t...(tool.title !== undefined ? { title: tool.title } : {}),\n\t\ttoolName: tool.name,\n\t});\n}\n\nfunction createSourceHash(tools: readonly PortalToolRecord[]): string {\n\treturn createHash('sha256').update(JSON.stringify(tools)).digest('hex');\n}\n\nfunction messageFromError(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nexport function createPortalSessionManager(\n\toptions: PortalSessionManagerOptions,\n): PortalSessionManager {\n\tconst sessions = new Map<string, CachedPortalSession>();\n\tconst agentScopeGenerations = new Map<string, number>();\n\tconst getNow = options.now ?? (() => Date.now());\n\n\tfunction generationForAgentScope(agentScopeId: string): number {\n\t\treturn agentScopeGenerations.get(agentScopeId) ?? 0;\n\t}\n\n\tfunction incrementAgentScopeGeneration(agentScopeId: string): void {\n\t\tagentScopeGenerations.set(agentScopeId, generationForAgentScope(agentScopeId) + 1);\n\t}\n\n\tfunction generationForScope(scopeKey: string): number {\n\t\tconst agentScopeId = scopeKey.split('\\n', 1)[0] ?? scopeKey;\n\t\treturn (agentScopeGenerations.get(scopeKey) ?? 0) + generationForAgentScope(agentScopeId);\n\t}\n\n\tfunction incrementScopeGeneration(scopeKey: string): void {\n\t\tagentScopeGenerations.set(scopeKey, generationForScope(scopeKey) + 1);\n\t}\n\n\tasync function buildSession(identity: PortalAgentIdentity): Promise<PortalSession> {\n\t\tconst policy = resolvePortalAccessPolicy({\n\t\t\tconfig: options.accessPolicy,\n\t\t\tidentity,\n\t\t\tupstreamNamespaces: options.upstreamNamespaces,\n\t\t});\n\t\tconst tools: PortalToolRecord[] = [];\n\t\tconst discoveryFailures: PortalDiscoveryFailure[] = [...(options.discoveryFailures ?? [])];\n\t\tconst allowedNamespaces = policy.allowedNamespaces;\n\n\t\tconst namespaceToolGroups = await Promise.allSettled(\n\t\t\tallowedNamespaces.map(async (namespace) => ({\n\t\t\t\tmcpTools: await options.runtime.listTools({\n\t\t\t\t\tagentScopeId: portalAgentScopeKey(identity),\n\t\t\t\t\tnamespace,\n\t\t\t\t}),\n\t\t\t\tnamespace,\n\t\t\t})),\n\t\t);\n\t\tfor (const [index, namespaceToolGroup] of namespaceToolGroups.entries()) {\n\t\t\tif (namespaceToolGroup.status === 'rejected') {\n\t\t\t\tconst namespace = allowedNamespaces[index] ?? 'unknown';\n\t\t\t\tdiscoveryFailures.push({ message: messageFromError(namespaceToolGroup.reason), namespace });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst { mcpTools, namespace } = namespaceToolGroup.value;\n\t\t\tfor (const mcpTool of mcpTools) {\n\t\t\t\tconst portalTool = portalToolFromMcpTool(namespace, mcpTool);\n\t\t\t\tif (\n\t\t\t\t\tisEnabledTool(portalTool, policy.enabledTools) &&\n\t\t\t\t\t!isHiddenTool(portalTool, policy.hiddenTools)\n\t\t\t\t) {\n\t\t\t\t\ttools.push(portalTool);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst sortedTools = tools.toSorted((left, right) => {\n\t\t\tconst namespaceOrder = left.namespace.localeCompare(right.namespace);\n\t\t\treturn namespaceOrder === 0 ? left.toolName.localeCompare(right.toolName) : namespaceOrder;\n\t\t});\n\t\tconst graph = buildToolGraph({ skills: options.skills ?? [], tools: sortedTools });\n\t\tconst catalog = {\n\t\t\tagentScopeId: identity.agentScopeId,\n\t\t\tdiscoveryFailures,\n\t\t\tgeneratedAt: new Date(getNow()).toISOString(),\n\t\t\tsourceHash: createSourceHash(sortedTools),\n\t\t\ttools: sortedTools,\n\t\t};\n\n\t\treturn {\n\t\t\tcatalog,\n\t\t\tgraph,\n\t\t\tidentity,\n\t\t\tsearchIndex: createSearchIndex(sortedTools, graph),\n\t\t};\n\t}\n\n\treturn {\n\t\tasync getSession(identity: PortalAgentIdentity): Promise<PortalSession> {\n\t\t\tconst key = portalAgentScopeKey(identity);\n\t\t\tconst now = getNow();\n\t\t\tconst cached = sessions.get(key);\n\t\t\tif (cached && cached.expiresAt > now) {\n\t\t\t\treturn cached.session;\n\t\t\t}\n\n\t\t\tconst generation = generationForScope(key);\n\t\t\tconst session = await buildSession(identity);\n\t\t\tif (\n\t\t\t\tgenerationForScope(key) === generation &&\n\t\t\t\tsession.catalog.discoveryFailures.length === 0\n\t\t\t) {\n\t\t\t\tsessions.set(key, { expiresAt: now + options.catalogTtlMs, session });\n\t\t\t}\n\t\t\treturn session;\n\t\t},\n\t\tasync invalidateAgentScope(agentScopeId: string): Promise<void> {\n\t\t\tincrementAgentScopeGeneration(agentScopeId);\n\t\t\tfor (const key of sessions.keys()) {\n\t\t\t\tif (key === agentScopeId || key.startsWith(`${agentScopeId}\\n`)) {\n\t\t\t\t\tsessions.delete(key);\n\t\t\t\t}\n\t\t\t}\n\t\t\tawait options.runtime.closeAgentScope(agentScopeId);\n\t\t},\n\t\tasync invalidateSession(identity: PortalAgentIdentity): Promise<void> {\n\t\t\tconst scopeKey = portalAgentScopeKey(identity);\n\t\t\tincrementScopeGeneration(scopeKey);\n\t\t\tsessions.delete(scopeKey);\n\t\t\tif (options.runtime.closeSession) {\n\t\t\t\tawait options.runtime.closeSession(scopeKey);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait options.runtime.closeAgentScope(scopeKey);\n\t\t},\n\t};\n}\n","import { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport {\n\tSSEClientTransport,\n\ttype SSEClientTransportOptions,\n} from '@modelcontextprotocol/sdk/client/sse.js';\nimport { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';\nimport {\n\tStreamableHTTPClientTransport,\n\ttype StreamableHTTPClientTransportOptions,\n} from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport { normalizeHeaders, type Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { ToolSchema, type Progress, type Tool } from '@modelcontextprotocol/sdk/types.js';\n\nimport type { JsonObject } from './json-schema.js';\nimport {\n\tredactThrownError,\n\tredactUpstreamCatalogValue,\n\tredactUpstreamResponse,\n} from './upstream-response-middleware.js';\n\nexport type UpstreamMcpTransportKind = 'auto-http' | 'sse' | 'stdio' | 'streamable-http';\n\ninterface BaseUpstreamMcpServer {\n\treadonly connectionTimeoutMs?: number;\n\treadonly namespace: string;\n\treadonly transport: UpstreamMcpTransportKind;\n}\n\nexport interface RemoteUpstreamMcpServer extends BaseUpstreamMcpServer {\n\treadonly eventSourceInit?: SSEClientTransportOptions['eventSourceInit'];\n\treadonly headers?: Readonly<Record<string, string>>;\n\treadonly requestInit?: RequestInit;\n\treadonly transport: 'auto-http' | 'sse' | 'streamable-http';\n\treadonly url: string;\n}\n\nexport interface StdioUpstreamMcpServer extends BaseUpstreamMcpServer {\n\treadonly args?: readonly string[];\n\treadonly command: string;\n\treadonly cwd?: string;\n\treadonly env?: Readonly<Record<string, string>>;\n\treadonly transport: 'stdio';\n}\n\nexport type NormalizedUpstreamMcpServer = RemoteUpstreamMcpServer | StdioUpstreamMcpServer;\n\nexport interface ListToolsCall {\n\treadonly agentScopeId: string;\n\treadonly namespace: string;\n}\n\nexport interface UpstreamToolCall {\n\treadonly arguments: JsonObject;\n\treadonly agentScopeId: string;\n\treadonly namespace: string;\n\treadonly onEvent?: (event: UpstreamToolEvent) => Promise<void> | void;\n\treadonly requestId?: string;\n\treadonly signal?: AbortSignal;\n\treadonly toolName: string;\n}\n\nexport type UpstreamToolEvent =\n\t| {\n\t\t\treadonly kind: 'progress';\n\t\t\treadonly message?: string;\n\t\t\treadonly progress: number;\n\t\t\treadonly total?: number;\n\t }\n\t// Extension event for runtimes that can source request-correlated MCP notifications.\n\t// The stock SDK callTool bridge currently emits real progress via RequestOptions.onprogress.\n\t| {\n\t\t\treadonly kind: 'upstream_notification';\n\t\t\treadonly method: string;\n\t\t\treadonly params: unknown;\n\t }\n\t// Extension event for runtimes that can source incremental content before the final result.\n\t| {\n\t\t\treadonly content:\n\t\t\t\t| { readonly text: string; readonly type: 'text' }\n\t\t\t\t| { readonly type: 'json'; readonly value: unknown };\n\t\t\treadonly kind: 'partial_content';\n\t };\n\nexport type UpstreamMcpProgress = Progress;\n\nexport interface UpstreamListToolsResult {\n\treadonly nextCursor?: string | undefined;\n\treadonly tools: readonly Tool[];\n}\n\nexport interface UpstreamMcpClientLike {\n\treadonly callTool: (\n\t\tparams: {\n\t\t\treadonly arguments: JsonObject;\n\t\t\treadonly name: string;\n\t\t},\n\t\tresultSchema?: unknown,\n\t\toptions?: {\n\t\t\treadonly onprogress?: (progress: UpstreamMcpProgress) => void;\n\t\t\treadonly signal?: AbortSignal;\n\t\t},\n\t) => Promise<unknown>;\n\treadonly close: () => Promise<void> | void;\n\treadonly connect: (\n\t\ttransport: unknown,\n\t\toptions?: { readonly signal?: AbortSignal },\n\t) => Promise<void>;\n\treadonly listTools: (\n\t\tparams?: { readonly cursor?: string },\n\t\toptions?: { readonly signal?: AbortSignal },\n\t) => Promise<UpstreamListToolsResult>;\n}\n\nexport interface UpstreamMcpRuntimeOptions {\n\treadonly additionalRedactionValues?: readonly string[];\n\treadonly createClient?: () => UpstreamMcpClientLike;\n\treadonly createTransport?: (\n\t\tserver: NormalizedUpstreamMcpServer,\n\t\ttransport: Exclude<UpstreamMcpTransportKind, 'auto-http'>,\n\t) => unknown;\n\treadonly maxResponseBytes?: number;\n\treadonly onCloseError?: (error: Error, context: UpstreamMcpCloseErrorContext) => void;\n\treadonly servers: readonly NormalizedUpstreamMcpServer[];\n}\n\nexport interface UpstreamMcpCloseErrorContext {\n\treadonly agentScopeId: string;\n\treadonly namespace?: string;\n}\n\nexport interface UpstreamMcpClientRuntime {\n\treadonly callTool: (call: UpstreamToolCall) => Promise<unknown>;\n\treadonly closeAgentScope: (agentScopeId: string) => Promise<void>;\n\treadonly closeSession: (scopeKey: string) => Promise<void>;\n\treadonly listTools: (call: ListToolsCall) => Promise<readonly Tool[]>;\n}\n\ninterface CachedClient {\n\treadonly client: UpstreamMcpClientLike;\n}\n\ninterface PendingClient {\n\treadonly generation: number;\n\treadonly promise: Promise<UpstreamMcpClientLike>;\n}\n\nconst defaultConnectionTimeoutMs = 30_000;\nconst defaultMaxResponseBytes = 4 * 1_024 * 1_024;\n\nfunction isObjectRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isTransport(value: unknown): value is Transport {\n\treturn (\n\t\tisObjectRecord(value) &&\n\t\ttypeof value.start === 'function' &&\n\t\ttypeof value.send === 'function' &&\n\t\ttypeof value.close === 'function'\n\t);\n}\n\nfunction createSdkClient(): UpstreamMcpClientLike {\n\tconst client = new Client({ name: 'mcp-portal', version: '1.0.0' });\n\treturn {\n\t\tcallTool: async (params, _resultSchema, options) =>\n\t\t\tawait client.callTool(params, undefined, options),\n\t\tclose: async () => {\n\t\t\tawait client.close();\n\t\t},\n\t\tconnect: async (transport, options) => {\n\t\t\tif (!isTransport(transport)) {\n\t\t\t\tthrow new Error('SDK MCP client requires a valid MCP transport.');\n\t\t\t}\n\t\t\tawait client.connect(transport, options);\n\t\t},\n\t\tlistTools: async (params, options) => {\n\t\t\tconst result = await client.listTools(params, options);\n\t\t\treturn {\n\t\t\t\t...(result.nextCursor !== undefined ? { nextCursor: result.nextCursor } : {}),\n\t\t\t\ttools: result.tools,\n\t\t\t};\n\t\t},\n\t};\n}\n\nfunction withRemoteHeaders(server: RemoteUpstreamMcpServer): RemoteUpstreamMcpServer {\n\tif (!server.headers) {\n\t\treturn server;\n\t}\n\n\treturn {\n\t\t...server,\n\t\trequestInit: {\n\t\t\t...server.requestInit,\n\t\t\theaders: {\n\t\t\t\t...normalizeHeaders(server.requestInit?.headers),\n\t\t\t\t...server.headers,\n\t\t\t},\n\t\t},\n\t};\n}\n\nfunction createSdkTransport(\n\tserver: NormalizedUpstreamMcpServer,\n\ttransport: Exclude<UpstreamMcpTransportKind, 'auto-http'>,\n): unknown {\n\tif (transport === 'stdio') {\n\t\tif (server.transport !== 'stdio') {\n\t\t\tthrow new Error('Stdio transport requires stdio server config.');\n\t\t}\n\n\t\treturn new StdioClientTransport({\n\t\t\t...(server.args ? { args: [...server.args] } : {}),\n\t\t\tcommand: server.command,\n\t\t\t...(server.cwd !== undefined ? { cwd: server.cwd } : {}),\n\t\t\t...(server.env ? { env: { ...server.env } } : {}),\n\t\t});\n\t}\n\n\tif (server.transport === 'stdio') {\n\t\tthrow new Error('Remote transport requires remote server config.');\n\t}\n\n\tconst remoteServer = withRemoteHeaders(server);\n\tif (transport === 'sse') {\n\t\tconst options: SSEClientTransportOptions = {};\n\t\tif (remoteServer.eventSourceInit !== undefined) {\n\t\t\toptions.eventSourceInit = remoteServer.eventSourceInit;\n\t\t}\n\t\tif (remoteServer.requestInit !== undefined) {\n\t\t\toptions.requestInit = remoteServer.requestInit;\n\t\t}\n\t\treturn new SSEClientTransport(new URL(remoteServer.url), options);\n\t}\n\n\tconst options: StreamableHTTPClientTransportOptions = {};\n\tif (remoteServer.requestInit !== undefined) {\n\t\toptions.requestInit = remoteServer.requestInit;\n\t}\n\treturn new StreamableHTTPClientTransport(new URL(remoteServer.url), options);\n}\n\nfunction cacheKey(agentScopeId: string, namespace: string): string {\n\treturn `${agentScopeId}\\n${namespace}`;\n}\n\nfunction rootAgentScopeId(agentScopeId: string): string {\n\treturn agentScopeId.split('\\n', 1)[0] ?? agentScopeId;\n}\n\nfunction transportAttempts(\n\tserver: NormalizedUpstreamMcpServer,\n): readonly Exclude<UpstreamMcpTransportKind, 'auto-http'>[] {\n\tif (server.transport === 'auto-http') {\n\t\treturn ['streamable-http', 'sse'];\n\t}\n\n\treturn [server.transport];\n}\n\nfunction redactionValuesFromServer(server: NormalizedUpstreamMcpServer): readonly string[] {\n\tif (server.transport === 'stdio') {\n\t\treturn Object.values(server.env ?? {}).filter((value) => value.length > 0);\n\t}\n\n\treturn Object.values(server.headers ?? {}).filter((value) => value.length > 0);\n}\n\nfunction timeoutMsForServer(server: NormalizedUpstreamMcpServer): number {\n\treturn server.connectionTimeoutMs ?? defaultConnectionTimeoutMs;\n}\n\nfunction assertUpstreamResponseSize(value: unknown, maxResponseBytes: number): void {\n\tconst serialized = JSON.stringify(value);\n\tif (serialized === undefined) {\n\t\treturn;\n\t}\n\tconst byteLength = Buffer.byteLength(serialized, 'utf8');\n\tif (byteLength > maxResponseBytes) {\n\t\tthrow new Error(\n\t\t\t`MCP upstream response exceeded ${String(maxResponseBytes)} bytes (${String(byteLength)} bytes).`,\n\t\t);\n\t}\n}\n\nfunction isAbortError(error: unknown): boolean {\n\treturn error instanceof Error && error.name === 'AbortError';\n}\n\nfunction isCallerAbortError(error: unknown, signal: AbortSignal | undefined): boolean {\n\treturn signal?.aborted === true && (error === signal.reason || isAbortError(error));\n}\n\nasync function withTimeout<TResult>(\n\tpromise: Promise<TResult>,\n\tprops: {\n\t\treadonly onTimeout?: (error: Error) => void;\n\t\treadonly operation: string;\n\t\treadonly timeoutMs: number;\n\t},\n): Promise<TResult> {\n\tlet timeout: NodeJS.Timeout | undefined;\n\ttry {\n\t\treturn await Promise.race([\n\t\t\tpromise,\n\t\t\tnew Promise<never>((_resolve, reject) => {\n\t\t\t\ttimeout = setTimeout(() => {\n\t\t\t\t\tconst error = new Error(`${props.operation} timed out after ${props.timeoutMs}ms.`);\n\t\t\t\t\tprops.onTimeout?.(error);\n\t\t\t\t\treject(error);\n\t\t\t\t}, props.timeoutMs);\n\t\t\t}),\n\t\t]);\n\t} finally {\n\t\tif (timeout) {\n\t\t\tclearTimeout(timeout);\n\t\t}\n\t}\n}\n\nfunction createRuntimeAbortSignal(parentSignal: AbortSignal | undefined): {\n\treadonly abortTimeout: (error: Error) => void;\n\treadonly dispose: () => void;\n\treadonly signal: AbortSignal;\n} {\n\tconst controller = new AbortController();\n\tconst abortFromParent = (): void => {\n\t\tif (!controller.signal.aborted) {\n\t\t\tcontroller.abort(parentSignal?.reason);\n\t\t}\n\t};\n\tif (parentSignal?.aborted) {\n\t\tabortFromParent();\n\t} else {\n\t\tparentSignal?.addEventListener('abort', abortFromParent, { once: true });\n\t}\n\n\treturn {\n\t\tabortTimeout: (error) => {\n\t\t\tif (!controller.signal.aborted) {\n\t\t\t\tcontroller.abort(error);\n\t\t\t}\n\t\t},\n\t\tdispose: () => {\n\t\t\tparentSignal?.removeEventListener('abort', abortFromParent);\n\t\t},\n\t\tsignal: controller.signal,\n\t};\n}\n\nasync function listAllTools(\n\tclient: UpstreamMcpClientLike,\n\tcursor: string | undefined,\n\tcollectedTools: readonly Tool[],\n\ttimeoutAbort: {\n\t\treadonly abortTimeout: (error: Error) => void;\n\t\treadonly signal: AbortSignal;\n\t},\n\ttimeoutMs: number,\n): Promise<readonly Tool[]> {\n\tconst result = await withTimeout(\n\t\tclient.listTools(cursor ? { cursor } : undefined, { signal: timeoutAbort.signal }),\n\t\t{\n\t\t\tonTimeout: timeoutAbort.abortTimeout,\n\t\t\toperation: 'MCP listTools',\n\t\t\ttimeoutMs,\n\t\t},\n\t);\n\tconst nextTools = [...collectedTools, ...result.tools];\n\treturn result.nextCursor\n\t\t? listAllTools(client, result.nextCursor, nextTools, timeoutAbort, timeoutMs)\n\t\t: nextTools;\n}\n\nasync function closeClientAfterFailure(client: UpstreamMcpClientLike | null): Promise<void> {\n\tif (!client) {\n\t\treturn;\n\t}\n\ttry {\n\t\tawait client.close();\n\t} catch {\n\t\t// Preserve the original upstream failure; close errors are best-effort cleanup.\n\t}\n}\n\nasync function closeClientForTeardown(\n\tclient: UpstreamMcpClientLike | null,\n\tprops: {\n\t\treadonly context: UpstreamMcpCloseErrorContext;\n\t\treadonly onCloseError?:\n\t\t\t| ((error: Error, context: UpstreamMcpCloseErrorContext) => void)\n\t\t\t| undefined;\n\t},\n): Promise<void> {\n\tif (!client) {\n\t\treturn;\n\t}\n\ttry {\n\t\tawait client.close();\n\t} catch (error) {\n\t\tprops.onCloseError?.(redactThrownError(error), props.context);\n\t}\n}\n\nfunction closeErrorContextFromCacheKey(cacheKeyValue: string): UpstreamMcpCloseErrorContext {\n\tconst keyParts = cacheKeyValue.split('\\n');\n\tconst namespace = keyParts.length > 1 ? keyParts[keyParts.length - 1] : undefined;\n\tconst agentScopeId =\n\t\tnamespace !== undefined ? keyParts.slice(0, keyParts.length - 1).join('\\n') : cacheKeyValue;\n\treturn {\n\t\tagentScopeId,\n\t\t...(namespace !== undefined ? { namespace } : {}),\n\t};\n}\n\nfunction redactToolCatalog(\n\ttools: readonly Tool[],\n\toptions: { readonly exactValues: readonly string[] },\n): readonly Tool[] {\n\treturn tools.map((tool) => ToolSchema.parse(redactUpstreamCatalogValue(tool, options)));\n}\n\nexport function createUpstreamMcpClientRuntime(\n\toptions: UpstreamMcpRuntimeOptions,\n): UpstreamMcpClientRuntime {\n\tconst serversByNamespace = new Map(options.servers.map((server) => [server.namespace, server]));\n\tconst clients = new Map<string, CachedClient>();\n\tconst pendingClients = new Map<string, PendingClient>();\n\tconst agentScopeGenerations = new Map<string, number>();\n\tconst closedClients = new WeakSet<UpstreamMcpClientLike>();\n\tconst createClient = options.createClient ?? createSdkClient;\n\tconst createTransport = options.createTransport ?? createSdkTransport;\n\tconst maxResponseBytes = options.maxResponseBytes ?? defaultMaxResponseBytes;\n\tconst redactionValues = [\n\t\t...(options.additionalRedactionValues ?? []),\n\t\t...options.servers.flatMap((server) => redactionValuesFromServer(server)),\n\t];\n\n\tfunction generationForAgentScope(agentScopeId: string): number {\n\t\treturn (\n\t\t\tagentScopeGenerations.get(agentScopeId) ??\n\t\t\tagentScopeGenerations.get(rootAgentScopeId(agentScopeId)) ??\n\t\t\t0\n\t\t);\n\t}\n\n\tfunction incrementAgentScopeGeneration(agentScopeId: string): void {\n\t\tconst rootAgentScope = rootAgentScopeId(agentScopeId);\n\t\tagentScopeGenerations.set(rootAgentScope, (agentScopeGenerations.get(rootAgentScope) ?? 0) + 1);\n\t}\n\n\tfunction incrementScopeGeneration(scopeKey: string): void {\n\t\tagentScopeGenerations.set(scopeKey, (agentScopeGenerations.get(scopeKey) ?? 0) + 1);\n\t}\n\n\tasync function closeClientAfterFailureOnce(client: UpstreamMcpClientLike | null): Promise<void> {\n\t\tif (!client || closedClients.has(client)) {\n\t\t\treturn;\n\t\t}\n\t\tclosedClients.add(client);\n\t\tawait closeClientAfterFailure(client);\n\t}\n\n\tasync function closeClientForTeardownOnce(\n\t\tclient: UpstreamMcpClientLike | null,\n\t\tcontext: UpstreamMcpCloseErrorContext,\n\t): Promise<void> {\n\t\tif (!client || closedClients.has(client)) {\n\t\t\treturn;\n\t\t}\n\t\tclosedClients.add(client);\n\t\tawait closeClientForTeardown(client, {\n\t\t\tcontext,\n\t\t\tonCloseError: options.onCloseError,\n\t\t});\n\t}\n\n\tasync function createConnectedClient(\n\t\tserver: NormalizedUpstreamMcpServer,\n\t): Promise<UpstreamMcpClientLike> {\n\t\tconst attempts = transportAttempts(server);\n\t\tasync function tryAttempt(\n\t\t\tattemptIndex: number,\n\t\t\tlastError: Error | null,\n\t\t): Promise<UpstreamMcpClientLike> {\n\t\t\tconst transportKind = attempts[attemptIndex];\n\t\t\tif (transportKind === undefined) {\n\t\t\t\tthrow (\n\t\t\t\t\tlastError ??\n\t\t\t\t\tnew Error(`Could not connect to upstream MCP namespace \"${server.namespace}\".`)\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst client = createClient();\n\t\t\tconst transportServer =\n\t\t\t\ttransportKind === 'sse' && server.transport !== 'stdio'\n\t\t\t\t\t? withRemoteHeaders(server)\n\t\t\t\t\t: server;\n\t\t\tconst transport = createTransport(transportServer, transportKind);\n\t\t\tconst timeoutAbort = createRuntimeAbortSignal(undefined);\n\t\t\ttry {\n\t\t\t\tawait withTimeout(client.connect(transport, { signal: timeoutAbort.signal }), {\n\t\t\t\t\tonTimeout: timeoutAbort.abortTimeout,\n\t\t\t\t\toperation: `MCP ${transportKind} connect for namespace \"${server.namespace}\"`,\n\t\t\t\t\ttimeoutMs: timeoutMsForServer(server),\n\t\t\t\t});\n\t\t\t\treturn client;\n\t\t\t} catch (error) {\n\t\t\t\tconst redactedError = redactThrownError(error, { exactValues: redactionValues });\n\t\t\t\tawait closeClientAfterFailureOnce(client);\n\t\t\t\treturn tryAttempt(attemptIndex + 1, redactedError);\n\t\t\t} finally {\n\t\t\t\ttimeoutAbort.dispose();\n\t\t\t}\n\t\t}\n\n\t\treturn tryAttempt(0, null);\n\t}\n\n\tasync function getClient(\n\t\tagentScopeId: string,\n\t\tnamespace: string,\n\t): Promise<UpstreamMcpClientLike> {\n\t\tconst key = cacheKey(agentScopeId, namespace);\n\t\tconst cachedClient = clients.get(key);\n\t\tif (cachedClient) {\n\t\t\treturn cachedClient.client;\n\t\t}\n\t\tconst pendingClient = pendingClients.get(key);\n\t\tconst generation = generationForAgentScope(agentScopeId);\n\t\tif (pendingClient && pendingClient.generation === generation) {\n\t\t\treturn pendingClient.promise;\n\t\t}\n\t\tif (pendingClient) {\n\t\t\tpendingClients.delete(key);\n\t\t\tvoid pendingClient.promise.then(closeClientAfterFailureOnce, () => undefined);\n\t\t}\n\n\t\tconst server = serversByNamespace.get(namespace);\n\t\tif (!server) {\n\t\t\tthrow new Error(`Unknown upstream MCP namespace \"${namespace}\".`);\n\t\t}\n\n\t\tconst pending = createConnectedClient(server);\n\t\tconst pendingRecord = { generation, promise: pending } satisfies PendingClient;\n\t\tpendingClients.set(key, pendingRecord);\n\t\ttry {\n\t\t\tconst client = await pending;\n\t\t\tif (generationForAgentScope(agentScopeId) !== generation) {\n\t\t\t\tawait closeClientAfterFailureOnce(client);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`MCP client for agent scope \"${rootAgentScopeId(agentScopeId)}\" was invalidated.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tclients.set(key, { client });\n\t\t\tif (generationForAgentScope(agentScopeId) !== generation) {\n\t\t\t\tif (clients.get(key)?.client === client) {\n\t\t\t\t\tclients.delete(key);\n\t\t\t\t}\n\t\t\t\tawait closeClientAfterFailureOnce(client);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`MCP client for agent scope \"${rootAgentScopeId(agentScopeId)}\" was invalidated.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn client;\n\t\t} finally {\n\t\t\tif (pendingClients.get(key) === pendingRecord) {\n\t\t\t\tpendingClients.delete(key);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tasync callTool(call: UpstreamToolCall): Promise<unknown> {\n\t\t\tconst key = cacheKey(call.agentScopeId, call.namespace);\n\t\t\tlet client: UpstreamMcpClientLike | null = null;\n\t\t\ttry {\n\t\t\t\tclient = await getClient(call.agentScopeId, call.namespace);\n\t\t\t\tconst server = serversByNamespace.get(call.namespace);\n\t\t\t\tconst timeoutAbort = createRuntimeAbortSignal(call.signal);\n\t\t\t\ttry {\n\t\t\t\t\tconst upstreamResult = await withTimeout(\n\t\t\t\t\t\tclient.callTool({ arguments: call.arguments, name: call.toolName }, undefined, {\n\t\t\t\t\t\t\tonprogress: (progress) => {\n\t\t\t\t\t\t\t\tvoid call.onEvent?.({\n\t\t\t\t\t\t\t\t\tkind: 'progress',\n\t\t\t\t\t\t\t\t\t...(progress.message !== undefined ? { message: progress.message } : {}),\n\t\t\t\t\t\t\t\t\tprogress: progress.progress,\n\t\t\t\t\t\t\t\t\t...(progress.total !== undefined ? { total: progress.total } : {}),\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tsignal: timeoutAbort.signal,\n\t\t\t\t\t\t}),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tonTimeout: timeoutAbort.abortTimeout,\n\t\t\t\t\t\t\toperation: `MCP callTool ${call.namespace}.${call.toolName}`,\n\t\t\t\t\t\t\ttimeoutMs: server ? timeoutMsForServer(server) : defaultConnectionTimeoutMs,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t\tassertUpstreamResponseSize(upstreamResult, maxResponseBytes);\n\t\t\t\t\treturn redactUpstreamResponse(upstreamResult, { exactValues: redactionValues });\n\t\t\t\t} finally {\n\t\t\t\t\ttimeoutAbort.dispose();\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (isCallerAbortError(error, call.signal)) {\n\t\t\t\t\tthrow redactThrownError(error, { exactValues: redactionValues });\n\t\t\t\t}\n\t\t\t\tclients.delete(key);\n\t\t\t\tawait closeClientAfterFailureOnce(client);\n\t\t\t\tthrow redactThrownError(error, { exactValues: redactionValues });\n\t\t\t}\n\t\t},\n\t\tasync closeAgentScope(agentScopeId: string): Promise<void> {\n\t\t\tincrementAgentScopeGeneration(agentScopeId);\n\t\t\tconst closePromises: Promise<void>[] = [];\n\t\t\tfor (const [key, cachedClient] of clients.entries()) {\n\t\t\t\tif (key !== agentScopeId && !key.startsWith(`${agentScopeId}\\n`)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tclients.delete(key);\n\t\t\t\tclosePromises.push(\n\t\t\t\t\tcloseClientForTeardownOnce(cachedClient.client, closeErrorContextFromCacheKey(key)),\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (const [key, pendingClient] of pendingClients.entries()) {\n\t\t\t\tif (key !== agentScopeId && !key.startsWith(`${agentScopeId}\\n`)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tpendingClients.delete(key);\n\t\t\t\tclosePromises.push(\n\t\t\t\t\tpendingClient.promise.then(\n\t\t\t\t\t\t(client) => closeClientForTeardownOnce(client, closeErrorContextFromCacheKey(key)),\n\t\t\t\t\t\t() => undefined,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait Promise.all(closePromises);\n\t\t},\n\t\tasync closeSession(scopeKey: string): Promise<void> {\n\t\t\tincrementScopeGeneration(scopeKey);\n\t\t\tconst closePromises: Promise<void>[] = [];\n\t\t\tfor (const [key, cachedClient] of clients.entries()) {\n\t\t\t\tif (key !== scopeKey && !key.startsWith(`${scopeKey}\\n`)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tclients.delete(key);\n\t\t\t\tclosePromises.push(\n\t\t\t\t\tcloseClientForTeardownOnce(cachedClient.client, closeErrorContextFromCacheKey(key)),\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (const [key, pendingClient] of pendingClients.entries()) {\n\t\t\t\tif (key !== scopeKey && !key.startsWith(`${scopeKey}\\n`)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tpendingClients.delete(key);\n\t\t\t\tclosePromises.push(\n\t\t\t\t\tpendingClient.promise.then(\n\t\t\t\t\t\t(client) => closeClientForTeardownOnce(client, closeErrorContextFromCacheKey(key)),\n\t\t\t\t\t\t() => undefined,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait Promise.all(closePromises);\n\t\t},\n\t\tasync listTools(call: ListToolsCall): Promise<readonly Tool[]> {\n\t\t\tconst key = cacheKey(call.agentScopeId, call.namespace);\n\t\t\tlet client: UpstreamMcpClientLike | null = null;\n\t\t\ttry {\n\t\t\t\tclient = await getClient(call.agentScopeId, call.namespace);\n\t\t\t\tconst server = serversByNamespace.get(call.namespace);\n\t\t\t\tconst timeoutAbort = createRuntimeAbortSignal(undefined);\n\t\t\t\ttry {\n\t\t\t\t\treturn redactToolCatalog(\n\t\t\t\t\t\tawait listAllTools(\n\t\t\t\t\t\t\tclient,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\ttimeoutAbort,\n\t\t\t\t\t\t\tserver ? timeoutMsForServer(server) : defaultConnectionTimeoutMs,\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{ exactValues: redactionValues },\n\t\t\t\t\t);\n\t\t\t\t} finally {\n\t\t\t\t\ttimeoutAbort.dispose();\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tclients.delete(key);\n\t\t\t\tawait closeClientAfterFailureOnce(client);\n\t\t\t\t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+
import { SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
3
|
+
import { Progress, Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
|
|
5
|
+
//#region src/upstream-mcp-client-runtime.d.ts
|
|
6
|
+
type UpstreamMcpTransportKind = 'auto-http' | 'sse' | 'stdio' | 'streamable-http';
|
|
7
|
+
interface BaseUpstreamMcpServer {
|
|
8
|
+
readonly connectionTimeoutMs?: number;
|
|
9
|
+
readonly namespace: string;
|
|
10
|
+
readonly transport: UpstreamMcpTransportKind;
|
|
11
|
+
}
|
|
12
|
+
interface RemoteUpstreamMcpServer extends BaseUpstreamMcpServer {
|
|
13
|
+
readonly eventSourceInit?: SSEClientTransportOptions['eventSourceInit'];
|
|
14
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
15
|
+
readonly requestInit?: RequestInit;
|
|
16
|
+
readonly transport: 'auto-http' | 'sse' | 'streamable-http';
|
|
17
|
+
readonly url: string;
|
|
18
|
+
}
|
|
19
|
+
interface StdioUpstreamMcpServer extends BaseUpstreamMcpServer {
|
|
20
|
+
readonly args?: readonly string[];
|
|
21
|
+
readonly command: string;
|
|
22
|
+
readonly cwd?: string;
|
|
23
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
24
|
+
readonly transport: 'stdio';
|
|
25
|
+
}
|
|
26
|
+
type NormalizedUpstreamMcpServer = RemoteUpstreamMcpServer | StdioUpstreamMcpServer;
|
|
27
|
+
interface ListToolsCall {
|
|
28
|
+
readonly agentScopeId: string;
|
|
29
|
+
readonly namespace: string;
|
|
30
|
+
}
|
|
31
|
+
interface UpstreamToolCall {
|
|
32
|
+
readonly arguments: JsonObject;
|
|
33
|
+
readonly agentScopeId: string;
|
|
34
|
+
readonly namespace: string;
|
|
35
|
+
readonly onEvent?: (event: UpstreamToolEvent) => Promise<void> | void;
|
|
36
|
+
readonly requestId?: string;
|
|
37
|
+
readonly signal?: AbortSignal;
|
|
38
|
+
readonly toolName: string;
|
|
39
|
+
}
|
|
40
|
+
type UpstreamToolEvent = {
|
|
41
|
+
readonly kind: 'progress';
|
|
42
|
+
readonly message?: string;
|
|
43
|
+
readonly progress: number;
|
|
44
|
+
readonly total?: number;
|
|
45
|
+
} | {
|
|
46
|
+
readonly kind: 'upstream_notification';
|
|
47
|
+
readonly method: string;
|
|
48
|
+
readonly params: unknown;
|
|
49
|
+
} | {
|
|
50
|
+
readonly content: {
|
|
51
|
+
readonly text: string;
|
|
52
|
+
readonly type: 'text';
|
|
53
|
+
} | {
|
|
54
|
+
readonly type: 'json';
|
|
55
|
+
readonly value: unknown;
|
|
56
|
+
};
|
|
57
|
+
readonly kind: 'partial_content';
|
|
58
|
+
};
|
|
59
|
+
type UpstreamMcpProgress = Progress;
|
|
60
|
+
interface UpstreamListToolsResult {
|
|
61
|
+
readonly nextCursor?: string | undefined;
|
|
62
|
+
readonly tools: readonly Tool[];
|
|
63
|
+
}
|
|
64
|
+
interface UpstreamMcpClientLike {
|
|
65
|
+
readonly callTool: (params: {
|
|
66
|
+
readonly arguments: JsonObject;
|
|
67
|
+
readonly name: string;
|
|
68
|
+
}, resultSchema?: unknown, options?: {
|
|
69
|
+
readonly onprogress?: (progress: UpstreamMcpProgress) => void;
|
|
70
|
+
readonly signal?: AbortSignal;
|
|
71
|
+
}) => Promise<unknown>;
|
|
72
|
+
readonly close: () => Promise<void> | void;
|
|
73
|
+
readonly connect: (transport: unknown, options?: {
|
|
74
|
+
readonly signal?: AbortSignal;
|
|
75
|
+
}) => Promise<void>;
|
|
76
|
+
readonly listTools: (params?: {
|
|
77
|
+
readonly cursor?: string;
|
|
78
|
+
}, options?: {
|
|
79
|
+
readonly signal?: AbortSignal;
|
|
80
|
+
}) => Promise<UpstreamListToolsResult>;
|
|
81
|
+
}
|
|
82
|
+
interface UpstreamMcpRuntimeOptions {
|
|
83
|
+
readonly additionalRedactionValues?: readonly string[];
|
|
84
|
+
readonly createClient?: () => UpstreamMcpClientLike;
|
|
85
|
+
readonly createTransport?: (server: NormalizedUpstreamMcpServer, transport: Exclude<UpstreamMcpTransportKind, 'auto-http'>) => unknown;
|
|
86
|
+
readonly maxResponseBytes?: number;
|
|
87
|
+
readonly onCloseError?: (error: Error, context: UpstreamMcpCloseErrorContext) => void;
|
|
88
|
+
readonly servers: readonly NormalizedUpstreamMcpServer[];
|
|
89
|
+
}
|
|
90
|
+
interface UpstreamMcpCloseErrorContext {
|
|
91
|
+
readonly agentScopeId: string;
|
|
92
|
+
readonly namespace?: string;
|
|
93
|
+
}
|
|
94
|
+
interface UpstreamMcpClientRuntime {
|
|
95
|
+
readonly callTool: (call: UpstreamToolCall) => Promise<unknown>;
|
|
96
|
+
readonly closeAgentScope: (agentScopeId: string) => Promise<void>;
|
|
97
|
+
readonly closeSession: (scopeKey: string) => Promise<void>;
|
|
98
|
+
readonly listTools: (call: ListToolsCall) => Promise<readonly Tool[]>;
|
|
99
|
+
}
|
|
100
|
+
declare function createUpstreamMcpClientRuntime(options: UpstreamMcpRuntimeOptions): UpstreamMcpClientRuntime;
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/upstream-response-middleware.d.ts
|
|
103
|
+
interface RedactionOptions {
|
|
104
|
+
readonly exactValues?: readonly string[];
|
|
105
|
+
}
|
|
106
|
+
declare function isCredentialConfigKey(key: string): boolean;
|
|
107
|
+
declare function redactExactCredentialText(text: string, options?: RedactionOptions): string;
|
|
108
|
+
declare function redactCredentialText(text: string, options?: RedactionOptions): string;
|
|
109
|
+
declare function redactUpstreamResponse(response: unknown, options?: RedactionOptions): unknown;
|
|
110
|
+
declare function redactUpstreamCatalogValue(response: unknown, options?: RedactionOptions): unknown;
|
|
111
|
+
declare function redactThrownError(error: unknown, options?: RedactionOptions): Error;
|
|
112
|
+
declare function toRedactedJsonValue(value: unknown, options?: RedactionOptions): JsonValue;
|
|
113
|
+
//#endregion
|
|
114
|
+
export { createUpstreamMcpClientRuntime as S, UpstreamMcpProgress as _, redactThrownError as a, UpstreamToolCall as b, toRedactedJsonValue as c, RemoteUpstreamMcpServer as d, StdioUpstreamMcpServer as f, UpstreamMcpCloseErrorContext as g, UpstreamMcpClientRuntime as h, redactExactCredentialText as i, ListToolsCall as l, UpstreamMcpClientLike as m, isCredentialConfigKey as n, redactUpstreamCatalogValue as o, UpstreamListToolsResult as p, redactCredentialText as r, redactUpstreamResponse as s, RedactionOptions as t, NormalizedUpstreamMcpServer as u, UpstreamMcpRuntimeOptions as v, UpstreamToolEvent as x, UpstreamMcpTransportKind as y };
|
|
115
|
+
//# sourceMappingURL=upstream-response-middleware-1MZnAD9C.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstream-response-middleware-1MZnAD9C.d.ts","names":[],"sources":["../src/upstream-mcp-client-runtime.ts","../src/upstream-response-middleware.ts"],"mappings":";;;;;KAoBY,wBAAA;AAAA,UAEF,qBAAA;EAAA,SACA,mBAAA;EAAA,SACA,SAAA;EAAA,SACA,SAAA,EAAW,wBAAA;AAAA;AAAA,UAGJ,uBAAA,SAAgC,qBAAA;EAAA,SACvC,eAAA,GAAkB,yBAAA;EAAA,SAClB,OAAA,GAAU,QAAA,CAAS,MAAA;EAAA,SACnB,WAAA,GAAc,WAAA;EAAA,SACd,SAAA;EAAA,SACA,GAAA;AAAA;AAAA,UAGO,sBAAA,SAA+B,qBAAA;EAAA,SACtC,IAAA;EAAA,SACA,OAAA;EAAA,SACA,GAAA;EAAA,SACA,GAAA,GAAM,QAAA,CAAS,MAAA;EAAA,SACf,SAAA;AAAA;AAAA,KAGE,2BAAA,GAA8B,uBAAA,GAA0B,sBAAA;AAAA,UAEnD,aAAA;EAAA,SACP,YAAA;EAAA,SACA,SAAA;AAAA;AAAA,UAGO,gBAAA;EAAA,SACP,SAAA,EAAW,UAAA;EAAA,SACX,YAAA;EAAA,SACA,SAAA;EAAA,SACA,OAAA,IAAW,KAAA,EAAO,iBAAA,KAAsB,OAAA;EAAA,SACxC,SAAA;EAAA,SACA,MAAA,GAAS,WAAA;EAA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P,QAAA,GAAW,IAAA,EAAM,gBAAA,KAAqB,OAAA;EAAA,SACtC,eAAA,GAAkB,YAAA,aAAyB,OAAA;EAAA,SAC3C,YAAA,GAAe,QAAA,aAAqB,OAAA;EAAA,SACpC,SAAA,GAAY,IAAA,EAAM,aAAA,KAAkB,OAAA,UAAiB,IAAA;AAAA;AAAA,iBAiS/C,8BAAA,CACf,OAAA,EAAS,yBAAA,GACP,wBAAA;;;UCjac,gBAAA;EAAA,SACP,WAAA;AAAA;AAAA,iBAGM,qBAAA,CAAsB,GAAA;AAAA,iBAmBtB,yBAAA,CAA0B,IAAA,UAAc,OAAA,GAAS,gBAAA;AAAA,iBAIjD,oBAAA,CAAqB,IAAA,UAAc,OAAA,GAAS,gBAAA;AAAA,iBAyE5C,sBAAA,CAAuB,QAAA,WAAmB,OAAA,GAAS,gBAAA;AAAA,iBAInD,0BAAA,CACf,QAAA,WACA,OAAA,GAAS,gBAAA;AAAA,iBAqBM,iBAAA,CAAkB,KAAA,WAAgB,OAAA,GAAS,gBAAA,GAAwB,KAAA;AAAA,iBA0BnE,mBAAA,CAAoB,KAAA,WAAgB,OAAA,GAAS,gBAAA,GAAwB,SAAA"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { a as portalToolRecordSchema, r as encodeToolRef } from "./zod-schema-loader-yNekKNpm.js";
|
|
2
|
+
//#region src/portal-access-policy.ts
|
|
3
|
+
const portalAgentIdentityBrand = Symbol("PortalAgentIdentity");
|
|
4
|
+
function createPortalAgentIdentity(input) {
|
|
5
|
+
validateIdentitySegment("agentId", input.agentId);
|
|
6
|
+
validateIdentitySegment("agentScopeId", input.agentScopeId);
|
|
7
|
+
if (input.sessionId !== void 0) validateIdentitySegment("sessionId", input.sessionId);
|
|
8
|
+
if (input.sessionKey !== void 0) validateIdentitySegment("sessionKey", input.sessionKey);
|
|
9
|
+
if (input.authSubject !== void 0) validateIdentitySegment("authSubject", input.authSubject);
|
|
10
|
+
return {
|
|
11
|
+
agentId: input.agentId,
|
|
12
|
+
agentScopeId: input.agentScopeId,
|
|
13
|
+
...input.authSubject !== void 0 ? { authSubject: input.authSubject } : {},
|
|
14
|
+
...input.sessionId !== void 0 ? { sessionId: input.sessionId } : {},
|
|
15
|
+
...input.sessionKey !== void 0 ? { sessionKey: input.sessionKey } : {},
|
|
16
|
+
source: input.source,
|
|
17
|
+
[portalAgentIdentityBrand]: true
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function validateIdentitySegment(name, value) {
|
|
21
|
+
if (value.length === 0) throw new Error(`MCP Portal ${name} must not be empty.`);
|
|
22
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
23
|
+
const codePoint = value.charCodeAt(index);
|
|
24
|
+
if (codePoint < 32 || codePoint === 127 || codePoint === 8232 || codePoint === 8233) throw new Error(`MCP Portal ${name} must not contain control characters.`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function portalAgentScopeKey(identity) {
|
|
28
|
+
const sessionScope = identity.sessionId ?? identity.sessionKey;
|
|
29
|
+
return sessionScope ? `${identity.agentScopeId}\n${sessionScope}` : identity.agentScopeId;
|
|
30
|
+
}
|
|
31
|
+
function sortToolSelectors(selectors) {
|
|
32
|
+
return [...selectors].toSorted((left, right) => {
|
|
33
|
+
const namespaceOrder = left.namespace.localeCompare(right.namespace);
|
|
34
|
+
return namespaceOrder === 0 ? left.toolName.localeCompare(right.toolName) : namespaceOrder;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function resolvePortalAccessPolicy(props) {
|
|
38
|
+
const agentNamespaces = props.config.enabledNamespacesByAgent[props.identity.agentId];
|
|
39
|
+
const globalNamespaces = props.config.enabledNamespaces;
|
|
40
|
+
const selectedNamespaces = agentNamespaces ?? globalNamespaces ?? (props.config.defaultPolicy === "allow-all" ? props.upstreamNamespaces : []);
|
|
41
|
+
const upstreamNamespaceSet = new Set(props.upstreamNamespaces);
|
|
42
|
+
return {
|
|
43
|
+
allowedNamespaces: selectedNamespaces.filter((namespace) => upstreamNamespaceSet.has(namespace)).toSorted(),
|
|
44
|
+
enabledTools: sortToolSelectors(props.config.enabledToolsByAgent?.[props.identity.agentId] ?? []),
|
|
45
|
+
hiddenTools: sortToolSelectors(props.config.hiddenToolsByAgent[props.identity.agentId] ?? [])
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/tool-summary.ts
|
|
50
|
+
function stringArrayFromValue(value) {
|
|
51
|
+
if (!Array.isArray(value)) return [];
|
|
52
|
+
return value.filter((entry) => typeof entry === "string").toSorted();
|
|
53
|
+
}
|
|
54
|
+
function objectPropertiesFromSchema(schema) {
|
|
55
|
+
const properties = schema.properties;
|
|
56
|
+
if (typeof properties !== "object" || properties === null || Array.isArray(properties)) return [];
|
|
57
|
+
return Object.keys(properties).toSorted();
|
|
58
|
+
}
|
|
59
|
+
function summarizeJsonSchema(schema) {
|
|
60
|
+
const properties = objectPropertiesFromSchema(schema);
|
|
61
|
+
const required = stringArrayFromValue(schema.required);
|
|
62
|
+
const requiredSet = new Set(required);
|
|
63
|
+
return {
|
|
64
|
+
optional: properties.filter((propertyName) => !requiredSet.has(propertyName)),
|
|
65
|
+
propertyCount: properties.length,
|
|
66
|
+
required,
|
|
67
|
+
type: typeof schema.type === "string" ? schema.type : "unknown"
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function createToolSummary(tool) {
|
|
71
|
+
const parsed = portalToolRecordSchema.parse(tool);
|
|
72
|
+
const safety = {
|
|
73
|
+
...parsed.annotations?.destructiveHint !== void 0 ? { destructiveHint: parsed.annotations.destructiveHint } : {},
|
|
74
|
+
...parsed.annotations?.readOnlyHint !== void 0 ? { readOnlyHint: parsed.annotations.readOnlyHint } : {}
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
...parsed.description !== void 0 ? { description: parsed.description } : {},
|
|
78
|
+
input: summarizeJsonSchema(parsed.inputSchema),
|
|
79
|
+
namespace: parsed.namespace,
|
|
80
|
+
...parsed.outputSchema ? { output: summarizeJsonSchema(parsed.outputSchema) } : {},
|
|
81
|
+
safety,
|
|
82
|
+
...parsed.title !== void 0 ? { title: parsed.title } : {},
|
|
83
|
+
toolName: parsed.toolName,
|
|
84
|
+
toolRef: encodeToolRef({
|
|
85
|
+
namespace: parsed.namespace,
|
|
86
|
+
toolName: parsed.toolName
|
|
87
|
+
})
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/upstream-response-middleware.ts
|
|
92
|
+
const credentialPatterns = [
|
|
93
|
+
/\bBearer\s+[A-Za-z0-9._~+/=-]+/gi,
|
|
94
|
+
/\bBasic\s+[A-Za-z0-9._~+/=-]+/gi,
|
|
95
|
+
/\b(api[_-]?key|token|password|secret)=([^&\s]+)/gi
|
|
96
|
+
];
|
|
97
|
+
function isCredentialConfigKey(key) {
|
|
98
|
+
const normalizedKey = key.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
99
|
+
return normalizedKey === "auth" || normalizedKey === "authorization" || normalizedKey === "apikey" || normalizedKey.endsWith("apikey") || normalizedKey.endsWith("token") || normalizedKey.endsWith("password") || normalizedKey.endsWith("secret");
|
|
100
|
+
}
|
|
101
|
+
function redactExactValues(text, exactValues) {
|
|
102
|
+
return exactValues.filter((value) => value.length > 0).reduce((currentText, value) => currentText.split(value).join("[REDACTED]"), text);
|
|
103
|
+
}
|
|
104
|
+
function redactExactCredentialText(text, options = {}) {
|
|
105
|
+
return redactExactValues(text, options.exactValues ?? []);
|
|
106
|
+
}
|
|
107
|
+
function redactCredentialText(text, options = {}) {
|
|
108
|
+
return redactExactValues(credentialPatterns.reduce((current, pattern) => current.replace(pattern, "[REDACTED]"), text), options.exactValues ?? []);
|
|
109
|
+
}
|
|
110
|
+
function redactJsonValue(value, options, keyHint) {
|
|
111
|
+
if (typeof value === "string") return keyHint && isCredentialConfigKey(keyHint) ? "[REDACTED]" : redactCredentialText(value, options);
|
|
112
|
+
if (Array.isArray(value)) return value.map((entry) => redactJsonValue(entry, options));
|
|
113
|
+
if (typeof value !== "object" || value === null) return value;
|
|
114
|
+
return Object.fromEntries(Object.entries(value).map(([key, childValue]) => [key, redactJsonValue(childValue, options, key)]));
|
|
115
|
+
}
|
|
116
|
+
function redactExactJsonValue(value, options) {
|
|
117
|
+
if (typeof value === "string") return redactExactCredentialText(value, options);
|
|
118
|
+
if (Array.isArray(value)) return value.map((entry) => redactExactJsonValue(entry, options));
|
|
119
|
+
if (typeof value !== "object" || value === null) return value;
|
|
120
|
+
return Object.fromEntries(Object.entries(value).map(([key, childValue]) => [key, redactExactJsonValue(childValue, options)]));
|
|
121
|
+
}
|
|
122
|
+
function isJsonValue(value) {
|
|
123
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") return true;
|
|
124
|
+
if (Array.isArray(value)) return value.every(isJsonValue);
|
|
125
|
+
if (typeof value !== "object") return false;
|
|
126
|
+
return Object.values(value).every(isJsonValue);
|
|
127
|
+
}
|
|
128
|
+
function redactUpstreamResponse(response, options = {}) {
|
|
129
|
+
return redactJsonValue(response, options);
|
|
130
|
+
}
|
|
131
|
+
function redactUpstreamCatalogValue(response, options = {}) {
|
|
132
|
+
return redactExactJsonValue(response, options);
|
|
133
|
+
}
|
|
134
|
+
function copyRedactedErrorField(props) {
|
|
135
|
+
const descriptor = Object.getOwnPropertyDescriptor(props.source, props.fieldName);
|
|
136
|
+
if (!descriptor || !("value" in descriptor)) return;
|
|
137
|
+
Object.defineProperty(props.target, props.fieldName, {
|
|
138
|
+
...descriptor,
|
|
139
|
+
value: redactJsonValue(descriptor.value, props.options)
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function redactThrownError(error, options = {}) {
|
|
143
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
144
|
+
if (!(error instanceof Error)) return new Error(redactCredentialText(message, options));
|
|
145
|
+
const rawCause = "cause" in error ? error.cause : void 0;
|
|
146
|
+
const redactedCause = rawCause === void 0 || rawCause === error ? void 0 : rawCause instanceof Error ? redactThrownError(rawCause, options) : redactJsonValue(rawCause, options);
|
|
147
|
+
const redactedError = redactedCause === void 0 ? new Error(redactCredentialText(message, options)) : new Error(redactCredentialText(message, options), { cause: redactedCause });
|
|
148
|
+
redactedError.name = error.name;
|
|
149
|
+
if (error.stack) redactedError.stack = redactCredentialText(error.stack, options);
|
|
150
|
+
copyRedactedErrorField({
|
|
151
|
+
fieldName: "code",
|
|
152
|
+
options,
|
|
153
|
+
source: error,
|
|
154
|
+
target: redactedError
|
|
155
|
+
});
|
|
156
|
+
copyRedactedErrorField({
|
|
157
|
+
fieldName: "data",
|
|
158
|
+
options,
|
|
159
|
+
source: error,
|
|
160
|
+
target: redactedError
|
|
161
|
+
});
|
|
162
|
+
return redactedError;
|
|
163
|
+
}
|
|
164
|
+
function toRedactedJsonValue(value, options = {}) {
|
|
165
|
+
const redacted = redactJsonValue(value, options);
|
|
166
|
+
if (isJsonValue(redacted)) return redacted;
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
export { redactUpstreamCatalogValue as a, createToolSummary as c, portalAgentScopeKey as d, resolvePortalAccessPolicy as f, redactThrownError as i, summarizeJsonSchema as l, redactCredentialText as n, redactUpstreamResponse as o, redactExactCredentialText as r, toRedactedJsonValue as s, isCredentialConfigKey as t, createPortalAgentIdentity as u };
|
|
171
|
+
|
|
172
|
+
//# sourceMappingURL=upstream-response-middleware-BjUWZ2G8.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstream-response-middleware-BjUWZ2G8.js","names":[],"sources":["../src/portal-access-policy.ts","../src/tool-summary.ts","../src/upstream-response-middleware.ts"],"sourcesContent":["const portalAgentIdentityBrand = Symbol('PortalAgentIdentity');\n\nexport type PortalAgentIdentity = {\n\treadonly agentId: string;\n\t// `agentScopeId` is the upstream session/cache boundary. Most current adapters scope it\n\t// per agent, but the core keeps it separate so a future adapter can isolate per session\n\t// without changing the authorization identity.\n\treadonly agentScopeId: string;\n\treadonly authSubject?: string;\n\treadonly sessionId?: string;\n\treadonly sessionKey?: string;\n\treadonly source: PortalAgentScopeSource;\n\treadonly [portalAgentIdentityBrand]: true;\n};\n\nexport type PortalAgentScopeSource = 'cli-operator' | 'mcp-proxy-bearer' | 'openclaw-trusted';\n\nexport interface PortalToolSelector {\n\treadonly namespace: string;\n\treadonly toolName: string;\n}\n\nexport type PortalDefaultPolicy = 'allow-all' | 'deny-all';\n\nexport interface PortalAccessPolicyConfig {\n\treadonly defaultPolicy?: PortalDefaultPolicy;\n\treadonly enabledNamespaces?: readonly string[];\n\treadonly enabledNamespacesByAgent: Readonly<Record<string, readonly string[]>>;\n\treadonly enabledToolsByAgent?: Readonly<Record<string, readonly PortalToolSelector[]>>;\n\treadonly hiddenToolsByAgent: Readonly<Record<string, readonly PortalToolSelector[]>>;\n}\n\nexport interface ResolvedPortalAccessPolicy {\n\treadonly allowedNamespaces: readonly string[];\n\treadonly enabledTools: readonly PortalToolSelector[];\n\treadonly hiddenTools: readonly PortalToolSelector[];\n}\n\nexport function createPortalAgentIdentity(input: {\n\treadonly agentId: string;\n\treadonly agentScopeId: string;\n\treadonly authSubject?: string;\n\treadonly sessionId?: string;\n\treadonly sessionKey?: string;\n\treadonly source: PortalAgentScopeSource;\n}): PortalAgentIdentity {\n\tvalidateIdentitySegment('agentId', input.agentId);\n\tvalidateIdentitySegment('agentScopeId', input.agentScopeId);\n\tif (input.sessionId !== undefined) {\n\t\tvalidateIdentitySegment('sessionId', input.sessionId);\n\t}\n\tif (input.sessionKey !== undefined) {\n\t\tvalidateIdentitySegment('sessionKey', input.sessionKey);\n\t}\n\tif (input.authSubject !== undefined) {\n\t\tvalidateIdentitySegment('authSubject', input.authSubject);\n\t}\n\treturn {\n\t\tagentId: input.agentId,\n\t\tagentScopeId: input.agentScopeId,\n\t\t...(input.authSubject !== undefined ? { authSubject: input.authSubject } : {}),\n\t\t...(input.sessionId !== undefined ? { sessionId: input.sessionId } : {}),\n\t\t...(input.sessionKey !== undefined ? { sessionKey: input.sessionKey } : {}),\n\t\tsource: input.source,\n\t\t[portalAgentIdentityBrand]: true,\n\t};\n}\n\nfunction validateIdentitySegment(name: string, value: string): void {\n\tif (value.length === 0) {\n\t\tthrow new Error(`MCP Portal ${name} must not be empty.`);\n\t}\n\tfor (let index = 0; index < value.length; index += 1) {\n\t\tconst codePoint = value.charCodeAt(index);\n\t\tif (codePoint < 32 || codePoint === 127 || codePoint === 0x2028 || codePoint === 0x2029) {\n\t\t\tthrow new Error(`MCP Portal ${name} must not contain control characters.`);\n\t\t}\n\t}\n}\n\nexport function portalAgentScopeKey(identity: PortalAgentIdentity): string {\n\tconst sessionScope = identity.sessionId ?? identity.sessionKey;\n\treturn sessionScope ? `${identity.agentScopeId}\\n${sessionScope}` : identity.agentScopeId;\n}\n\nfunction sortToolSelectors(\n\tselectors: readonly PortalToolSelector[],\n): readonly PortalToolSelector[] {\n\treturn [...selectors].toSorted((left, right) => {\n\t\tconst namespaceOrder = left.namespace.localeCompare(right.namespace);\n\t\treturn namespaceOrder === 0 ? left.toolName.localeCompare(right.toolName) : namespaceOrder;\n\t});\n}\n\nexport function resolvePortalAccessPolicy(props: {\n\treadonly config: PortalAccessPolicyConfig;\n\treadonly identity: PortalAgentIdentity;\n\treadonly upstreamNamespaces: readonly string[];\n}): ResolvedPortalAccessPolicy {\n\tconst agentNamespaces = props.config.enabledNamespacesByAgent[props.identity.agentId];\n\tconst globalNamespaces = props.config.enabledNamespaces;\n\tconst selectedNamespaces =\n\t\tagentNamespaces ??\n\t\tglobalNamespaces ??\n\t\t(props.config.defaultPolicy === 'allow-all' ? props.upstreamNamespaces : []);\n\tconst upstreamNamespaceSet = new Set(props.upstreamNamespaces);\n\n\treturn {\n\t\tallowedNamespaces: selectedNamespaces\n\t\t\t.filter((namespace) => upstreamNamespaceSet.has(namespace))\n\t\t\t.toSorted(),\n\t\tenabledTools: sortToolSelectors(\n\t\t\tprops.config.enabledToolsByAgent?.[props.identity.agentId] ?? [],\n\t\t),\n\t\thiddenTools: sortToolSelectors(props.config.hiddenToolsByAgent[props.identity.agentId] ?? []),\n\t};\n}\n","import { portalToolRecordSchema, type PortalToolRecord } from './catalog-types.js';\nimport type { JsonObject } from './json-schema.js';\nimport { encodeToolRef } from './tool-ref.js';\n\nexport interface ToolSchemaSummary {\n\treadonly optional: readonly string[];\n\treadonly propertyCount: number;\n\treadonly required: readonly string[];\n\treadonly type: string;\n}\n\nexport interface ToolSafetySummary {\n\treadonly destructiveHint?: boolean;\n\treadonly readOnlyHint?: boolean;\n}\n\nexport interface ToolSummary {\n\treadonly description?: string;\n\treadonly input: ToolSchemaSummary;\n\treadonly namespace: string;\n\treadonly output?: ToolSchemaSummary;\n\treadonly safety: ToolSafetySummary;\n\treadonly title?: string;\n\treadonly toolName: string;\n\treadonly toolRef: string;\n}\n\nfunction stringArrayFromValue(value: unknown): readonly string[] {\n\tif (!Array.isArray(value)) {\n\t\treturn [];\n\t}\n\n\treturn value.filter((entry): entry is string => typeof entry === 'string').toSorted();\n}\n\nfunction objectPropertiesFromSchema(schema: JsonObject): readonly string[] {\n\tconst properties = schema.properties;\n\tif (typeof properties !== 'object' || properties === null || Array.isArray(properties)) {\n\t\treturn [];\n\t}\n\n\treturn Object.keys(properties).toSorted();\n}\n\nexport function summarizeJsonSchema(schema: JsonObject): ToolSchemaSummary {\n\tconst properties = objectPropertiesFromSchema(schema);\n\tconst required = stringArrayFromValue(schema.required);\n\tconst requiredSet = new Set(required);\n\tconst optional = properties.filter((propertyName) => !requiredSet.has(propertyName));\n\n\treturn {\n\t\toptional,\n\t\tpropertyCount: properties.length,\n\t\trequired,\n\t\ttype: typeof schema.type === 'string' ? schema.type : 'unknown',\n\t};\n}\n\nexport function createToolSummary(tool: PortalToolRecord): ToolSummary {\n\tconst parsed = portalToolRecordSchema.parse(tool);\n\tconst safety = {\n\t\t...(parsed.annotations?.destructiveHint !== undefined\n\t\t\t? { destructiveHint: parsed.annotations.destructiveHint }\n\t\t\t: {}),\n\t\t...(parsed.annotations?.readOnlyHint !== undefined\n\t\t\t? { readOnlyHint: parsed.annotations.readOnlyHint }\n\t\t\t: {}),\n\t};\n\n\treturn {\n\t\t...(parsed.description !== undefined ? { description: parsed.description } : {}),\n\t\tinput: summarizeJsonSchema(parsed.inputSchema),\n\t\tnamespace: parsed.namespace,\n\t\t...(parsed.outputSchema ? { output: summarizeJsonSchema(parsed.outputSchema) } : {}),\n\t\tsafety,\n\t\t...(parsed.title !== undefined ? { title: parsed.title } : {}),\n\t\ttoolName: parsed.toolName,\n\t\ttoolRef: encodeToolRef({ namespace: parsed.namespace, toolName: parsed.toolName }),\n\t};\n}\n","import type { JsonValue } from './json-schema.js';\n\nconst credentialPatterns = [\n\t/\\bBearer\\s+[A-Za-z0-9._~+/=-]+/gi,\n\t/\\bBasic\\s+[A-Za-z0-9._~+/=-]+/gi,\n\t/\\b(api[_-]?key|token|password|secret)=([^&\\s]+)/gi,\n];\n\nexport interface RedactionOptions {\n\treadonly exactValues?: readonly string[];\n}\n\nexport function isCredentialConfigKey(key: string): boolean {\n\tconst normalizedKey = key.toLowerCase().replace(/[^a-z0-9]/g, '');\n\treturn (\n\t\tnormalizedKey === 'auth' ||\n\t\tnormalizedKey === 'authorization' ||\n\t\tnormalizedKey === 'apikey' ||\n\t\tnormalizedKey.endsWith('apikey') ||\n\t\tnormalizedKey.endsWith('token') ||\n\t\tnormalizedKey.endsWith('password') ||\n\t\tnormalizedKey.endsWith('secret')\n\t);\n}\n\nfunction redactExactValues(text: string, exactValues: readonly string[]): string {\n\treturn exactValues\n\t\t.filter((value) => value.length > 0)\n\t\t.reduce((currentText, value) => currentText.split(value).join('[REDACTED]'), text);\n}\n\nexport function redactExactCredentialText(text: string, options: RedactionOptions = {}): string {\n\treturn redactExactValues(text, options.exactValues ?? []);\n}\n\nexport function redactCredentialText(text: string, options: RedactionOptions = {}): string {\n\tconst patternRedactedText = credentialPatterns.reduce(\n\t\t(current, pattern) => current.replace(pattern, '[REDACTED]'),\n\t\ttext,\n\t);\n\treturn redactExactValues(patternRedactedText, options.exactValues ?? []);\n}\n\nfunction redactJsonValue(value: unknown, options: RedactionOptions, keyHint?: string): unknown {\n\tif (typeof value === 'string') {\n\t\treturn keyHint && isCredentialConfigKey(keyHint)\n\t\t\t? '[REDACTED]'\n\t\t\t: redactCredentialText(value, options);\n\t}\n\n\tif (Array.isArray(value)) {\n\t\treturn value.map((entry) => redactJsonValue(entry, options));\n\t}\n\n\tif (typeof value !== 'object' || value === null) {\n\t\treturn value;\n\t}\n\n\treturn Object.fromEntries(\n\t\tObject.entries(value).map(([key, childValue]) => [\n\t\t\tkey,\n\t\t\tredactJsonValue(childValue, options, key),\n\t\t]),\n\t);\n}\n\nfunction redactExactJsonValue(value: unknown, options: RedactionOptions): unknown {\n\tif (typeof value === 'string') {\n\t\treturn redactExactCredentialText(value, options);\n\t}\n\n\tif (Array.isArray(value)) {\n\t\treturn value.map((entry) => redactExactJsonValue(entry, options));\n\t}\n\n\tif (typeof value !== 'object' || value === null) {\n\t\treturn value;\n\t}\n\n\treturn Object.fromEntries(\n\t\tObject.entries(value).map(([key, childValue]) => [\n\t\t\tkey,\n\t\t\tredactExactJsonValue(childValue, options),\n\t\t]),\n\t);\n}\n\nfunction isJsonValue(value: unknown): value is JsonValue {\n\tif (\n\t\tvalue === null ||\n\t\ttypeof value === 'string' ||\n\t\ttypeof value === 'number' ||\n\t\ttypeof value === 'boolean'\n\t) {\n\t\treturn true;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\treturn value.every(isJsonValue);\n\t}\n\n\tif (typeof value !== 'object') {\n\t\treturn false;\n\t}\n\n\treturn Object.values(value).every(isJsonValue);\n}\n\nexport function redactUpstreamResponse(response: unknown, options: RedactionOptions = {}): unknown {\n\treturn redactJsonValue(response, options);\n}\n\nexport function redactUpstreamCatalogValue(\n\tresponse: unknown,\n\toptions: RedactionOptions = {},\n): unknown {\n\treturn redactExactJsonValue(response, options);\n}\n\nfunction copyRedactedErrorField(props: {\n\treadonly source: Error;\n\treadonly target: Error;\n\treadonly fieldName: string;\n\treadonly options: RedactionOptions;\n}): void {\n\tconst descriptor = Object.getOwnPropertyDescriptor(props.source, props.fieldName);\n\tif (!descriptor || !('value' in descriptor)) {\n\t\treturn;\n\t}\n\tObject.defineProperty(props.target, props.fieldName, {\n\t\t...descriptor,\n\t\tvalue: redactJsonValue(descriptor.value, props.options),\n\t});\n}\n\nexport function redactThrownError(error: unknown, options: RedactionOptions = {}): Error {\n\tconst message = error instanceof Error ? error.message : String(error);\n\tif (!(error instanceof Error)) {\n\t\treturn new Error(redactCredentialText(message, options));\n\t}\n\n\tconst rawCause = 'cause' in error ? error.cause : undefined;\n\tconst redactedCause =\n\t\trawCause === undefined || rawCause === error\n\t\t\t? undefined\n\t\t\t: rawCause instanceof Error\n\t\t\t\t? redactThrownError(rawCause, options)\n\t\t\t\t: redactJsonValue(rawCause, options);\n\tconst redactedError =\n\t\tredactedCause === undefined\n\t\t\t? new Error(redactCredentialText(message, options))\n\t\t\t: new Error(redactCredentialText(message, options), { cause: redactedCause });\n\tredactedError.name = error.name;\n\tif (error.stack) {\n\t\tredactedError.stack = redactCredentialText(error.stack, options);\n\t}\n\tcopyRedactedErrorField({ fieldName: 'code', options, source: error, target: redactedError });\n\tcopyRedactedErrorField({ fieldName: 'data', options, source: error, target: redactedError });\n\treturn redactedError;\n}\n\nexport function toRedactedJsonValue(value: unknown, options: RedactionOptions = {}): JsonValue {\n\tconst redacted = redactJsonValue(value, options);\n\tif (isJsonValue(redacted)) {\n\t\treturn redacted;\n\t}\n\n\treturn null;\n}\n"],"mappings":";;AAAA,MAAM,2BAA2B,OAAO,sBAAsB;AAsC9D,SAAgB,0BAA0B,OAOlB;CACvB,wBAAwB,WAAW,MAAM,QAAQ;CACjD,wBAAwB,gBAAgB,MAAM,aAAa;CAC3D,IAAI,MAAM,cAAc,KAAA,GACvB,wBAAwB,aAAa,MAAM,UAAU;CAEtD,IA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Q;EACvD,CAAC;;AAGH,SAAgB,kBAAkB,OAAgB,UAA4B,EAAE,EAAS;CACxF,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;CACtE,IAAI,EAAE,iBAAiB,QACtB,OAAO,IAAI,MAAM,qBAAqB,SAAS,QAAQ,CAAC;CAGzD,MAAM,WAAW,WAAW,QAAQ,MAAM,QAAQ,KAAA;CAClD,MAAM,gBACL,aAAa,KAAA,KAAa,aAAa,QACpC,KAAA,IACA,oBAAoB,QACnB,kBAAkB,UAAU,QAAQ,GACpC,gBAAgB,UAAU,QAAQ;CACvC,MAAM,gBACL,kBAAkB,KAAA,IACf,IAAI,MAAM,qBAAqB,SAAS,QAAQ,CAAC,GACjD,IAAI,MAAM,qBAAqB,SAAS,QAAQ,EAAE,EAAE,OAAO,eAAe,CAAC;CAC/E,cAAc,OAAO,MAAM;CAC3B,IAAI,MAAM,OACT,cAAc,QAAQ,qBAAqB,MAAM,OAAO,QAAQ;CAEjE,uBAAuB;EAAE,WAAW;EAAQ;EAAS,QAAQ;EAAO,QAAQ;EAAe,CAAC;CAC5F,uBAAuB;EAAE,WAAW;EAAQ;EAAS,QAAQ;EAAO,QAAQ;EAAe,CAAC;CAC5F,OAAO;;AAGR,SAAgB,oBAAoB,OAAgB,UAA4B,EAAE,EAAa;CAC9F,MAAM,WAAW,gBAAgB,OAAO,QAAQ;CAChD,IAAI,YAAY,SAAS,EACxB,OAAO;CAGR,OAAO"}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { s as JsonObject } from "./catalog-types-BVuB4Ynx.js";
|
|
2
2
|
|
|
3
|
-
//#region src/tool-vm/typescript-artifact.d.ts
|
|
4
|
-
interface CatalogArtifactInput {
|
|
5
|
-
readonly tools: readonly PortalToolRecord[];
|
|
6
|
-
}
|
|
7
|
-
declare function generateTypescriptCatalogArtifact(input: CatalogArtifactInput): string;
|
|
8
|
-
//#endregion
|
|
9
3
|
//#region src/zod-schema-loader.d.ts
|
|
10
4
|
interface InputValidationIssue {
|
|
11
5
|
readonly code: string;
|
|
@@ -38,5 +32,5 @@ type BuiltZodValidator = {
|
|
|
38
32
|
};
|
|
39
33
|
declare function buildZodValidatorFromJsonSchema(jsonSchema: JsonObject): BuiltZodValidator;
|
|
40
34
|
//#endregion
|
|
41
|
-
export { SchemaValidationUnavailableError as a,
|
|
42
|
-
//# sourceMappingURL=
|
|
35
|
+
export { SchemaValidationUnavailableError as a, PortalValidationResult as i, InputValidationError as n, buildZodValidatorFromJsonSchema as o, InputValidationIssue as r, BuiltZodValidator as t };
|
|
36
|
+
//# sourceMappingURL=zod-schema-loader-DLGQpYFD.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-schema-loader-DLGQpYFD.d.ts","names":[],"sources":["../src/zod-schema-loader.ts"],"mappings":";;;UAIiB,oBAAA;EAAA,SACP,IAAA;EAAA,SACA,OAAA;EAAA,SACA,IAAA;AAAA;AAAA,UAGO,oBAAA;EAAA,SACP,IAAA;EAAA,SACA,MAAA,WAAiB,oBAAA;AAAA;AAAA,UAGV,gCAAA;EAAA,SACP,OAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA;EAAA,SACA,IAAA;AAAA;AAAA,KAGE,sBAAA;EAAA,SACE,EAAA;EAAA,SAAmB,KAAA;AAAA;EAAA,SACnB,KAAA,EAAO,oBAAA;EAAA,SAA+B,EAAA;AAAA;AAAA,KAExC,iBAAA;EAAA,SAEA,EAAA;EAAA,SACA,QAAA,GAAW,KAAA,cAAmB,sBAAA;AAAA;EAAA,SAG9B,KAAA,EAAO,gCAAA;EAAA,SACP,EAAA;AAAA;AAAA,iBA4EI,+BAAA,CAAgC,UAAA,EAAY,UAAA,GAAa,iBAAA"}
|