@kya-os/mcp-i-runtime 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/config.d.ts +5 -7
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/config.js +4 -6
  5. package/dist/config.js.map +1 -1
  6. package/dist/index.d.ts +3 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +20 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/runtime/audit-logger.d.ts +6 -28
  11. package/dist/runtime/audit-logger.d.ts.map +1 -1
  12. package/dist/runtime/audit-logger.js +5 -3
  13. package/dist/runtime/audit-logger.js.map +1 -1
  14. package/dist/runtime/audit.d.ts +132 -0
  15. package/dist/runtime/audit.d.ts.map +1 -0
  16. package/dist/runtime/audit.js +424 -0
  17. package/dist/runtime/audit.js.map +1 -0
  18. package/dist/runtime/base.d.ts +9 -48
  19. package/dist/runtime/base.d.ts.map +1 -1
  20. package/dist/runtime/base.js +109 -89
  21. package/dist/runtime/base.js.map +1 -1
  22. package/dist/services/auth-type-satisfies.d.ts +93 -0
  23. package/dist/services/auth-type-satisfies.d.ts.map +1 -0
  24. package/dist/services/auth-type-satisfies.js +127 -0
  25. package/dist/services/auth-type-satisfies.js.map +1 -0
  26. package/dist/services/oauth-config.service.d.ts.map +1 -1
  27. package/dist/services/oauth-config.service.js +29 -0
  28. package/dist/services/oauth-config.service.js.map +1 -1
  29. package/dist/services/tool-context-builder.d.ts +6 -1
  30. package/dist/services/tool-context-builder.d.ts.map +1 -1
  31. package/dist/services/tool-context-builder.js +35 -3
  32. package/dist/services/tool-context-builder.js.map +1 -1
  33. package/package.json +7 -3
  34. package/src/__tests__/config/provider-runtime-config.test.ts +2 -9
  35. package/src/__tests__/config.test.ts +12 -11
  36. package/src/__tests__/integration/full-flow.test.ts +0 -5
  37. package/src/__tests__/integration.test.ts +2 -6
  38. package/src/__tests__/runtime/audit.test.ts +327 -0
  39. package/src/__tests__/runtime/base-extensions.test.ts +0 -46
  40. package/src/__tests__/runtime/base.test.ts +71 -102
  41. package/src/__tests__/runtime/delegation-flow.test.ts +0 -4
  42. package/src/__tests__/runtime/process-tool-call-security.test.ts +5 -11
  43. package/src/__tests__/runtime/proof-client-did.test.ts +0 -4
  44. package/src/__tests__/runtime/provider-selection.test.ts +0 -2
  45. package/src/__tests__/runtime/route-interception.test.ts +7 -4
  46. package/src/__tests__/runtime/tool-protection-enforcement.test.ts +23 -31
  47. package/src/__tests__/services/tool-protection-merged-config.test.ts +0 -40
  48. package/src/config/__tests__/merged-config.spec.ts +0 -26
  49. package/src/config.ts +9 -10
  50. package/src/index.ts +32 -2
  51. package/src/runtime/__tests__/audit-logger-compat.test.ts +15 -0
  52. package/src/runtime/audit-logger.ts +6 -29
  53. package/src/runtime/audit.ts +598 -0
  54. package/src/runtime/base.ts +154 -99
  55. package/src/services/__tests__/auth-type-satisfies.test.ts +232 -0
  56. package/src/services/__tests__/oauth-config.service.test.ts +66 -0
  57. package/src/services/__tests__/proof-verifier.integration.test.ts +1 -1
  58. package/src/services/__tests__/proof-verifier.test.ts +6 -3
  59. package/src/services/__tests__/tool-context-builder-authtype.test.ts +167 -0
  60. package/src/services/auth-type-satisfies.ts +134 -0
  61. package/src/services/oauth-config.service.ts +44 -1
  62. package/src/services/tool-context-builder.ts +64 -18
  63. package/src/__tests__/runtime/audit-logger.test.ts +0 -154
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Auth-Type Satisfaction Check
3
+ *
4
+ * Pure comparison used by the delegation-enforcement gate (security fix:
5
+ * consent-approve auth-gate, 2026-07-29, Task B3) to decide whether a
6
+ * delegation's authorization type satisfies a tool's required authorization
7
+ * type.
8
+ *
9
+ * Background: a gated MCP tool call is authorized by presenting a
10
+ * delegation. A bug let a delegation of ANY auth type satisfy a tool that
11
+ * requires a specific type — e.g. an anonymous consent-only (`none`)
12
+ * delegation wrongly satisfied a `password`-gated tool, because call-time
13
+ * enforcement accepted any present delegation without checking its
14
+ * `authorization.type`. This module implements the comparison that closes
15
+ * that gap. Wiring it into the enforcement sites (`agent.ts`,
16
+ * `tool-context-builder.ts`) is a later task (B3) — this module is
17
+ * intentionally standalone and unused by any gate yet.
18
+ *
19
+ * Decision (locked by product owner, 2026-07-29): STRICT NORMALIZED
20
+ * EQUALITY. A delegation type satisfies a required type iff, after folding
21
+ * deprecated aliases, they are equal. There is no "stronger satisfies
22
+ * weaker" lattice — `oauth`/`oauth2` and `password` are NOT interchangeable,
23
+ * and a `password` delegation does NOT satisfy a `none`-gated tool (or vice
24
+ * versa).
25
+ *
26
+ * @module @kya-os/mcp-i-runtime/services/auth-type-satisfies
27
+ */
28
+ /**
29
+ * Fold deprecated authorization-type aliases to their canonical form and
30
+ * normalize casing/whitespace.
31
+ *
32
+ * Alias rules mirror `normalizeAuthorizationType` in
33
+ * `packages/contracts/src/tool-protection/index.ts` (~774): `oauth` folds to
34
+ * `oauth2`, `credential` folds to `verifiable_credential`. That function
35
+ * operates on a full `AuthorizationRequirement` object and emits a
36
+ * deprecation warning on every call; this is a bare-string equivalent for
37
+ * use at the enforcement gate, where only the stored/required type strings
38
+ * — not the full requirement object — are available, and where a warning
39
+ * log on every tool call would be noise. (Not reusing the alias mapping
40
+ * directly from `@kya-os/contracts` here — it is not exposed as a
41
+ * standalone string-keyed map, only baked into that function's control
42
+ * flow — so the two rules are mirrored inline per the task's fallback
43
+ * guidance.)
44
+ *
45
+ * Canonical types (`AUTHORIZATION_TYPES`, contracts/src/tool-protection/index.ts
46
+ * ~88-106) are stored as lowercase string consts (e.g. "password", "oauth2",
47
+ * "none"), so normalization here only needs to trim and lowercase for
48
+ * defensive consistency — it does not need to handle differently-cased
49
+ * input from any known caller today.
50
+ *
51
+ * @param type - Raw authorization type string, or nullish if unknown/missing.
52
+ * @returns The normalized type string, or `undefined` if `type` is nullish or
53
+ * empty/whitespace-only after trimming.
54
+ */
55
+ export declare function normalizeAuthType(type: string | undefined | null): string | undefined;
56
+ /**
57
+ * Decide whether a delegation's authorization type satisfies a tool's
58
+ * required authorization type.
59
+ *
60
+ * Strict normalized equality (locked decision, see module docs above): both
61
+ * types are normalized (alias-folded, trimmed, lowercased) and then compared
62
+ * for exact equality. There is no cross-type satisfaction — a `password`
63
+ * delegation does NOT satisfy an `oauth2`-gated tool, and (by the same
64
+ * strict rule) does NOT satisfy a `none`-gated tool either.
65
+ *
66
+ * Note on `none`-required tools: per strict equality, only a `none`
67
+ * delegation satisfies a `none` requirement. In practice, a tool requiring
68
+ * `none` (consent-only) is not expected to reach this call today — it is
69
+ * rejected earlier, before the delegation-presence gate, by
70
+ * `ConsentOnlyModeError` (see `provider-resolver.ts`) — so this function is
71
+ * expected to be invoked only for TYPED requirements (`password`, `oauth2`,
72
+ * `apikey`, etc.). Strict equality is still implemented faithfully for
73
+ * `none` in case that assumption ever changes.
74
+ *
75
+ * Fail-safe rules (both nullish cases return `false`, never `true`):
76
+ * - If `delegationType` is nullish (missing on a legacy stored record that
77
+ * predates persisting `authorizationType`, or simply absent), this
78
+ * returns `false` regardless of `requiredType` — an unknown/unrecorded
79
+ * delegation type never satisfies a typed requirement.
80
+ * - If `requiredType` is nullish (or normalizes to empty), there is no
81
+ * requirement to compare against. Callers are not expected to invoke this
82
+ * with a nullish `requiredType` (a tool with no authorization requirement
83
+ * doesn't reach this gate), but this fails safe to `false` rather than
84
+ * treating "no requirement" as automatically satisfied.
85
+ *
86
+ * @param delegationType - The delegation's stored/asserted authorization
87
+ * type (e.g. from `getDelegationFromStorage`), or nullish if unknown.
88
+ * @param requiredType - The tool's required authorization type (e.g.
89
+ * `protection.authorization.type`), or nullish.
90
+ * @returns `true` iff both types are present and equal after normalization.
91
+ */
92
+ export declare function authTypeSatisfies(delegationType: string | undefined | null, requiredType: string | undefined | null): boolean;
93
+ //# sourceMappingURL=auth-type-satisfies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-type-satisfies.d.ts","sourceRoot":"","sources":["../../src/services/auth-type-satisfies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAC9B,MAAM,GAAG,SAAS,CAmBpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,iBAAiB,CAC/B,cAAc,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EACzC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GACtC,OAAO,CAgBT"}
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ /**
3
+ * Auth-Type Satisfaction Check
4
+ *
5
+ * Pure comparison used by the delegation-enforcement gate (security fix:
6
+ * consent-approve auth-gate, 2026-07-29, Task B3) to decide whether a
7
+ * delegation's authorization type satisfies a tool's required authorization
8
+ * type.
9
+ *
10
+ * Background: a gated MCP tool call is authorized by presenting a
11
+ * delegation. A bug let a delegation of ANY auth type satisfy a tool that
12
+ * requires a specific type — e.g. an anonymous consent-only (`none`)
13
+ * delegation wrongly satisfied a `password`-gated tool, because call-time
14
+ * enforcement accepted any present delegation without checking its
15
+ * `authorization.type`. This module implements the comparison that closes
16
+ * that gap. Wiring it into the enforcement sites (`agent.ts`,
17
+ * `tool-context-builder.ts`) is a later task (B3) — this module is
18
+ * intentionally standalone and unused by any gate yet.
19
+ *
20
+ * Decision (locked by product owner, 2026-07-29): STRICT NORMALIZED
21
+ * EQUALITY. A delegation type satisfies a required type iff, after folding
22
+ * deprecated aliases, they are equal. There is no "stronger satisfies
23
+ * weaker" lattice — `oauth`/`oauth2` and `password` are NOT interchangeable,
24
+ * and a `password` delegation does NOT satisfy a `none`-gated tool (or vice
25
+ * versa).
26
+ *
27
+ * @module @kya-os/mcp-i-runtime/services/auth-type-satisfies
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.normalizeAuthType = normalizeAuthType;
31
+ exports.authTypeSatisfies = authTypeSatisfies;
32
+ /**
33
+ * Fold deprecated authorization-type aliases to their canonical form and
34
+ * normalize casing/whitespace.
35
+ *
36
+ * Alias rules mirror `normalizeAuthorizationType` in
37
+ * `packages/contracts/src/tool-protection/index.ts` (~774): `oauth` folds to
38
+ * `oauth2`, `credential` folds to `verifiable_credential`. That function
39
+ * operates on a full `AuthorizationRequirement` object and emits a
40
+ * deprecation warning on every call; this is a bare-string equivalent for
41
+ * use at the enforcement gate, where only the stored/required type strings
42
+ * — not the full requirement object — are available, and where a warning
43
+ * log on every tool call would be noise. (Not reusing the alias mapping
44
+ * directly from `@kya-os/contracts` here — it is not exposed as a
45
+ * standalone string-keyed map, only baked into that function's control
46
+ * flow — so the two rules are mirrored inline per the task's fallback
47
+ * guidance.)
48
+ *
49
+ * Canonical types (`AUTHORIZATION_TYPES`, contracts/src/tool-protection/index.ts
50
+ * ~88-106) are stored as lowercase string consts (e.g. "password", "oauth2",
51
+ * "none"), so normalization here only needs to trim and lowercase for
52
+ * defensive consistency — it does not need to handle differently-cased
53
+ * input from any known caller today.
54
+ *
55
+ * @param type - Raw authorization type string, or nullish if unknown/missing.
56
+ * @returns The normalized type string, or `undefined` if `type` is nullish or
57
+ * empty/whitespace-only after trimming.
58
+ */
59
+ function normalizeAuthType(type) {
60
+ if (type === undefined || type === null) {
61
+ return undefined;
62
+ }
63
+ const trimmed = type.trim().toLowerCase();
64
+ if (trimmed === "") {
65
+ return undefined;
66
+ }
67
+ // Deprecated alias -> canonical (mirrors normalizeAuthorizationType).
68
+ if (trimmed === "oauth") {
69
+ return "oauth2";
70
+ }
71
+ if (trimmed === "credential") {
72
+ return "verifiable_credential";
73
+ }
74
+ return trimmed;
75
+ }
76
+ /**
77
+ * Decide whether a delegation's authorization type satisfies a tool's
78
+ * required authorization type.
79
+ *
80
+ * Strict normalized equality (locked decision, see module docs above): both
81
+ * types are normalized (alias-folded, trimmed, lowercased) and then compared
82
+ * for exact equality. There is no cross-type satisfaction — a `password`
83
+ * delegation does NOT satisfy an `oauth2`-gated tool, and (by the same
84
+ * strict rule) does NOT satisfy a `none`-gated tool either.
85
+ *
86
+ * Note on `none`-required tools: per strict equality, only a `none`
87
+ * delegation satisfies a `none` requirement. In practice, a tool requiring
88
+ * `none` (consent-only) is not expected to reach this call today — it is
89
+ * rejected earlier, before the delegation-presence gate, by
90
+ * `ConsentOnlyModeError` (see `provider-resolver.ts`) — so this function is
91
+ * expected to be invoked only for TYPED requirements (`password`, `oauth2`,
92
+ * `apikey`, etc.). Strict equality is still implemented faithfully for
93
+ * `none` in case that assumption ever changes.
94
+ *
95
+ * Fail-safe rules (both nullish cases return `false`, never `true`):
96
+ * - If `delegationType` is nullish (missing on a legacy stored record that
97
+ * predates persisting `authorizationType`, or simply absent), this
98
+ * returns `false` regardless of `requiredType` — an unknown/unrecorded
99
+ * delegation type never satisfies a typed requirement.
100
+ * - If `requiredType` is nullish (or normalizes to empty), there is no
101
+ * requirement to compare against. Callers are not expected to invoke this
102
+ * with a nullish `requiredType` (a tool with no authorization requirement
103
+ * doesn't reach this gate), but this fails safe to `false` rather than
104
+ * treating "no requirement" as automatically satisfied.
105
+ *
106
+ * @param delegationType - The delegation's stored/asserted authorization
107
+ * type (e.g. from `getDelegationFromStorage`), or nullish if unknown.
108
+ * @param requiredType - The tool's required authorization type (e.g.
109
+ * `protection.authorization.type`), or nullish.
110
+ * @returns `true` iff both types are present and equal after normalization.
111
+ */
112
+ function authTypeSatisfies(delegationType, requiredType) {
113
+ const normalizedDelegationType = normalizeAuthType(delegationType);
114
+ if (normalizedDelegationType === undefined) {
115
+ // Fail-safe: an unknown/missing delegation type never satisfies a
116
+ // requirement, typed or not.
117
+ return false;
118
+ }
119
+ const normalizedRequiredType = normalizeAuthType(requiredType);
120
+ if (normalizedRequiredType === undefined) {
121
+ // Fail-safe: no requirement to satisfy is not treated as "anything
122
+ // satisfies it".
123
+ return false;
124
+ }
125
+ return normalizedDelegationType === normalizedRequiredType;
126
+ }
127
+ //# sourceMappingURL=auth-type-satisfies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-type-satisfies.js","sourceRoot":"","sources":["../../src/services/auth-type-satisfies.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;AA6BH,8CAqBC;AAsCD,8CAmBC;AAzGD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,iBAAiB,CAC/B,IAA+B;IAE/B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACxC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC1C,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QACnB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,sEAAsE;IACtE,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,OAAO,KAAK,YAAY,EAAE,CAAC;QAC7B,OAAO,uBAAuB,CAAC;IACjC,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,SAAgB,iBAAiB,CAC/B,cAAyC,EACzC,YAAuC;IAEvC,MAAM,wBAAwB,GAAG,iBAAiB,CAAC,cAAc,CAAC,CAAC;IACnE,IAAI,wBAAwB,KAAK,SAAS,EAAE,CAAC;QAC3C,kEAAkE;QAClE,6BAA6B;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,sBAAsB,GAAG,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAC/D,IAAI,sBAAsB,KAAK,SAAS,EAAE,CAAC;QACzC,mEAAmE;QACnE,iBAAiB;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,wBAAwB,KAAK,sBAAsB,CAAC;AAC7D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-config.service.d.ts","sourceRoot":"","sources":["../../src/services/oauth-config.service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAGvE,MAAM,WAAW,wBAAwB;IACvC,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAEhB,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IAEf,8CAA8C;IAC9C,aAAa,EAAE,aAAa,CAAC;IAE7B,mDAAmD;IACnD,KAAK,CAAC,EAAE,gBAAgB,CAAC;IAEzB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACpD;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAGZ;gBAEU,MAAM,EAAE,wBAAwB;IAW5C;;;;;;;;OAQG;IACG,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IA8G7D;;;;OAIG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlD;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CAIrC"}
1
+ {"version":3,"file":"oauth-config.service.d.ts","sourceRoot":"","sources":["../../src/services/oauth-config.service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EACV,WAAW,EAGZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAiCvE,MAAM,WAAW,wBAAwB;IACvC,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAEhB,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IAEf,8CAA8C;IAC9C,aAAa,EAAE,aAAa,CAAC;IAE7B,mDAAmD;IACnD,KAAK,CAAC,EAAE,gBAAgB,CAAC;IAEzB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACpD;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAGZ;gBAEU,MAAM,EAAE,wBAAwB;IAW5C;;;;;;;;OAQG;IACG,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAuH7D;;;;OAIG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlD;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CAIrC"}
@@ -10,6 +10,26 @@
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.OAuthConfigService = void 0;
12
12
  const oauth_config_cache_js_1 = require("../cache/oauth-config-cache.js");
13
+ /**
14
+ * Normalize a provider's secret-reference metadata from the AgentShield
15
+ * `/providers` response into the OAuthProvider `metadata` shape.
16
+ *
17
+ * The response may use camelCase or snake_case; only the secret-*name*
18
+ * references are carried (never the secret values). Returns `undefined` when
19
+ * no metadata is present so the field stays absent on the parsed provider.
20
+ */
21
+ function mapProviderSecretMetadata(raw) {
22
+ if (!raw || typeof raw !== "object")
23
+ return undefined;
24
+ const m = raw;
25
+ const metadata = {
26
+ clientSecretName: (m.clientSecretName ?? m.client_secret_name),
27
+ clientIdSecretName: (m.clientIdSecretName ?? m.client_id_secret_name),
28
+ apiKeySecretName: (m.apiKeySecretName ?? m.api_key_secret_name),
29
+ clientSecretVersion: (m.clientSecretVersion ?? m.client_secret_version),
30
+ };
31
+ return metadata;
32
+ }
13
33
  /**
14
34
  * Service for fetching OAuth provider configurations from AgentShield API
15
35
  */
@@ -91,6 +111,15 @@ class OAuthConfigService {
91
111
  tokenEndpointAuthMethod: (p.tokenEndpointAuthMethod ?? p.token_endpoint_auth_method),
92
112
  responseType: (p.responseType ?? p.response_type),
93
113
  grantType: (p.grantType ?? p.grant_type),
114
+ // Provider-registry secret metadata (clientSecretName etc.). REQUIRED:
115
+ // OAuthService.resolveClientSecret resolves a confidential provider's
116
+ // client secret from secure storage via `metadata.clientSecretName`
117
+ // (the AgentShield /providers response intentionally omits the plaintext
118
+ // `clientSecret`). Without mapping this field here, `metadata` is
119
+ // undefined, resolveClientSecret falls back to the (absent) inline
120
+ // clientSecret, and the worker sends an empty secret — token exchange
121
+ // then fails with "client_id and/or client_secret incorrect".
122
+ metadata: mapProviderSecretMetadata(p.metadata),
94
123
  };
95
124
  }
