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cesContent":["/**\n * Model Context Protocol (MCP) identity validation for Krikos.\n *\n * An MCP server can require that a connecting agent prove its identity and hold the right\n * capability before a request is honored. Krikos provides the gate: map an MCP method (and, for\n * `tools/call`, the tool name) to a capability requirement, then authorize the acting agent\n * against the registry before dispatching. A denied request is recorded in the audit trail.\n *\n * Structural by design: Krikos imports nothing from any MCP SDK. The request shape is matched by\n * structure.\n *\n * @packageDocumentation\n */\n\nimport type { Krikos } from '../types.js';\n\n/** A minimal structural MCP request: a method, and optional params carrying a tool name. */\nexport interface McpRequestLike {\n  /** The JSON-RPC method, for example `tools/call`, `resources/read`, `prompts/get`. */\n  readonly method: string;\n  /** Optional params; for `tools/call` the tool name lives at `params.name`. */\n  readonly params?: { readonly name?: string; readonly [key: string]: unknown };\n}\n\n/** The capability a method (or method plus tool) requires. */\nexport interface McpCapability {\n  /** The capability name required. */\n  readonly capability: string;\n  /** The action required. Defaults to the method (or tool name for `tools/call`). */\n  readonly action?: string;\n}\n\n/**\n * A mapping from MCP route to capability requirement. A route is either a bare method\n * (`resources/read`) or a method plus tool name joined by a colon (`tools/call:deploy`). The more\n * specific tool route wins when both are present.\n */\nexport type McpCapabilityMap = Readonly<Record<string, McpCapability>>;\n\n/** The route key for a request: `method:tool` when a tool name is present, else `method`. */\nfunction routeKey(request: McpRequestLike): { readonly route: string; readonly tool?: string } {\n  const tool = request.method === 'tools/call' ? request.params?.name : undefined;\n  if (typeof tool === 'string' && tool.length > 0) {\n    return { route: `${request.method}:${tool}`, tool };\n  }\n  return { route: request.method };\n}\n\n/**\n * Builds an MCP identity guard bound to a registry and a capability map.\n *\n * The returned function authorizes one request for one agent: it resolves the request's route,\n * looks up its capability requirement (a tool-specific route takes precedence over the bare\n * method), and authorizes the agent. A route with no mapping is denied by default when\n * `denyUnmapped` is true (the safe posture), or allowed when false. Every decision is recorded.\n *\n * @param krikos - The registry holding agent identities.\n * @param mapping - Route-to-capability requirements.\n * @param options - `denyUnmapped` defaults to true (fail-closed for unmapped routes).\n * @returns A guard `(agentId, request) => boolean`.\n */\nexport function mcpIdentityGuard(\n  krikos: Krikos,\n  mapping: McpCapabilityMap,\n  options: { readonly denyUnmapped?: boolean } = {},\n): (agentId: string, request: McpRequestLike) => boolean {\n  const denyUnmapped = options.denyUnmapped ?? true;\n  return (agentId: string, request: McpRequestLike): boolean => {\n    const { route, tool } = routeKey(request);\n    const requirement = mapping[route] ?? mapping[request.method];\n    if (requirement === undefined) {\n      if (denyUnmapped) {\n        krikos.authorize(agentId, 'mcp', request.method, route, 'mcp:unmapped');\n        return false;\n      }\n      return true;\n    }\n    const action = requirement.action ?? tool ?? request.method;\n    return krikos.authorize(agentId, requirement.capability, action, route, 'mcp');\n  };\n}\n"]}