@kya-os/mcp-i-runtime 1.2.4 → 1.2.6
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/.turbo/turbo-build.log +1 -1
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/config/remote-config.d.ts +3 -3
- package/dist/config/remote-config.js +4 -4
- package/dist/config/remote-config.js.map +1 -1
- package/dist/identity/user-did-manager.d.ts +4 -4
- package/dist/identity/user-did-manager.js +5 -5
- package/dist/identity/user-did-manager.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/runtime/audit.d.ts.map +1 -1
- package/dist/runtime/audit.js +22 -0
- package/dist/runtime/audit.js.map +1 -1
- package/dist/runtime/base.d.ts +17 -11
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +58 -28
- package/dist/runtime/base.js.map +1 -1
- package/dist/runtime/delegation-denial.d.ts +43 -0
- package/dist/runtime/delegation-denial.d.ts.map +1 -0
- package/dist/runtime/delegation-denial.js +83 -0
- package/dist/runtime/delegation-denial.js.map +1 -0
- package/dist/runtime/verified-delegation.d.ts +30 -0
- package/dist/runtime/verified-delegation.d.ts.map +1 -0
- package/dist/runtime/verified-delegation.js +62 -0
- package/dist/runtime/verified-delegation.js.map +1 -0
- package/dist/services/access-control.service.d.ts +2 -2
- package/dist/services/access-control.service.js +4 -4
- package/dist/services/access-control.service.js.map +1 -1
- package/dist/services/delegation-error-formatter.d.ts +15 -0
- package/dist/services/delegation-error-formatter.d.ts.map +1 -1
- package/dist/services/delegation-error-formatter.js +27 -1
- package/dist/services/delegation-error-formatter.js.map +1 -1
- package/dist/services/oauth-config.service.d.ts +4 -4
- package/dist/services/oauth-config.service.d.ts.map +1 -1
- package/dist/services/oauth-config.service.js +8 -8
- package/dist/services/oauth-config.service.js.map +1 -1
- package/dist/services/oauth-provider-registry.d.ts +3 -3
- package/dist/services/oauth-provider-registry.js +4 -4
- package/dist/services/oauth-provider-registry.js.map +1 -1
- package/dist/services/oauth-service.d.ts +8 -8
- package/dist/services/oauth-service.d.ts.map +1 -1
- package/dist/services/oauth-service.js +8 -8
- package/dist/services/oauth-service.js.map +1 -1
- package/dist/services/oauth-token-retrieval.service.d.ts +6 -6
- package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -1
- package/dist/services/oauth-token-retrieval.service.js +5 -5
- package/dist/services/provider-resolver.d.ts +1 -1
- package/dist/services/provider-resolver.js +4 -4
- package/dist/services/provider-resolver.js.map +1 -1
- package/dist/services/session-registration.service.d.ts +4 -4
- package/dist/services/session-registration.service.d.ts.map +1 -1
- package/dist/services/session-registration.service.js +5 -5
- package/dist/services/session-registration.service.js.map +1 -1
- package/dist/services/tool-protection.service.d.ts +13 -13
- package/dist/services/tool-protection.service.js +16 -16
- package/dist/services/tool-protection.service.js.map +1 -1
- package/dist/types/tool-protection.d.ts +11 -4
- package/dist/types/tool-protection.d.ts.map +1 -1
- package/dist/types/tool-protection.js +8 -1
- package/dist/types/tool-protection.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/index.test.ts +12 -0
- package/src/__tests__/integration/full-flow.test.ts +3 -3
- package/src/__tests__/runtime/audit-contracts-compat.test.ts +54 -0
- package/src/__tests__/runtime/audit.test.ts +172 -0
- package/src/__tests__/runtime/delegation-denial.test.ts +115 -0
- package/src/__tests__/runtime/native-holder-enforcement.test.ts +107 -0
- package/src/__tests__/runtime/process-tool-call-security.test.ts +323 -6
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +40 -42
- package/src/__tests__/runtime/verified-delegation.test.ts +129 -0
- package/src/__tests__/services/agentshield-integration.test.ts +3 -3
- package/src/__tests__/services/oauth-service-secret-resolution.test.ts +1 -1
- package/src/__tests__/services/provider-resolver-edge-cases.test.ts +2 -2
- package/src/__tests__/services/tool-protection.service.test.ts +1 -1
- package/src/__tests__/utils/tool-protection-runtime.ts +25 -0
- package/src/auth/types.ts +1 -1
- package/src/config/remote-config.ts +4 -4
- package/src/identity/user-did-manager.ts +5 -5
- package/src/index.ts +15 -0
- package/src/runtime/audit.ts +26 -0
- package/src/runtime/base.ts +76 -31
- package/src/runtime/delegation-denial.ts +107 -0
- package/src/runtime/verified-delegation.ts +66 -0
- package/src/services/__tests__/access-control.proof-response-validation.test.ts +8 -8
- package/src/services/__tests__/delegation-error-formatter.test.ts +156 -0
- package/src/services/__tests__/oauth-config.service.test.ts +2 -2
- package/src/services/__tests__/oauth-provider-registry.test.ts +1 -1
- package/src/services/__tests__/storage.service.test.ts +21 -16
- package/src/services/access-control.service.ts +4 -4
- package/src/services/delegation-error-formatter.ts +42 -1
- package/src/services/oauth-config.service.d.ts +4 -4
- package/src/services/oauth-config.service.ts +9 -9
- package/src/services/oauth-provider-registry.d.ts +2 -2
- package/src/services/oauth-provider-registry.ts +4 -4
- package/src/services/oauth-service.ts +10 -10
- package/src/services/oauth-token-retrieval.service.ts +8 -8
- package/src/services/provider-resolver.ts +4 -4
- package/src/services/session-registration.service.ts +6 -6
- package/src/services/tool-protection.service.ts +17 -17
- package/src/types/tool-protection.ts +13 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* OAuth Config Service
|
|
3
3
|
*
|
|
4
|
-
* Fetches and caches OAuth provider configurations from
|
|
4
|
+
* Fetches and caches OAuth provider configurations from Checkpoint API.
|
|
5
5
|
* Provides caching with TTL to reduce API calls.
|
|
6
6
|
*
|
|
7
7
|
* @package @kya-os/mcp-i-core
|
|
@@ -17,7 +17,7 @@ import type { OAuthConfigCache } from "../cache/oauth-config-cache.js";
|
|
|
17
17
|
import { InMemoryOAuthConfigCache } from "../cache/oauth-config-cache.js";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Normalize a provider's secret-reference metadata from the
|
|
20
|
+
* Normalize a provider's secret-reference metadata from the Checkpoint
|
|
21
21
|
* `/providers` response into the OAuthProvider `metadata` shape.
|
|
22
22
|
*
|
|
23
23
|
* The response may use camelCase or snake_case; only the secret-*name*
|
|
@@ -47,7 +47,7 @@ function mapProviderSecretMetadata(
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
export interface OAuthConfigServiceConfig {
|
|
50
|
-
/** Base URL for
|
|
50
|
+
/** Base URL for Checkpoint API (e.g., "https://kya.vouched.id") */
|
|
51
51
|
baseUrl: string;
|
|
52
52
|
|
|
53
53
|
/** API key for authentication */
|
|
@@ -67,7 +67,7 @@ export interface OAuthConfigServiceConfig {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
* Service for fetching OAuth provider configurations from
|
|
70
|
+
* Service for fetching OAuth provider configurations from Checkpoint API
|
|
71
71
|
*/
|
|
72
72
|
export class OAuthConfigService {
|
|
73
73
|
private config: Required<Omit<OAuthConfigServiceConfig, "logger" | "cache">> & {
|
|
@@ -89,7 +89,7 @@ export class OAuthConfigService {
|
|
|
89
89
|
/**
|
|
90
90
|
* Get OAuth configuration for a project
|
|
91
91
|
*
|
|
92
|
-
* Fetches from
|
|
92
|
+
* Fetches from Checkpoint API: GET /api/v1/bouncer/projects/{projectId}/providers
|
|
93
93
|
* Caches responses with TTL to reduce API calls.
|
|
94
94
|
*
|
|
95
95
|
* @param projectId - Project ID to fetch config for
|
|
@@ -105,7 +105,7 @@ export class OAuthConfigService {
|
|
|
105
105
|
return cached;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
// Fetch from
|
|
108
|
+
// Fetch from Checkpoint API
|
|
109
109
|
const url = `${this.config.baseUrl}/api/v1/bouncer/projects/${encodeURIComponent(projectId)}/providers`;
|
|
110
110
|
|
|
111
111
|
this.config.logger("[OAuthConfigService] Fetching config from API", {
|
|
@@ -143,7 +143,7 @@ export class OAuthConfigService {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
// Parse providers object with snake_case → camelCase mapping
|
|
146
|
-
//
|
|
146
|
+
// Checkpoint API may return snake_case fields, but OAuthProvider interface uses camelCase
|
|
147
147
|
const rawProviders = result.data.providers || {};
|
|
148
148
|
if (typeof rawProviders !== "object" || Array.isArray(rawProviders)) {
|
|
149
149
|
throw new Error(
|
|
@@ -173,7 +173,7 @@ export class OAuthConfigService {
|
|
|
173
173
|
// Provider-registry secret metadata (clientSecretName etc.). REQUIRED:
|
|
174
174
|
// OAuthService.resolveClientSecret resolves a confidential provider's
|
|
175
175
|
// client secret from secure storage via `metadata.clientSecretName`
|
|
176
|
-
// (the
|
|
176
|
+
// (the Checkpoint /providers response intentionally omits the plaintext
|
|
177
177
|
// `clientSecret`). Without mapping this field here, `metadata` is
|
|
178
178
|
// undefined, resolveClientSecret falls back to the (absent) inline
|
|
179
179
|
// clientSecret, and the worker sends an empty secret — token exchange
|
|
@@ -184,7 +184,7 @@ export class OAuthConfigService {
|
|
|
184
184
|
|
|
185
185
|
// Build OAuthConfig object
|
|
186
186
|
// Extract configuredProvider from API response - this indicates which provider
|
|
187
|
-
// the user has actually configured in
|
|
187
|
+
// the user has actually configured in Checkpoint dashboard
|
|
188
188
|
const configuredProvider = result.data.configuredProvider ?? (result.data as any).configured_provider ?? null;
|
|
189
189
|
const config: OAuthConfig = {
|
|
190
190
|
providers,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* OAuth Provider Registry
|
|
3
3
|
*
|
|
4
|
-
* Manages OAuth provider configurations loaded from
|
|
4
|
+
* Manages OAuth provider configurations loaded from Checkpoint API.
|
|
5
5
|
* Provides efficient lookup and caching of provider configurations.
|
|
6
6
|
*
|
|
7
7
|
* @package @kya-os/mcp-i-core
|
|
@@ -19,7 +19,7 @@ export declare class OAuthProviderRegistry {
|
|
|
19
19
|
private providers;
|
|
20
20
|
constructor(configService: OAuthConfigService);
|
|
21
21
|
/**
|
|
22
|
-
* Load providers from
|
|
22
|
+
* Load providers from Checkpoint API
|
|
23
23
|
*
|
|
24
24
|
* Fetches OAuth configuration and caches providers in memory.
|
|
25
25
|
* Clears existing providers before loading new ones.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* OAuth Provider Registry
|
|
3
3
|
*
|
|
4
|
-
* Manages OAuth provider configurations loaded from
|
|
4
|
+
* Manages OAuth provider configurations loaded from Checkpoint API.
|
|
5
5
|
* Provides efficient lookup and caching of provider configurations.
|
|
6
6
|
*
|
|
7
7
|
* @package @kya-os/mcp-i-core
|
|
@@ -27,7 +27,7 @@ export class OAuthProviderRegistry {
|
|
|
27
27
|
) {}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* Load providers from
|
|
30
|
+
* Load providers from Checkpoint API
|
|
31
31
|
*
|
|
32
32
|
* Fetches OAuth configuration and caches providers in memory.
|
|
33
33
|
* Clears existing providers before loading new ones.
|
|
@@ -42,7 +42,7 @@ export class OAuthProviderRegistry {
|
|
|
42
42
|
this.providers.clear();
|
|
43
43
|
|
|
44
44
|
// Store the configured provider from API response
|
|
45
|
-
// This is the provider the user has explicitly configured in
|
|
45
|
+
// This is the provider the user has explicitly configured in Checkpoint dashboard
|
|
46
46
|
this._configuredProvider = config.configuredProvider || null;
|
|
47
47
|
|
|
48
48
|
// Register all providers from config
|
|
@@ -54,7 +54,7 @@ export class OAuthProviderRegistry {
|
|
|
54
54
|
/**
|
|
55
55
|
* Get the explicitly configured provider for this project
|
|
56
56
|
*
|
|
57
|
-
* Returns the provider that the user has configured in
|
|
57
|
+
* Returns the provider that the user has configured in Checkpoint dashboard.
|
|
58
58
|
* Used by ProviderResolver as fallback when tool doesn't specify oauthProvider.
|
|
59
59
|
*
|
|
60
60
|
* @returns Configured provider name, or null if no provider is configured
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* OAuth Service
|
|
3
3
|
*
|
|
4
4
|
* Handles OAuth token exchange and refresh using PKCE (Proof Key for Code Exchange).
|
|
5
|
-
* Supports both direct PKCE exchange with OAuth providers and proxy mode via
|
|
5
|
+
* Supports both direct PKCE exchange with OAuth providers and proxy mode via Checkpoint.
|
|
6
6
|
*
|
|
7
7
|
* MCP-I Provider Registry Model:
|
|
8
8
|
* - Client secrets are NOT sent via the API response
|
|
9
|
-
* - Agents receive metadata.clientSecretName from
|
|
9
|
+
* - Agents receive metadata.clientSecretName from Checkpoint
|
|
10
10
|
* - Secrets are resolved at runtime from secure storage (Cloudflare Worker env)
|
|
11
11
|
* - The SecretResolver interface enables platform-specific secret resolution
|
|
12
12
|
*
|
|
@@ -56,10 +56,10 @@ export interface OAuthServiceConfig {
|
|
|
56
56
|
/** Fetch provider for making HTTP requests */
|
|
57
57
|
fetchProvider: FetchProvider;
|
|
58
58
|
|
|
59
|
-
/**
|
|
59
|
+
/** Checkpoint API URL (for proxy mode) */
|
|
60
60
|
agentShieldApiUrl: string;
|
|
61
61
|
|
|
62
|
-
/**
|
|
62
|
+
/** Checkpoint API key (for proxy mode) */
|
|
63
63
|
agentShieldApiKey: string;
|
|
64
64
|
|
|
65
65
|
/** Project ID for fetching OAuth config */
|
|
@@ -158,7 +158,7 @@ export class OAuthService {
|
|
|
158
158
|
* Exchange authorization code for IDP tokens using PKCE
|
|
159
159
|
*
|
|
160
160
|
* For PKCE providers: Exchanges code directly with OAuth provider (no client secret)
|
|
161
|
-
* For proxy mode: Exchanges code via
|
|
161
|
+
* For proxy mode: Exchanges code via Checkpoint API
|
|
162
162
|
*
|
|
163
163
|
* @param provider - OAuth provider name (e.g., "github", "google")
|
|
164
164
|
* @param code - Authorization code from OAuth callback
|
|
@@ -338,7 +338,7 @@ export class OAuthService {
|
|
|
338
338
|
}
|
|
339
339
|
|
|
340
340
|
/**
|
|
341
|
-
* Exchange token via
|
|
341
|
+
* Exchange token via Checkpoint proxy (for providers that require proxy mode)
|
|
342
342
|
*
|
|
343
343
|
* Note: For Phase 3 two-step flow, OAuth tokens are retrieved separately via
|
|
344
344
|
* OAuthTokenRetrievalService in the callback handler. This method maintains
|
|
@@ -350,7 +350,7 @@ export class OAuthService {
|
|
|
350
350
|
codeVerifier?: string,
|
|
351
351
|
redirectUri?: string
|
|
352
352
|
): Promise<IdpTokens> {
|
|
353
|
-
// Exchange via
|
|
353
|
+
// Exchange via Checkpoint proxy endpoint
|
|
354
354
|
const proxyUrl = `${this.config.agentShieldApiUrl}/api/v1/oauth/token`;
|
|
355
355
|
|
|
356
356
|
this.config.logger("[OAuthService] Exchanging token via proxy", {
|
|
@@ -453,7 +453,7 @@ export class OAuthService {
|
|
|
453
453
|
* Refresh IDP access token using refresh token
|
|
454
454
|
*
|
|
455
455
|
* For PKCE providers: Refreshes directly with OAuth provider
|
|
456
|
-
* For proxy mode: Refreshes via
|
|
456
|
+
* For proxy mode: Refreshes via Checkpoint API
|
|
457
457
|
*
|
|
458
458
|
* @param provider - OAuth provider name
|
|
459
459
|
* @param refreshToken - Refresh token from previous token exchange
|
|
@@ -481,7 +481,7 @@ export class OAuthService {
|
|
|
481
481
|
return this.refreshTokenPKCE(providerConfig, refreshToken);
|
|
482
482
|
}
|
|
483
483
|
|
|
484
|
-
// For proxy mode, refresh via
|
|
484
|
+
// For proxy mode, refresh via Checkpoint
|
|
485
485
|
if (providerConfig.proxyMode) {
|
|
486
486
|
return this.refreshTokenProxy(providerConfig, refreshToken);
|
|
487
487
|
}
|
|
@@ -564,7 +564,7 @@ export class OAuthService {
|
|
|
564
564
|
}
|
|
565
565
|
|
|
566
566
|
/**
|
|
567
|
-
* Refresh token via
|
|
567
|
+
* Refresh token via Checkpoint proxy
|
|
568
568
|
*/
|
|
569
569
|
private async refreshTokenProxy(
|
|
570
570
|
providerConfig: OAuthProvider,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* OAuth Token Retrieval Service
|
|
3
3
|
*
|
|
4
|
-
* Retrieves OAuth tokens from
|
|
4
|
+
* Retrieves OAuth tokens from Checkpoint after receiving delegation token.
|
|
5
5
|
* Implements the two-step token flow for Phase 3 custom IDP support.
|
|
6
6
|
*
|
|
7
7
|
* @package @kya-os/mcp-i-core
|
|
@@ -13,7 +13,7 @@ import type { IdpTokens } from "@kya-os/contracts/config";
|
|
|
13
13
|
* Configuration for OAuthTokenRetrievalService
|
|
14
14
|
*/
|
|
15
15
|
export interface OAuthTokenRetrievalServiceConfig {
|
|
16
|
-
/**
|
|
16
|
+
/** Checkpoint API base URL */
|
|
17
17
|
baseUrl: string;
|
|
18
18
|
/** Fetch implementation */
|
|
19
19
|
fetchProvider: typeof fetch;
|
|
@@ -28,7 +28,7 @@ export interface OAuthTokenRetrievalServiceConfig {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Response from
|
|
31
|
+
* Response from Checkpoint token retrieval endpoint
|
|
32
32
|
*/
|
|
33
33
|
interface OAuthTokenRetrievalResponse {
|
|
34
34
|
success: true;
|
|
@@ -47,7 +47,7 @@ interface OAuthTokenRetrievalResponse {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
* Error response from
|
|
50
|
+
* Error response from Checkpoint
|
|
51
51
|
*/
|
|
52
52
|
interface OAuthTokenRetrievalErrorResponse {
|
|
53
53
|
success: false;
|
|
@@ -59,7 +59,7 @@ interface OAuthTokenRetrievalErrorResponse {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* Service for retrieving OAuth tokens from
|
|
62
|
+
* Service for retrieving OAuth tokens from Checkpoint
|
|
63
63
|
*/
|
|
64
64
|
export class OAuthTokenRetrievalService {
|
|
65
65
|
private config: Required<OAuthTokenRetrievalServiceConfig> & {
|
|
@@ -86,7 +86,7 @@ export class OAuthTokenRetrievalService {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
* Retrieve OAuth tokens from
|
|
89
|
+
* Retrieve OAuth tokens from Checkpoint
|
|
90
90
|
*
|
|
91
91
|
* @param delegationId - Delegation ID from token exchange response
|
|
92
92
|
* @param delegationToken - Delegation token (JWT) for authorization
|
|
@@ -213,9 +213,9 @@ export class OAuthTokenRetrievalService {
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
/**
|
|
216
|
-
* Map
|
|
216
|
+
* Map Checkpoint response to IdpTokens format
|
|
217
217
|
*
|
|
218
|
-
* @param data - Response data from
|
|
218
|
+
* @param data - Response data from Checkpoint
|
|
219
219
|
* @returns IdpTokens object
|
|
220
220
|
*/
|
|
221
221
|
private mapToIdpTokens(
|
|
@@ -52,7 +52,7 @@ export class CredentialAuthModeError extends Error {
|
|
|
52
52
|
* 0. Check for consent-only mode (authorization.type === 'none') - skip OAuth
|
|
53
53
|
* 1. Tool-specific oauthProvider field (Phase 2+ preferred)
|
|
54
54
|
* 2. Scope prefix inference (fallback)
|
|
55
|
-
* 3. Project-configured provider from
|
|
55
|
+
* 3. Project-configured provider from Checkpoint dashboard
|
|
56
56
|
* 4. Error if no provider can be resolved
|
|
57
57
|
*/
|
|
58
58
|
export class ProviderResolver {
|
|
@@ -161,7 +161,7 @@ export class ProviderResolver {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
// Priority 3: Use explicitly configured provider from
|
|
164
|
+
// Priority 3: Use explicitly configured provider from Checkpoint dashboard
|
|
165
165
|
// This is the provider the user has actually configured, not just any available provider
|
|
166
166
|
await this.registry.loadFromAgentShield(projectId);
|
|
167
167
|
const configuredProvider = this.registry.getConfiguredProvider();
|
|
@@ -177,11 +177,11 @@ export class ProviderResolver {
|
|
|
177
177
|
|
|
178
178
|
// Priority 4: Error if no provider is configured
|
|
179
179
|
// NOTE: We intentionally do NOT fall back to "first available provider" anymore
|
|
180
|
-
// because
|
|
180
|
+
// because Checkpoint returns ALL providers (even unconfigured ones).
|
|
181
181
|
// Only use providers explicitly configured by the user.
|
|
182
182
|
throw new Error(
|
|
183
183
|
`Tool requires OAuth but no provider is configured for project "${projectId}". ` +
|
|
184
|
-
`Configure an OAuth provider in
|
|
184
|
+
`Configure an OAuth provider in Checkpoint dashboard.`
|
|
185
185
|
);
|
|
186
186
|
}
|
|
187
187
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Session Registration Service
|
|
3
3
|
*
|
|
4
|
-
* Registers MCP sessions with the
|
|
4
|
+
* Registers MCP sessions with the Checkpoint dashboard, enabling
|
|
5
5
|
* visibility into which MCP clients are connecting to agents.
|
|
6
6
|
*
|
|
7
7
|
* This is a fire-and-forget service - session registration should not
|
|
@@ -25,7 +25,7 @@ import type { FetchProvider } from "../providers/base.js";
|
|
|
25
25
|
* Configuration for the session registration service
|
|
26
26
|
*/
|
|
27
27
|
export interface SessionRegistrationServiceConfig {
|
|
28
|
-
/** Base URL for the
|
|
28
|
+
/** Base URL for the Checkpoint API (e.g., "https://kya.vouched.id") */
|
|
29
29
|
baseUrl: string;
|
|
30
30
|
|
|
31
31
|
/** API key for authentication */
|
|
@@ -56,7 +56,7 @@ export interface SessionRegistrationResult {
|
|
|
56
56
|
/**
|
|
57
57
|
* Session Registration Service
|
|
58
58
|
*
|
|
59
|
-
* Registers MCP sessions with
|
|
59
|
+
* Registers MCP sessions with Checkpoint for dashboard visibility.
|
|
60
60
|
* Designed to be non-blocking - failures are logged but don't throw.
|
|
61
61
|
*/
|
|
62
62
|
export class SessionRegistrationService {
|
|
@@ -78,7 +78,7 @@ export class SessionRegistrationService {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
* Register a session with
|
|
81
|
+
* Register a session with Checkpoint
|
|
82
82
|
*
|
|
83
83
|
* This is a fire-and-forget operation. Failures are logged but don't throw.
|
|
84
84
|
* The method returns quickly and doesn't block the caller.
|
|
@@ -105,7 +105,7 @@ export class SessionRegistrationService {
|
|
|
105
105
|
|
|
106
106
|
const url = `${this.config.baseUrl}${AGENTSHIELD_ENDPOINTS.SESSIONS}`;
|
|
107
107
|
|
|
108
|
-
// NOTE: This registers the SESSION with
|
|
108
|
+
// NOTE: This registers the SESSION with Checkpoint for dashboard visibility
|
|
109
109
|
// This is NOT the same as agent registration with Know That AI (which happens during deploy)
|
|
110
110
|
this.config.logger(
|
|
111
111
|
"[SessionRegistration] Registering session for dashboard visibility",
|
|
@@ -173,7 +173,7 @@ export class SessionRegistrationService {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
this.config.logger(
|
|
176
|
-
"[SessionRegistration] Session now visible in
|
|
176
|
+
"[SessionRegistration] Session now visible in Checkpoint dashboard",
|
|
177
177
|
{
|
|
178
178
|
sessionId,
|
|
179
179
|
registered: parseResult.data.registered,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ToolProtectionService - Fetches and caches tool protection configurations
|
|
3
3
|
*
|
|
4
|
-
* This service manages tool protection configuration from
|
|
4
|
+
* This service manages tool protection configuration from Checkpoint API with
|
|
5
5
|
* efficient caching and automatic synchronization support.
|
|
6
6
|
*
|
|
7
7
|
* C2 (#2916) classification: **product-layer, no DIF equivalent.** This service is
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
*
|
|
23
23
|
* CONFIGURATION PRECEDENCE (highest to lowest):
|
|
24
24
|
* ---------------------------------------------
|
|
25
|
-
* 1. Remote config (
|
|
25
|
+
* 1. Remote config (Checkpoint API) - WINS (source of truth)
|
|
26
26
|
* 2. Local config (localConfig) - Base defaults, overridden by remote
|
|
27
27
|
* 3. Framework defaults
|
|
28
28
|
*
|
|
@@ -34,26 +34,26 @@
|
|
|
34
34
|
*
|
|
35
35
|
* CORE FUNCTIONALITY:
|
|
36
36
|
* -------------------
|
|
37
|
-
* 1. Fetches tool protection config from
|
|
37
|
+
* 1. Fetches tool protection config from Checkpoint API (remote wins)
|
|
38
38
|
* 2. Merges with local config (local serves as base defaults)
|
|
39
39
|
* 3. Caches responses with configurable TTL (default 5 minutes)
|
|
40
40
|
* 4. Provides delegation requirement checking before tool execution
|
|
41
41
|
*
|
|
42
42
|
* SYNCHRONIZATION WITH AGENTSHIELD:
|
|
43
43
|
* ----------------------------------
|
|
44
|
-
* When you update tool protection settings in the
|
|
44
|
+
* When you update tool protection settings in the Checkpoint dashboard:
|
|
45
45
|
*
|
|
46
46
|
* 1. Dashboard sends PATCH /api/internal/bouncer/tools/{projectId}/{toolName}
|
|
47
|
-
* 2.
|
|
47
|
+
* 2. Checkpoint updates the database immediately (PostgreSQL JSONB column)
|
|
48
48
|
* 3. Dashboard sends POST /admin/clear-cache to this service (automatic)
|
|
49
49
|
* 4. This service clears the cached config from KV storage
|
|
50
|
-
* 5. Next tool call fetches fresh config from
|
|
50
|
+
* 5. Next tool call fetches fresh config from Checkpoint API
|
|
51
51
|
* 6. New config is cached for the configured TTL period
|
|
52
52
|
*
|
|
53
53
|
* CACHE INVALIDATION:
|
|
54
54
|
* -------------------
|
|
55
55
|
* Cache is invalidated via POST /admin/clear-cache endpoint:
|
|
56
|
-
* - Triggered automatically by
|
|
56
|
+
* - Triggered automatically by Checkpoint dashboard when tool protection changes
|
|
57
57
|
* - Can be triggered manually for testing/debugging
|
|
58
58
|
* - Requires API key authentication for security
|
|
59
59
|
*
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
*
|
|
69
69
|
* Discovery happens when:
|
|
70
70
|
* - Agent makes first tool call with proof submission
|
|
71
|
-
* -
|
|
71
|
+
* - Checkpoint extracts tool info from cryptographic proof
|
|
72
72
|
* - Tool is added to bouncerConfigs.discoveredTools in database
|
|
73
73
|
*
|
|
74
74
|
* If tool not discovered:
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
*
|
|
101
101
|
* Problem: Updates take 5+ minutes to apply
|
|
102
102
|
* Cause: Long cache TTL and cache clear failed
|
|
103
|
-
* Solution: Configure MCP server URL in
|
|
103
|
+
* Solution: Configure MCP server URL in Checkpoint for auto cache clear
|
|
104
104
|
*
|
|
105
105
|
* @see https://github.com/modelcontextprotocol-identity/agent-shield/docs/bouncer/tool-protection-sync.md
|
|
106
106
|
* @package @kya-os/mcp-i-core
|
|
@@ -133,7 +133,7 @@ interface ToolProtectionData {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
|
-
* Response from
|
|
136
|
+
* Response from Checkpoint API bouncer endpoints
|
|
137
137
|
*
|
|
138
138
|
* Uses the merged config endpoint (/projects/{projectId}/config):
|
|
139
139
|
* { data: { config: { toolProtection: { tools: {...} } } } }
|
|
@@ -330,7 +330,7 @@ export class ToolProtectionService {
|
|
|
330
330
|
|
|
331
331
|
// Merge with local config (REMOTE API takes priority over local)
|
|
332
332
|
// Standard precedence: Default < Local < Remote
|
|
333
|
-
// Remote (
|
|
333
|
+
// Remote (Checkpoint dashboard) is the source of truth and WINS over local config
|
|
334
334
|
const mergedToolProtections: Record<string, ToolProtection> = {};
|
|
335
335
|
|
|
336
336
|
// Step 1: Apply local config as base (if provided)
|
|
@@ -620,7 +620,7 @@ export class ToolProtectionService {
|
|
|
620
620
|
}
|
|
621
621
|
|
|
622
622
|
/**
|
|
623
|
-
* Fetch tool protection config from
|
|
623
|
+
* Fetch tool protection config from Checkpoint API
|
|
624
624
|
*
|
|
625
625
|
* Uses the merged /config endpoint which returns tool protections embedded
|
|
626
626
|
* at config.toolProtection.tools. Falls back to legacy formats for backward
|
|
@@ -646,7 +646,7 @@ export class ToolProtectionService {
|
|
|
646
646
|
const error = new Error(
|
|
647
647
|
"[ToolProtectionService] projectId is required for user-scoped delegation. " +
|
|
648
648
|
"Agent-only scoping has been deprecated due to security concerns (cross-user delegation leakage). " +
|
|
649
|
-
"Please configure
|
|
649
|
+
"Please configure CHECKPOINT_PROJECT_ID environment variable."
|
|
650
650
|
);
|
|
651
651
|
console.error("[ToolProtectionService]", error.message);
|
|
652
652
|
throw error;
|
|
@@ -700,7 +700,7 @@ export class ToolProtectionService {
|
|
|
700
700
|
});
|
|
701
701
|
}
|
|
702
702
|
throw new Error(
|
|
703
|
-
`ToolProtectionService: ${error}. Check
|
|
703
|
+
`ToolProtectionService: ${error}. Check CHECKPOINT_API_KEY in .dev.vars or wrangler.toml [vars]`
|
|
704
704
|
);
|
|
705
705
|
}
|
|
706
706
|
|
|
@@ -763,7 +763,7 @@ export class ToolProtectionService {
|
|
|
763
763
|
* Extracts tool protection configs from merged config format:
|
|
764
764
|
* { data: { config: { toolProtection: { tools: {...} } } } }
|
|
765
765
|
*
|
|
766
|
-
* @param response API response from
|
|
766
|
+
* @param response API response from Checkpoint
|
|
767
767
|
* @returns Record of tool name to ToolProtection
|
|
768
768
|
*/
|
|
769
769
|
private parseToolProtectionsFromResponse(
|
|
@@ -854,9 +854,9 @@ export class ToolProtectionService {
|
|
|
854
854
|
* The next request from the same edge location will get the fresh data.
|
|
855
855
|
*
|
|
856
856
|
* IMPORTANT: This method uses bypassCDNCache to ensure we get fresh data
|
|
857
|
-
* from
|
|
857
|
+
* from Checkpoint's origin server, not stale CDN-cached data. This is
|
|
858
858
|
* critical for instant cache invalidation when tool protection settings
|
|
859
|
-
* are changed in the
|
|
859
|
+
* are changed in the Checkpoint dashboard.
|
|
860
860
|
*
|
|
861
861
|
* @param agentDid DID of the agent (used for cache key)
|
|
862
862
|
* @returns The fresh tool protection config from API
|
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
ToolProtection,
|
|
14
14
|
ToolProtectionMap,
|
|
15
15
|
} from "@kya-os/contracts/tool-protection";
|
|
16
|
+
import type { DelegationDenial } from "../runtime/delegation-denial.js";
|
|
16
17
|
|
|
17
18
|
// Re-export for backward compatibility
|
|
18
19
|
export type { ToolProtection };
|
|
@@ -33,13 +34,13 @@ export interface ToolProtectionConfig {
|
|
|
33
34
|
*/
|
|
34
35
|
export interface ToolProtectionServiceConfig {
|
|
35
36
|
/**
|
|
36
|
-
*
|
|
37
|
+
* Checkpoint API base URL
|
|
37
38
|
* @example "https://kya.vouched.id"
|
|
38
39
|
*/
|
|
39
40
|
apiUrl: string;
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
+
* Checkpoint API key for authentication
|
|
43
44
|
* @example "sk_..."
|
|
44
45
|
*/
|
|
45
46
|
apiKey: string;
|
|
@@ -65,7 +66,7 @@ export interface ToolProtectionServiceConfig {
|
|
|
65
66
|
* Use this for development defaults or project-specific base settings.
|
|
66
67
|
*
|
|
67
68
|
* Precedence order (highest to lowest):
|
|
68
|
-
* 1. Remote config (
|
|
69
|
+
* 1. Remote config (Checkpoint API) - WINS
|
|
69
70
|
* 2. Local config (this field)
|
|
70
71
|
* 3. Framework defaults
|
|
71
72
|
*
|
|
@@ -139,18 +140,26 @@ export interface ToolProtectionApiResponse {
|
|
|
139
140
|
export class DelegationRequiredError extends Error {
|
|
140
141
|
public resumeToken?: string;
|
|
141
142
|
public interceptedCall?: InterceptedToolCall;
|
|
143
|
+
/**
|
|
144
|
+
* Why the verifier refused a presented delegation, when it gave an
|
|
145
|
+
* allowlisted code. Undefined when no delegation was presented or the
|
|
146
|
+
* reason is unknown, so callers keep today's authorization-required text.
|
|
147
|
+
*/
|
|
148
|
+
public denial?: DelegationDenial;
|
|
142
149
|
|
|
143
150
|
constructor(
|
|
144
151
|
public toolName: string,
|
|
145
152
|
public requiredScopes: string[],
|
|
146
153
|
public consentUrl?: string,
|
|
147
154
|
interceptedCall?: InterceptedToolCall,
|
|
148
|
-
resumeToken?: string
|
|
155
|
+
resumeToken?: string,
|
|
156
|
+
denial?: DelegationDenial
|
|
149
157
|
) {
|
|
150
158
|
super(`Delegation required for tool "${toolName}"`);
|
|
151
159
|
this.name = "DelegationRequiredError";
|
|
152
160
|
this.interceptedCall = interceptedCall;
|
|
153
161
|
this.resumeToken = resumeToken;
|
|
162
|
+
this.denial = denial;
|
|
154
163
|
}
|
|
155
164
|
}
|
|
156
165
|
|