96
125
  // Build OAuthConfig object
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-config.service.js","sourceRoot":"","sources":["../../src/services/oauth-config.service.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAKH,0EAA0E;AAsB1E;;GAEG;AACH,MAAa,kBAAkB;IACrB,MAAM,CAGZ;IAEF,YAAY,MAAgC;QAC1C,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,oBAAoB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,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU,CAAC,SAAiB;QAChC,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,oCAAoC,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa;QACjB,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,wCAAwC,CAAC,CAAC;IAC/D,CAAC;CACF;AAlKD,gDAkKC"}
@@ -44,9 +44,14 @@ export declare class ToolContextBuilder {
44
44
  * @param sessionId - Session ID (optional)
45
45
  * @param delegationToken - Delegation token (optional)
46
46
  * @param toolProtection - Tool protection configuration (optional)
47
+ * @param delegationAuthorizationType - The stored authorization type of the
48
+ * presented delegation (from `getDelegationFromStorage`), or undefined for
49
+ * legacy records that predate persisting it. Used by the delegation-only
50
+ * fallback below to reject a delegation whose type does not satisfy the
51
+ * tool's required type (security fix: consent-approve auth-gate, Task B3).
47
52
  * @returns Tool execution context or undefined if not needed
48
53
  */
49
- buildContext(toolName: string, userDid: string | undefined, sessionId: string | undefined, delegationToken: string | undefined, toolProtection: ToolProtection | null): Promise<ToolExecutionContext | undefined>;
54
+ buildContext(toolName: string, userDid: string | undefined, sessionId: string | undefined, delegationToken: string | undefined, toolProtection: ToolProtection | null, delegationAuthorizationType?: string): Promise<ToolExecutionContext | undefined>;
50
55
  /**
51
56
  * Build authentication headers based on token usage metadata (CRED-003)
52
57
  *
@@ -1 +1 @@
1
- {"version":3,"file":"tool-context-builder.d.ts","sourceRoot":"","sources":["../../src/services/tool-context-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE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B,EAAE,MAAM,mCAAmC,CAAC;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAQ/D,MAAM,WAAW,wBAAwB;IACvC,4DAA4D;IAC5D,aAAa,EAAE,gBAAgB,CAAC;IAEhC,gEAAgE;IAChE,aAAa,EAAE,kBAAkB,CAAC;IAElC,gEAAgE;IAChE,gBAAgB,EAAE,gBAAgB,CAAC;IAEnC,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;IAElB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACpD;AAED;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAEZ;gBAEU,MAAM,EAAE,wBAAwB;IAU5C;;;;;;;;;;;;;;OAcG;IACG,YAAY,CAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,eAAe,EAAE,MAAM,GAAG,SAAS,EACnC,cAAc,EAAE,cAAc,GAAG,IAAI,EACrC,2BAA2B,CAAC,EAAE,MAAM,GACnC,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IA8J5C;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,gBAAgB;IA2CxB;;;;;;;OAOG;YACW,eAAe;CAsB9B"}
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.ToolContextBuilder = void 0;
15
15
  const oauth_required_error_js_1 = require("../types/oauth-required-error.js");
16
16
  const provider_resolver_js_1 = require("./provider-resolver.js");
17
+ const auth_type_satisfies_js_1 = require("./auth-type-satisfies.js");
17
18
  /**
18
19
  * Builder for tool execution context
19
20
  *
@@ -40,9 +41,14 @@ class ToolContextBuilder {
40
41
  * @param sessionId - Session ID (optional)
41
42
  * @param delegationToken - Delegation token (optional)
42
43
  * @param toolProtection - Tool protection configuration (optional)
44
+ * @param delegationAuthorizationType - The stored authorization type of the
45
+ * presented delegation (from `getDelegationFromStorage`), or undefined for
46
+ * legacy records that predate persisting it. Used by the delegation-only
47
+ * fallback below to reject a delegation whose type does not satisfy the
48
+ * tool's required type (security fix: consent-approve auth-gate, Task B3).
43
49
  * @returns Tool execution context or undefined if not needed
44
50
  */
45
- async buildContext(toolName, userDid, sessionId, delegationToken, toolProtection) {
51
+ async buildContext(toolName, userDid, sessionId, delegationToken, toolProtection, delegationAuthorizationType) {
46
52
  // Only build context if tool requires OAuth/credentials
47
53
  if (!toolProtection?.requiredScopes?.length || !userDid) {
48
54
  return undefined;
@@ -80,7 +86,22 @@ class ToolContextBuilder {
80
86
  // IDP token not available - check if delegation token exists
81
87
  // If delegation exists, tool can still execute without IDP token
82
88
  // (the tool handler should check for idpToken if it needs external API access)
83
- if (delegationToken) {
89
+ //
90
+ // SECURITY (consent-approve auth-gate, Task B3): a delegation only
91
+ // authorizes this tool if its OWN authorization type satisfies the tool's
92
+ // required type. Reaching this OAuth context builder means the tool is
93
+ // neither consent-only (`none`) nor password — those throw
94
+ // ConsentOnlyModeError / CredentialAuthModeError inside resolveProvider,
95
+ // BEFORE this point — so the effective requirement is OAuth. Fall back to
96
+ // "oauth2" only when the tool omits an explicit authorization.type (legacy
97
+ // oauthProvider-only config); this keeps such tools working while a
98
+ // mismatched delegation (e.g. an anonymous `none` consent-only delegation,
99
+ // or a legacy record with no persisted type → undefined) is rejected. On
100
+ // mismatch we do NOT return the delegation-only context; we fall through
101
+ // to OAuthRequiredError so the tool re-challenges.
102
+ const requiredAuthType = toolProtection.authorization?.type ?? "oauth2";
103
+ if (delegationToken &&
104
+ (0, auth_type_satisfies_js_1.authTypeSatisfies)(delegationAuthorizationType, requiredAuthType)) {
84
105
  this.config.logger("[ToolContextBuilder] IDP token not found, but delegation exists - returning minimal context", {
85
106
  toolName,
86
107
  userDid: userDid.substring(0, 20) + "...",
@@ -98,7 +119,18 @@ class ToolContextBuilder {
98
119
  delegationToken,
99
120
  };
100
121
  }
101
- // No delegation token either - throw OAuthRequiredError to trigger auth flow
122
+ if (delegationToken) {
123
+ // A delegation WAS presented but its authorization type does not satisfy
124
+ // the tool's required type — log and re-challenge instead of authorizing.
125
+ this.config.logger("[ToolContextBuilder] Delegation present but auth-type does not satisfy tool requirement - re-challenging", {
126
+ toolName,
127
+ userDid: userDid.substring(0, 20) + "...",
128
+ provider,
129
+ requiredAuthType,
130
+ delegationAuthorizationType: delegationAuthorizationType ?? null,
131
+ });
132
+ }
133
+ // No (satisfying) delegation token - throw OAuthRequiredError to trigger auth flow
102
134
  this.config.logger("[ToolContextBuilder] Token not available, throwing OAuthRequiredError", {
103
135
  toolName,
104
136
  userDid: userDid.substring(0, 20) + "...",
@@ -1 +1 @@
1
- {"version":3,"file":"tool-context-builder.js","sourceRoot":"","sources":["../../src/services/tool-context-builder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAQH,8EAAsE;AACtE,iEAGgC;AAmBhC;;;;;;GAMG;AACH,MAAa,kBAAkB;IACrB,MAAM,CAEZ;IAEF,YAAY,MAAgC;QAC1C,IAAI,CAAC,MAAM,GAAG;YACZ,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;YACzC,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;SACpC,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,YAAY,CAChB,QAAgB,EAChB,OAA2B,EAC3B,SAA6B,EAC7B,eAAmC,EACnC,cA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CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,wCAAwC,EAAE;gBAC3D,QAAQ;aACT,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,iDAAiD,EAAE;gBACpE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC7D,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;aACjC,CAAC,CAAC;YACH,MAAM,KAAK,CAAC,CAAC,gCAAgC;QAC/C,CAAC;IACH,CAAC;CACF;AAzRD,gDAyRC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kya-os/mcp-i-runtime",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Shared product-runtime layer for the MCP-I framework (Node + Cloudflare adapters). Protocol types/values live in @kya-os/mcp (DIF).",
5
5
  "license": "MIT",
6
6
  "author": "Dylan Hobbs",
@@ -24,6 +24,10 @@
24
24
  "types": "./dist/runtime/audit-logger.d.ts",
25
25
  "default": "./dist/runtime/audit-logger.js"
26
26
  },
27
+ "./runtime/audit": {
28
+ "types": "./dist/runtime/audit.d.ts",
29
+ "default": "./dist/runtime/audit.js"
30
+ },
27
31
  "./runtime/ext-apps-constants": {
28
32
  "types": "./dist/runtime/ext-apps-constants.d.ts",
29
33
  "default": "./dist/runtime/ext-apps-constants.js"
@@ -55,8 +59,8 @@
55
59
  "prepublishOnly": "npm run build && node ../create-mcpi-app/scripts/validate-no-workspace.js"
56
60
  },
57
61
  "dependencies": {
58
- "@kya-os/contracts": "^1.8.0",
59
- "@kya-os/mcp": "^1.6.1",
62
+ "@kya-os/contracts": "^1.10.0",
63
+ "@kya-os/mcp": "1.11.0",
60
64
  "jose": "^5.6.3",
61
65
  "json-canonicalize": "^2.0.0",
62
66
  "zod": "^3.25.67"
@@ -241,10 +241,6 @@ describe('ProviderRuntimeConfig', () => {
241
241
  apiKey: 'as-key',
242
242
  },
243
243
  },
244
- audit: {
245
- enabled: true,
246
- includeProofHashes: false,
247
- },
248
244
  wellKnown: {
249
245
  enabled: true,
250
246
  serviceName: 'Test Service',
@@ -257,7 +253,7 @@ describe('ProviderRuntimeConfig', () => {
257
253
  expect(config.proofing?.enabled).toBe(true);
258
254
  expect(config.delegation?.enabled).toBe(true);
259
255
  expect(config.toolProtection?.source).toBe('agentshield');
260
- expect(config.audit?.enabled).toBe(true);
256
+ expect(config).not.toHaveProperty('audit');
261
257
  expect(config.wellKnown?.enabled).toBe(true);
262
258
  });
263
259
  });
@@ -272,9 +268,6 @@ describe('ProviderRuntimeConfig', () => {
272
268
  storageProvider: mockStorageProvider,
273
269
  nonceCacheProvider: mockNonceCacheProvider,
274
270
  identityProvider: mockIdentityProvider,
275
- audit: {
276
- enabled: true,
277
- },
278
271
  wellKnown: {
279
272
  enabled: true,
280
273
  },
@@ -282,7 +275,7 @@ describe('ProviderRuntimeConfig', () => {
282
275
 
283
276
  // MCPIBaseConfig fields should be available
284
277
  expect(config.environment).toBeDefined();
285
- expect(config.audit).toBeDefined();
278
+ expect(config).not.toHaveProperty('audit');
286
279
  expect(config.wellKnown).toBeDefined();
287
280
  });
288
281
 
@@ -22,6 +22,7 @@ import type {
22
22
  IdentityProvider,
23
23
  } from "../providers/base";
24
24
  import type { ToolProtectionService } from "../services/tool-protection.service";
25
+ import type { RuntimeAuditConfig } from "../runtime/audit";
25
26
 
26
27
  describe("ProviderRuntimeConfigBuilder", () => {
27
28
  // Create mock providers
@@ -194,19 +195,21 @@ describe("ProviderRuntimeConfigBuilder", () => {
194
195
  });
195
196
  });
196
197
 
197
- describe("withAudit", () => {
198
- it("should set audit config", () => {
198
+ describe("withAuditTrail", () => {
199
+ it("should set the canonical audit trail without a diagnostic logger", () => {
199
200
  const providers = createMockProviders();
201
+ const auditTrail = {
202
+ trail: { record: vi.fn() },
203
+ context: { create: vi.fn() },
204
+ sourceId: "deployment:test",
205
+ } as unknown as RuntimeAuditConfig;
200
206
  const config = new ProviderRuntimeConfigBuilder()
201
207
  .withProviders(providers)
202
- .withAudit({
203
- enabled: true,
204
- includeProofHashes: true,
205
- })
208
+ .withAuditTrail(auditTrail)
206
209
  .build();
207
210
 
208
- expect(config.audit?.enabled).toBe(true);
209
- expect(config.audit?.includeProofHashes).toBe(true);
211
+ expect(config.auditTrail).toBe(auditTrail);
212
+ expect(config).not.toHaveProperty("audit");
210
213
  });
211
214
  });
212
215
 
@@ -250,12 +253,11 @@ describe("ProviderRuntimeConfigBuilder", () => {
250
253
  .withProviders(providers)
251
254
  .withEnvironment("production")
252
255
  .withSession({ ttlMinutes: 60 })
253
- .withAudit({ enabled: true })
254
256
  .build();
255
257
 
256
258
  expect(config.environment).toBe("production");
257
259
  expect(config.session?.ttlMinutes).toBe(60);
258
- expect(config.audit?.enabled).toBe(true);
260
+ expect(config).not.toHaveProperty("audit");
259
261
  });
260
262
  });
261
263
  });
@@ -304,4 +306,3 @@ describe("createProviderRuntimeConfig", () => {
304
306
 
305
307
 
306
308
 
307
-
@@ -104,11 +104,6 @@ describe("Full Flow Integration", () => {
104
104
  timestampSkewSeconds: 120,
105
105
  ttlMinutes: 30,
106
106
  },
107
- audit: {
108
- enabled: true,
109
- logFunction: vi.fn(),
110
- includePayloads: true,
111
- },
112
107
  toolProtection: {
113
108
  source: "agentshield",
114
109
  agentShield: {
@@ -33,11 +33,7 @@ describe('Integration Tests', () => {
33
33
  identityProvider: new MemoryIdentityProvider(cryptoProvider),
34
34
  environment: 'development',
35
35
  timestampSkewSeconds: 120,
36
- sessionTtlMinutes: 30,
37
- audit: {
38
- enabled: true,
39
- includePayloads: true
40
- }
36
+ sessionTtlMinutes: 30
41
37
  });
42
38
 
43
39
  await runtime.initialize();
@@ -278,4 +274,4 @@ describe('Integration Tests', () => {
278
274
  expect(debugEndpoint).toBeNull();
279
275
  });
280
276
  });
281
- });
277
+ });