@kya-os/mcp-i-runtime 1.2.6 → 1.3.0
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/config/remote-config.js +2 -2
- package/dist/config/remote-config.js.map +1 -1
- package/dist/runtime/base.js +4 -4
- package/dist/runtime/base.js.map +1 -1
- package/dist/runtime/verified-delegation.d.ts +1 -1
- package/dist/runtime/verified-delegation.d.ts.map +1 -1
- package/dist/services/access-control.service.d.ts +2 -2
- package/dist/services/access-control.service.d.ts.map +1 -1
- package/dist/services/access-control.service.js +30 -30
- package/dist/services/access-control.service.js.map +1 -1
- package/dist/services/oauth-provider-registry.d.ts +3 -1
- package/dist/services/oauth-provider-registry.d.ts.map +1 -1
- package/dist/services/oauth-provider-registry.js +5 -1
- package/dist/services/oauth-provider-registry.js.map +1 -1
- package/dist/services/oauth-service.d.ts +9 -2
- package/dist/services/oauth-service.d.ts.map +1 -1
- package/dist/services/oauth-service.js +6 -6
- package/dist/services/oauth-service.js.map +1 -1
- package/dist/services/provider-resolver.js +3 -3
- package/dist/services/provider-resolver.js.map +1 -1
- package/dist/services/session-registration.service.d.ts +1 -1
- package/dist/services/session-registration.service.d.ts.map +1 -1
- package/dist/services/session-registration.service.js +4 -4
- package/dist/services/session-registration.service.js.map +1 -1
- package/dist/services/tool-protection.service.d.ts +2 -2
- package/dist/services/tool-protection.service.js +2 -2
- package/package.json +2 -2
- package/src/__tests__/config/provider-runtime-config.test.ts +1 -1
- package/src/__tests__/config.test.ts +3 -3
- package/src/__tests__/integration/full-flow.test.ts +1 -1
- package/src/__tests__/regression/phase2-regression.test.ts +2 -2
- package/src/__tests__/runtime/process-tool-call-security.test.ts +3 -3
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +4 -4
- package/src/__tests__/runtime/verified-delegation.test.ts +1 -1
- package/src/__tests__/services/access-control-retry.test.ts +2 -2
- package/src/__tests__/services/cache-busting.test.ts +1 -1
- package/src/__tests__/services/former-names.test.ts +114 -0
- package/src/__tests__/services/oauth-service-errors.test.ts +5 -5
- package/src/__tests__/services/oauth-service-pkce.test.ts +2 -2
- package/src/__tests__/services/oauth-service-secret-resolution.test.ts +14 -14
- package/src/__tests__/services/provider-resolver-edge-cases.test.ts +9 -9
- package/src/auth/types.ts +1 -1
- package/src/config/remote-config.ts +2 -2
- package/src/runtime/base.ts +5 -5
- package/src/runtime/verified-delegation.ts +1 -1
- package/src/services/__tests__/access-control.integration.test.ts +3 -3
- package/src/services/__tests__/access-control.proof-response-validation.test.ts +7 -7
- package/src/services/__tests__/access-control.service.test.ts +14 -14
- package/src/services/__tests__/oauth-provider-registry.test.ts +10 -10
- package/src/services/__tests__/provider-resolution.integration.test.ts +6 -6
- package/src/services/__tests__/provider-resolver.test.ts +1 -1
- package/src/services/__tests__/session-registration.service.test.ts +1 -1
- package/src/services/access-control.service.ts +27 -27
- package/src/services/oauth-provider-registry.d.ts +2 -0
- package/src/services/oauth-provider-registry.ts +6 -1
- package/src/services/oauth-service.ts +20 -9
- package/src/services/provider-resolver.ts +3 -3
- package/src/services/session-registration.service.ts +4 -4
- package/src/services/tool-protection.service.ts +2 -2
- package/vitest.config.mts +1 -1
- /package/src/__tests__/services/{agentshield-integration.test.ts → checkpoint-integration.test.ts} +0 -0
|
@@ -250,7 +250,7 @@ describe("AccessControlApiService Retry Logic", () => {
|
|
|
250
250
|
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
251
251
|
});
|
|
252
252
|
|
|
253
|
-
it("should throw
|
|
253
|
+
it("should throw CheckpointAPIError on response with success: false", async () => {
|
|
254
254
|
mockFetch.mockResolvedValue(
|
|
255
255
|
createMockResponse({
|
|
256
256
|
ok: true,
|
|
@@ -383,7 +383,7 @@ describe("AccessControlApiService Retry Logic", () => {
|
|
|
383
383
|
});
|
|
384
384
|
|
|
385
385
|
describe("Retry Behavior (Server Errors)", () => {
|
|
386
|
-
it("should retry on 5xx server errors when
|
|
386
|
+
it("should retry on 5xx server errors when CheckpointAPIError thrown", async () => {
|
|
387
387
|
// First call returns 500, second succeeds
|
|
388
388
|
mockFetch
|
|
389
389
|
.mockResolvedValueOnce(
|
|
@@ -12,7 +12,7 @@ describe("Cache Busting in clearAndRefresh", () => {
|
|
|
12
12
|
cache = new InMemoryToolProtectionCache();
|
|
13
13
|
service = new ToolProtectionService(
|
|
14
14
|
{
|
|
15
|
-
apiUrl: "https://test.
|
|
15
|
+
apiUrl: "https://test.checkpoint.example",
|
|
16
16
|
apiKey: "test-api-key",
|
|
17
17
|
projectId,
|
|
18
18
|
cacheTtl: 300000,
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtimes released before the rename to Checkpoint (mcp-i-cloudflare 1.14.8
|
|
3
|
+
* and earlier) call this package with the AgentShield names. Those calls keep
|
|
4
|
+
* working: OAuthService reads the former API URL and key when the Checkpoint
|
|
5
|
+
* ones are absent, and the provider registry keeps its former load method.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
9
|
+
import type { OAuthConfig } from "@kya-os/contracts/config";
|
|
10
|
+
import {
|
|
11
|
+
OAuthService,
|
|
12
|
+
type OAuthServiceConfig,
|
|
13
|
+
} from "../../services/oauth-service";
|
|
14
|
+
import { OAuthProviderRegistry } from "../../services/oauth-provider-registry";
|
|
15
|
+
import type { FetchProvider } from "../../providers/base";
|
|
16
|
+
import type { OAuthConfigService } from "../../services/oauth-config.service";
|
|
17
|
+
|
|
18
|
+
const oauthConfig: OAuthConfig = {
|
|
19
|
+
enabled: true,
|
|
20
|
+
providers: {
|
|
21
|
+
google: {
|
|
22
|
+
clientId: "google-client-id",
|
|
23
|
+
authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
24
|
+
tokenUrl: "https://oauth2.googleapis.com/token",
|
|
25
|
+
supportsPKCE: false,
|
|
26
|
+
proxyMode: true,
|
|
27
|
+
scopes: ["profile", "email"],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe("OAuthService settings from callers built before the rename", () => {
|
|
33
|
+
let fetch: ReturnType<typeof vi.fn>;
|
|
34
|
+
let fetchProvider: FetchProvider;
|
|
35
|
+
let configService: OAuthConfigService;
|
|
36
|
+
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
fetch = vi.fn().mockResolvedValue({
|
|
39
|
+
ok: true,
|
|
40
|
+
status: 200,
|
|
41
|
+
text: vi
|
|
42
|
+
.fn()
|
|
43
|
+
.mockResolvedValue(
|
|
44
|
+
JSON.stringify({ access_token: "token", token_type: "Bearer" })
|
|
45
|
+
),
|
|
46
|
+
json: vi
|
|
47
|
+
.fn()
|
|
48
|
+
.mockResolvedValue({ access_token: "token", token_type: "Bearer" }),
|
|
49
|
+
clone: vi.fn().mockReturnThis(),
|
|
50
|
+
});
|
|
51
|
+
fetchProvider = { fetch } as unknown as FetchProvider;
|
|
52
|
+
configService = {
|
|
53
|
+
getOAuthConfig: vi.fn().mockResolvedValue(oauthConfig),
|
|
54
|
+
} as unknown as OAuthConfigService;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/** Where the proxy token exchange went, and with which key. */
|
|
58
|
+
async function proxyRequest(settings: Partial<OAuthServiceConfig>) {
|
|
59
|
+
const service = new OAuthService({
|
|
60
|
+
configService,
|
|
61
|
+
fetchProvider,
|
|
62
|
+
projectId: "project-1",
|
|
63
|
+
...settings,
|
|
64
|
+
} as OAuthServiceConfig);
|
|
65
|
+
await service
|
|
66
|
+
.exchangeToken("google", "code", "verifier", "http://localhost/callback")
|
|
67
|
+
.catch(() => undefined);
|
|
68
|
+
const [url, init] = fetch.mock.calls[0] as [string, RequestInit];
|
|
69
|
+
return {
|
|
70
|
+
url,
|
|
71
|
+
authorization: (init.headers as Record<string, string>).Authorization,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
it("uses the former agentShieldApiUrl and agentShieldApiKey when they are all it gets", async () => {
|
|
76
|
+
expect(
|
|
77
|
+
await proxyRequest({
|
|
78
|
+
agentShieldApiUrl: "https://former.example",
|
|
79
|
+
agentShieldApiKey: "sk_former",
|
|
80
|
+
})
|
|
81
|
+
).toEqual({
|
|
82
|
+
url: "https://former.example/api/v1/oauth/token",
|
|
83
|
+
authorization: "Bearer sk_former",
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("prefers the Checkpoint settings when both are given", async () => {
|
|
88
|
+
expect(
|
|
89
|
+
await proxyRequest({
|
|
90
|
+
checkpointApiUrl: "https://kya.vouched.id",
|
|
91
|
+
checkpointApiKey: "sk_current",
|
|
92
|
+
agentShieldApiUrl: "https://former.example",
|
|
93
|
+
agentShieldApiKey: "sk_former",
|
|
94
|
+
})
|
|
95
|
+
).toEqual({
|
|
96
|
+
url: "https://kya.vouched.id/api/v1/oauth/token",
|
|
97
|
+
authorization: "Bearer sk_current",
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("OAuthProviderRegistry.loadFromAgentShield", () => {
|
|
103
|
+
it("loads the project's providers the same way as loadFromCheckpoint", async () => {
|
|
104
|
+
const getOAuthConfig = vi.fn().mockResolvedValue(oauthConfig);
|
|
105
|
+
const registry = new OAuthProviderRegistry({
|
|
106
|
+
getOAuthConfig,
|
|
107
|
+
} as unknown as OAuthConfigService);
|
|
108
|
+
|
|
109
|
+
await registry.loadFromAgentShield("project-1");
|
|
110
|
+
|
|
111
|
+
expect(getOAuthConfig).toHaveBeenCalledWith("project-1");
|
|
112
|
+
expect(registry.getProviderNames()).toEqual(["google"]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -41,8 +41,8 @@ describe("OAuthService Error Handling", () => {
|
|
|
41
41
|
let mockLogger: ReturnType<typeof vi.fn>;
|
|
42
42
|
|
|
43
43
|
const projectId = "test-project-123";
|
|
44
|
-
const
|
|
45
|
-
const
|
|
44
|
+
const checkpointApiUrl = "https://kya.vouched.id";
|
|
45
|
+
const checkpointApiKey = "test-api-key";
|
|
46
46
|
|
|
47
47
|
// Mock provider configurations
|
|
48
48
|
const pkceProvider: OAuthProvider = {
|
|
@@ -92,8 +92,8 @@ describe("OAuthService Error Handling", () => {
|
|
|
92
92
|
service = new OAuthService({
|
|
93
93
|
configService: mockConfigService,
|
|
94
94
|
fetchProvider: mockFetchProvider,
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
checkpointApiUrl,
|
|
96
|
+
checkpointApiKey,
|
|
97
97
|
projectId,
|
|
98
98
|
logger: mockLogger,
|
|
99
99
|
});
|
|
@@ -419,7 +419,7 @@ describe("OAuthService Error Handling", () => {
|
|
|
419
419
|
expect(call[0]).toContain("/api/v1/oauth/token");
|
|
420
420
|
expect(call[1].headers["Content-Type"]).toBe("application/json");
|
|
421
421
|
expect(call[1].headers["Authorization"]).toBe(
|
|
422
|
-
`Bearer ${
|
|
422
|
+
`Bearer ${checkpointApiKey}`
|
|
423
423
|
);
|
|
424
424
|
});
|
|
425
425
|
|
|
@@ -51,8 +51,8 @@ describe("OAuthService PKCE Token Exchange", () => {
|
|
|
51
51
|
oauthService = new OAuthService({
|
|
52
52
|
configService: mockConfigService,
|
|
53
53
|
fetchProvider: mockFetchProvider,
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
checkpointApiUrl: "https://test.checkpoint.example",
|
|
55
|
+
checkpointApiKey: "test-api-key",
|
|
56
56
|
projectId: "test-project",
|
|
57
57
|
logger: vi.fn(),
|
|
58
58
|
});
|
|
@@ -93,8 +93,8 @@ describe("OAuthService Secret Resolution", () => {
|
|
|
93
93
|
const oauthService = new OAuthService({
|
|
94
94
|
configService: mockConfigService,
|
|
95
95
|
fetchProvider: mockFetchProvider,
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
checkpointApiUrl: "https://test.checkpoint.example",
|
|
97
|
+
checkpointApiKey: "test-api-key",
|
|
98
98
|
projectId: "test-project",
|
|
99
99
|
logger: mockLogger,
|
|
100
100
|
secretResolver: mockSecretResolver,
|
|
@@ -130,8 +130,8 @@ describe("OAuthService Secret Resolution", () => {
|
|
|
130
130
|
const oauthService = new OAuthService({
|
|
131
131
|
configService: mockConfigService,
|
|
132
132
|
fetchProvider: mockFetchProvider,
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
checkpointApiUrl: "https://test.checkpoint.example",
|
|
134
|
+
checkpointApiKey: "test-api-key",
|
|
135
135
|
projectId: "test-project",
|
|
136
136
|
logger: mockLogger,
|
|
137
137
|
secretResolver: mockSecretResolver,
|
|
@@ -155,8 +155,8 @@ describe("OAuthService Secret Resolution", () => {
|
|
|
155
155
|
const oauthService = new OAuthService({
|
|
156
156
|
configService: mockConfigService,
|
|
157
157
|
fetchProvider: mockFetchProvider,
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
checkpointApiUrl: "https://test.checkpoint.example",
|
|
159
|
+
checkpointApiKey: "test-api-key",
|
|
160
160
|
projectId: "test-project",
|
|
161
161
|
logger: mockLogger,
|
|
162
162
|
secretResolver: mockSecretResolver,
|
|
@@ -184,8 +184,8 @@ describe("OAuthService Secret Resolution", () => {
|
|
|
184
184
|
const oauthService = new OAuthService({
|
|
185
185
|
configService: mockConfigService,
|
|
186
186
|
fetchProvider: mockFetchProvider,
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
checkpointApiUrl: "https://test.checkpoint.example",
|
|
188
|
+
checkpointApiKey: "test-api-key",
|
|
189
189
|
projectId: "test-project",
|
|
190
190
|
logger: mockLogger,
|
|
191
191
|
secretResolver: mockSecretResolver,
|
|
@@ -201,8 +201,8 @@ describe("OAuthService Secret Resolution", () => {
|
|
|
201
201
|
const oauthService = new OAuthService({
|
|
202
202
|
configService: mockConfigService,
|
|
203
203
|
fetchProvider: mockFetchProvider,
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
checkpointApiUrl: "https://test.checkpoint.example",
|
|
205
|
+
checkpointApiKey: "test-api-key",
|
|
206
206
|
projectId: "test-project",
|
|
207
207
|
logger: mockLogger,
|
|
208
208
|
// No secretResolver provided - should use defaultSecretResolver
|
|
@@ -248,8 +248,8 @@ describe("OAuthService Secret Resolution", () => {
|
|
|
248
248
|
const oauthService = new OAuthService({
|
|
249
249
|
configService: mockConfigService,
|
|
250
250
|
fetchProvider: mockFetchProvider,
|
|
251
|
-
|
|
252
|
-
|
|
251
|
+
checkpointApiUrl: "https://test.checkpoint.example",
|
|
252
|
+
checkpointApiKey: "test-api-key",
|
|
253
253
|
projectId: "test-project",
|
|
254
254
|
logger: mockLogger,
|
|
255
255
|
secretResolver: mockSecretResolver,
|
|
@@ -295,8 +295,8 @@ describe("OAuthService Secret Resolution", () => {
|
|
|
295
295
|
const oauthService = new OAuthService({
|
|
296
296
|
configService: mockConfigService,
|
|
297
297
|
fetchProvider: mockFetchProvider,
|
|
298
|
-
|
|
299
|
-
|
|
298
|
+
checkpointApiUrl: "https://test.checkpoint.example",
|
|
299
|
+
checkpointApiKey: "test-api-key",
|
|
300
300
|
projectId: "test-project",
|
|
301
301
|
logger: mockLogger,
|
|
302
302
|
secretResolver: mockSecretResolver,
|
|
@@ -55,7 +55,7 @@ describe("ProviderResolver - Edge Cases", () => {
|
|
|
55
55
|
|
|
56
56
|
// Create fresh mocks for each test
|
|
57
57
|
const getProviderNamesMock = vi.fn().mockReturnValue([]);
|
|
58
|
-
const
|
|
58
|
+
const loadFromCheckpointMock = vi.fn().mockResolvedValue(undefined);
|
|
59
59
|
const hasProviderMock = vi.fn().mockReturnValue(false);
|
|
60
60
|
const getConfiguredProviderMock = vi.fn().mockReturnValue(null);
|
|
61
61
|
|
|
@@ -63,7 +63,7 @@ describe("ProviderResolver - Edge Cases", () => {
|
|
|
63
63
|
hasProvider: hasProviderMock,
|
|
64
64
|
getAllProviders: vi.fn().mockReturnValue([]),
|
|
65
65
|
getProviderNames: getProviderNamesMock,
|
|
66
|
-
|
|
66
|
+
loadFromCheckpoint: loadFromCheckpointMock,
|
|
67
67
|
getConfiguredProvider: getConfiguredProviderMock,
|
|
68
68
|
} as any;
|
|
69
69
|
|
|
@@ -82,7 +82,7 @@ describe("ProviderResolver - Edge Cases", () => {
|
|
|
82
82
|
const testRegistry = {
|
|
83
83
|
getProviderNames: vi.fn().mockReturnValue(["github", "google"]),
|
|
84
84
|
hasProvider: vi.fn((provider: string) => provider === "github" || provider === "google"),
|
|
85
|
-
|
|
85
|
+
loadFromCheckpoint: vi.fn().mockResolvedValue(undefined),
|
|
86
86
|
getAllProviders: vi.fn().mockReturnValue([]),
|
|
87
87
|
};
|
|
88
88
|
|
|
@@ -96,13 +96,13 @@ describe("ProviderResolver - Edge Cases", () => {
|
|
|
96
96
|
expect(provider).toBe("github");
|
|
97
97
|
expect(testRegistry.hasProvider).toHaveBeenCalledWith("github");
|
|
98
98
|
// Should not need to load since registry already has providers
|
|
99
|
-
expect(testRegistry.
|
|
99
|
+
expect(testRegistry.loadFromCheckpoint).not.toHaveBeenCalled();
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
// TODO: Fix this test - it's trying to verify that the registry automatically loads
|
|
103
103
|
// when empty, but the mock state transitions are complex due to async timing.
|
|
104
104
|
// The test needs to properly simulate the registry state changing from empty to
|
|
105
|
-
// populated after
|
|
105
|
+
// populated after loadFromCheckpoint completes, but before hasProvider is called.
|
|
106
106
|
// Consider using a more integration-style test or rethinking the test approach.
|
|
107
107
|
it.skip("should load registry if empty before checking provider existence", async () => {
|
|
108
108
|
const toolProtection: ToolProtection = {
|
|
@@ -115,7 +115,7 @@ describe("ProviderResolver - Edge Cases", () => {
|
|
|
115
115
|
const mockEmptyRegistry = {
|
|
116
116
|
getProviderNames: vi.fn().mockReturnValue([]), // Empty initially
|
|
117
117
|
hasProvider: vi.fn().mockReturnValue(false), // No providers initially
|
|
118
|
-
|
|
118
|
+
loadFromCheckpoint: vi.fn().mockResolvedValue(undefined),
|
|
119
119
|
getAllProviders: vi.fn().mockReturnValue([]),
|
|
120
120
|
};
|
|
121
121
|
|
|
@@ -127,8 +127,8 @@ describe("ProviderResolver - Edge Cases", () => {
|
|
|
127
127
|
testResolver.resolveProvider(toolProtection, "test-project")
|
|
128
128
|
).rejects.toThrow(/not configured for project/);
|
|
129
129
|
|
|
130
|
-
// Verify that
|
|
131
|
-
expect(mockEmptyRegistry.
|
|
130
|
+
// Verify that loadFromCheckpoint was called
|
|
131
|
+
expect(mockEmptyRegistry.loadFromCheckpoint).toHaveBeenCalledWith("test-project");
|
|
132
132
|
expect(mockEmptyRegistry.getProviderNames).toHaveBeenCalled();
|
|
133
133
|
expect(mockEmptyRegistry.hasProvider).toHaveBeenCalledWith("github");
|
|
134
134
|
});
|
|
@@ -430,7 +430,7 @@ describe("ProviderResolver - Edge Cases", () => {
|
|
|
430
430
|
};
|
|
431
431
|
|
|
432
432
|
(mockRegistry.hasProvider as any).mockReturnValue(false);
|
|
433
|
-
(mockRegistry.
|
|
433
|
+
(mockRegistry.loadFromCheckpoint as any).mockRejectedValueOnce(
|
|
434
434
|
new Error("Network error")
|
|
435
435
|
);
|
|
436
436
|
|
package/src/auth/types.ts
CHANGED
|
@@ -58,7 +58,7 @@ export interface VerifyDelegationResult {
|
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Minimal delegation verifier interface required by verifyOrHints().
|
|
61
|
-
* Concrete implementations live in packages/mcp-i (
|
|
61
|
+
* Concrete implementations live in packages/mcp-i (CheckpointAPIDelegationVerifier, etc.).
|
|
62
62
|
*/
|
|
63
63
|
export interface DelegationVerifier {
|
|
64
64
|
verify(
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
import type { MCPIConfig } from '@kya-os/contracts/config';
|
|
26
26
|
import type { ToolProtection, ToolProtectionMap } from '@kya-os/contracts/tool-protection';
|
|
27
27
|
import type { PolicyConfig } from '@kya-os/contracts';
|
|
28
|
-
import {
|
|
28
|
+
import { CHECKPOINT_ENDPOINTS } from '@kya-os/contracts/checkpoint-api';
|
|
29
29
|
import { DEFAULT_POLICY_CONFIG } from '@kya-os/contracts';
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -142,7 +142,7 @@ export async function fetchRemoteConfig(
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
// ✅ PROJECT-SCOPED ENDPOINT: Ensures delegations are properly scoped to user+agent
|
|
145
|
-
const url = `${apiUrl}${
|
|
145
|
+
const url = `${apiUrl}${CHECKPOINT_ENDPOINTS.CONFIG(projectId)}`;
|
|
146
146
|
|
|
147
147
|
const response = await fetchProvider(url, {
|
|
148
148
|
headers: {
|
package/src/runtime/base.ts
CHANGED
|
@@ -29,8 +29,8 @@ import type {
|
|
|
29
29
|
} from "@kya-os/contracts/well-known";
|
|
30
30
|
import type { AccessControlApiService } from "../services/access-control.service.js";
|
|
31
31
|
import { authorizationMatches } from "../services/access-control.service.js";
|
|
32
|
-
import type { VerifyDelegationRequest } from "@kya-os/contracts/
|
|
33
|
-
import {
|
|
32
|
+
import type { VerifyDelegationRequest } from "@kya-os/contracts/checkpoint-api";
|
|
33
|
+
import { CheckpointAPIError } from "@kya-os/contracts/checkpoint-api";
|
|
34
34
|
import type { VerifiedDelegation } from "@kya-os/contracts/config";
|
|
35
35
|
import { toVerifiedDelegation } from "./verified-delegation.js";
|
|
36
36
|
import {
|
|
@@ -936,7 +936,7 @@ export class MCPIRuntimeBase {
|
|
|
936
936
|
sessionId: session?.id?.substring(0, 20) + "...",
|
|
937
937
|
matchType: identifiersMatch
|
|
938
938
|
? "direct"
|
|
939
|
-
: "
|
|
939
|
+
: "trusted_checkpoint_verification",
|
|
940
940
|
delegationIdentifierFormat: isDelegationIdentifierDid
|
|
941
941
|
? "did"
|
|
942
942
|
: "email_or_other",
|
|
@@ -1112,8 +1112,8 @@ export class MCPIRuntimeBase {
|
|
|
1112
1112
|
throw error;
|
|
1113
1113
|
}
|
|
1114
1114
|
|
|
1115
|
-
// Handle
|
|
1116
|
-
if (error instanceof
|
|
1115
|
+
// Handle CheckpointAPIError (network errors, API errors, etc.)
|
|
1116
|
+
if (error instanceof CheckpointAPIError) {
|
|
1117
1117
|
if (this.config.environment === "development") {
|
|
1118
1118
|
console.error(
|
|
1119
1119
|
"[MCP-I] ❌ Delegation verification error (API failure)",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type { VerifiedDelegation } from "@kya-os/contracts/config";
|
|
13
|
-
import type { VerifyDelegationResponse } from "@kya-os/contracts/
|
|
13
|
+
import type { VerifyDelegationResponse } from "@kya-os/contracts/checkpoint-api";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Build a VerifiedDelegation from a verify response.
|
|
@@ -18,8 +18,8 @@ import {
|
|
|
18
18
|
} from "../../__tests__/utils/mock-providers.js";
|
|
19
19
|
import type { ProviderRuntimeConfig } from "../../config.js";
|
|
20
20
|
import type { DetachedProof } from "@kya-os/contracts/proof";
|
|
21
|
-
import type { VerifyDelegationRequest, ProofSubmissionRequest } from "@kya-os/contracts/
|
|
22
|
-
import {
|
|
21
|
+
import type { VerifyDelegationRequest, ProofSubmissionRequest } from "@kya-os/contracts/checkpoint-api";
|
|
22
|
+
import { CheckpointAPIError } from "@kya-os/contracts/checkpoint-api";
|
|
23
23
|
|
|
24
24
|
describe("AccessControlApiService Integration", () => {
|
|
25
25
|
let accessControlService: AccessControlApiService;
|
|
@@ -432,7 +432,7 @@ describe("AccessControlApiService Integration", () => {
|
|
|
432
432
|
|
|
433
433
|
await expect(
|
|
434
434
|
accessControlService.verifyDelegation(request)
|
|
435
|
-
).rejects.toThrow(
|
|
435
|
+
).rejects.toThrow(CheckpointAPIError);
|
|
436
436
|
|
|
437
437
|
// Should not retry
|
|
438
438
|
expect(mockFetchProvider.fetch).toHaveBeenCalledTimes(1);
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
11
11
|
import { AccessControlApiService } from "../access-control.service";
|
|
12
|
-
import { proofSubmissionResponseSchema } from "@kya-os/contracts/
|
|
13
|
-
import type { ProofSubmissionRequest } from "@kya-os/contracts/
|
|
12
|
+
import { proofSubmissionResponseSchema } from "@kya-os/contracts/checkpoint-api";
|
|
13
|
+
import type { ProofSubmissionRequest } from "@kya-os/contracts/checkpoint-api";
|
|
14
14
|
|
|
15
15
|
describe("Proof Submission Response Validation", () => {
|
|
16
16
|
let service: AccessControlApiService;
|
|
@@ -274,7 +274,7 @@ describe("Proof Submission Response Validation", () => {
|
|
|
274
274
|
|
|
275
275
|
it("should validate schema directly matches Checkpoint response format", () => {
|
|
276
276
|
// This test ensures the schema matches what Checkpoint actually returns
|
|
277
|
-
const
|
|
277
|
+
const checkpointResponseData = {
|
|
278
278
|
success: true,
|
|
279
279
|
accepted: 1,
|
|
280
280
|
rejected: 0,
|
|
@@ -287,16 +287,16 @@ describe("Proof Submission Response Validation", () => {
|
|
|
287
287
|
};
|
|
288
288
|
|
|
289
289
|
const validation = proofSubmissionResponseSchema.safeParse(
|
|
290
|
-
|
|
290
|
+
checkpointResponseData
|
|
291
291
|
);
|
|
292
292
|
expect(validation.success).toBe(true);
|
|
293
293
|
if (validation.success) {
|
|
294
|
-
expect(validation.data).toMatchObject(
|
|
294
|
+
expect(validation.data).toMatchObject(checkpointResponseData);
|
|
295
295
|
}
|
|
296
296
|
});
|
|
297
297
|
|
|
298
298
|
it("should validate schema with errors array matches Checkpoint format", () => {
|
|
299
|
-
const
|
|
299
|
+
const checkpointResponseData = {
|
|
300
300
|
success: true,
|
|
301
301
|
accepted: 0,
|
|
302
302
|
rejected: 1,
|
|
@@ -319,7 +319,7 @@ describe("Proof Submission Response Validation", () => {
|
|
|
319
319
|
};
|
|
320
320
|
|
|
321
321
|
const validation = proofSubmissionResponseSchema.safeParse(
|
|
322
|
-
|
|
322
|
+
checkpointResponseData
|
|
323
323
|
);
|
|
324
324
|
expect(validation.success).toBe(true);
|
|
325
325
|
if (validation.success) {
|
|
@@ -11,13 +11,13 @@ import {
|
|
|
11
11
|
AccessControlApiService,
|
|
12
12
|
authorizationMatches,
|
|
13
13
|
} from "../access-control.service.js";
|
|
14
|
-
import {
|
|
14
|
+
import { CheckpointAPIError } from "@kya-os/contracts/checkpoint-api";
|
|
15
15
|
import type { FetchProvider } from "../../providers/base.js";
|
|
16
16
|
import type {
|
|
17
17
|
VerifyDelegationRequest,
|
|
18
18
|
ToolProtectionConfigAPIResponse,
|
|
19
19
|
ProofSubmissionRequest,
|
|
20
|
-
} from "@kya-os/contracts/
|
|
20
|
+
} from "@kya-os/contracts/checkpoint-api";
|
|
21
21
|
|
|
22
22
|
describe("AccessControlApiService", () => {
|
|
23
23
|
let service: AccessControlApiService;
|
|
@@ -109,7 +109,7 @@ describe("AccessControlApiService", () => {
|
|
|
109
109
|
|
|
110
110
|
await expect(
|
|
111
111
|
service.fetchConfig({ agentDid: "did:key:z123" })
|
|
112
|
-
).rejects.toThrow(
|
|
112
|
+
).rejects.toThrow(CheckpointAPIError);
|
|
113
113
|
|
|
114
114
|
const metrics = service.getMetrics();
|
|
115
115
|
expect(metrics.errorCount).toBe(1);
|
|
@@ -161,12 +161,12 @@ describe("AccessControlApiService", () => {
|
|
|
161
161
|
|
|
162
162
|
await expect(
|
|
163
163
|
service.fetchConfig({ agentDid: "did:key:z123" })
|
|
164
|
-
).rejects.toThrow(
|
|
164
|
+
).rejects.toThrow(CheckpointAPIError);
|
|
165
165
|
|
|
166
166
|
const error = await service
|
|
167
167
|
.fetchConfig({ agentDid: "did:key:z123" })
|
|
168
168
|
.catch((e) => e);
|
|
169
|
-
expect(error).toBeInstanceOf(
|
|
169
|
+
expect(error).toBeInstanceOf(CheckpointAPIError);
|
|
170
170
|
expect(error.code).toBe("invalid_response");
|
|
171
171
|
});
|
|
172
172
|
});
|
|
@@ -379,7 +379,7 @@ describe("AccessControlApiService", () => {
|
|
|
379
379
|
);
|
|
380
380
|
|
|
381
381
|
await expect(service.verifyDelegation(invalidRequest)).rejects.toThrow(
|
|
382
|
-
|
|
382
|
+
CheckpointAPIError
|
|
383
383
|
);
|
|
384
384
|
|
|
385
385
|
const error = await service
|
|
@@ -428,7 +428,7 @@ describe("AccessControlApiService", () => {
|
|
|
428
428
|
);
|
|
429
429
|
|
|
430
430
|
await expect(service.verifyDelegation(request)).rejects.toThrow(
|
|
431
|
-
|
|
431
|
+
CheckpointAPIError
|
|
432
432
|
);
|
|
433
433
|
|
|
434
434
|
const error = await service.verifyDelegation(request).catch((e) => e);
|
|
@@ -640,9 +640,9 @@ describe("AccessControlApiService", () => {
|
|
|
640
640
|
);
|
|
641
641
|
|
|
642
642
|
const error = await service.submitProofs(request).catch((e) => e);
|
|
643
|
-
expect(error).toBeInstanceOf(
|
|
644
|
-
expect((error as
|
|
645
|
-
expect((error as
|
|
643
|
+
expect(error).toBeInstanceOf(CheckpointAPIError);
|
|
644
|
+
expect((error as CheckpointAPIError).code).toBe("invalid_response");
|
|
645
|
+
expect((error as CheckpointAPIError).message).toBe(
|
|
646
646
|
"Response validation failed"
|
|
647
647
|
);
|
|
648
648
|
|
|
@@ -803,8 +803,8 @@ describe("AccessControlApiService", () => {
|
|
|
803
803
|
);
|
|
804
804
|
|
|
805
805
|
const error = await service.submitProofs(request).catch((e) => e);
|
|
806
|
-
expect(error).toBeInstanceOf(
|
|
807
|
-
expect((error as
|
|
806
|
+
expect(error).toBeInstanceOf(CheckpointAPIError);
|
|
807
|
+
expect((error as CheckpointAPIError).code).toBe("invalid_response");
|
|
808
808
|
});
|
|
809
809
|
|
|
810
810
|
it("should validate request schema", async () => {
|
|
@@ -814,7 +814,7 @@ describe("AccessControlApiService", () => {
|
|
|
814
814
|
} as ProofSubmissionRequest;
|
|
815
815
|
|
|
816
816
|
await expect(service.submitProofs(invalidRequest)).rejects.toThrow(
|
|
817
|
-
|
|
817
|
+
CheckpointAPIError
|
|
818
818
|
);
|
|
819
819
|
|
|
820
820
|
const error = await service.submitProofs(invalidRequest).catch((e) => e);
|
|
@@ -872,7 +872,7 @@ describe("AccessControlApiService", () => {
|
|
|
872
872
|
|
|
873
873
|
await expect(
|
|
874
874
|
service.fetchConfig({ agentDid: "did:key:z123" })
|
|
875
|
-
).rejects.toThrow(
|
|
875
|
+
).rejects.toThrow(CheckpointAPIError);
|
|
876
876
|
|
|
877
877
|
expect(mockFetchProvider.fetch).toHaveBeenCalledTimes(1);
|
|
878
878
|
expect(mockSleepFn).not.toHaveBeenCalled();
|
|
@@ -44,9 +44,9 @@ describe("OAuthProviderRegistry", () => {
|
|
|
44
44
|
registry = new OAuthProviderRegistry(mockConfigService);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
describe("
|
|
47
|
+
describe("loadFromCheckpoint", () => {
|
|
48
48
|
it("should load providers from Checkpoint config", async () => {
|
|
49
|
-
await registry.
|
|
49
|
+
await registry.loadFromCheckpoint("test-project");
|
|
50
50
|
|
|
51
51
|
expect(mockConfigService.getOAuthConfig).toHaveBeenCalledWith(
|
|
52
52
|
"test-project"
|
|
@@ -56,7 +56,7 @@ describe("OAuthProviderRegistry", () => {
|
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
it("should clear existing providers before loading new ones", async () => {
|
|
59
|
-
await registry.
|
|
59
|
+
await registry.loadFromCheckpoint("test-project");
|
|
60
60
|
expect(registry.getAllProviders().length).toBe(2);
|
|
61
61
|
|
|
62
62
|
const newConfig: OAuthConfig = {
|
|
@@ -72,7 +72,7 @@ describe("OAuthProviderRegistry", () => {
|
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
(mockConfigService.getOAuthConfig as any).mockResolvedValueOnce(newConfig);
|
|
75
|
-
await registry.
|
|
75
|
+
await registry.loadFromCheckpoint("test-project-2");
|
|
76
76
|
|
|
77
77
|
expect(registry.getAllProviders().length).toBe(1);
|
|
78
78
|
expect(registry.hasProvider("github")).toBe(false);
|
|
@@ -82,7 +82,7 @@ describe("OAuthProviderRegistry", () => {
|
|
|
82
82
|
|
|
83
83
|
describe("getProvider", () => {
|
|
84
84
|
it("should return provider by name", async () => {
|
|
85
|
-
await registry.
|
|
85
|
+
await registry.loadFromCheckpoint("test-project");
|
|
86
86
|
|
|
87
87
|
const githubProvider = registry.getProvider("github");
|
|
88
88
|
expect(githubProvider).toBeDefined();
|
|
@@ -90,7 +90,7 @@ describe("OAuthProviderRegistry", () => {
|
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
it("should return null for non-existent provider", async () => {
|
|
93
|
-
await registry.
|
|
93
|
+
await registry.loadFromCheckpoint("test-project");
|
|
94
94
|
|
|
95
95
|
const provider = registry.getProvider("nonexistent");
|
|
96
96
|
expect(provider).toBeNull();
|
|
@@ -99,7 +99,7 @@ describe("OAuthProviderRegistry", () => {
|
|
|
99
99
|
|
|
100
100
|
describe("getAllProviders", () => {
|
|
101
101
|
it("should return all providers", async () => {
|
|
102
|
-
await registry.
|
|
102
|
+
await registry.loadFromCheckpoint("test-project");
|
|
103
103
|
|
|
104
104
|
const providers = registry.getAllProviders();
|
|
105
105
|
expect(providers.length).toBe(2);
|
|
@@ -115,14 +115,14 @@ describe("OAuthProviderRegistry", () => {
|
|
|
115
115
|
|
|
116
116
|
describe("hasProvider", () => {
|
|
117
117
|
it("should return true for existing provider", async () => {
|
|
118
|
-
await registry.
|
|
118
|
+
await registry.loadFromCheckpoint("test-project");
|
|
119
119
|
|
|
120
120
|
expect(registry.hasProvider("github")).toBe(true);
|
|
121
121
|
expect(registry.hasProvider("google")).toBe(true);
|
|
122
122
|
});
|
|
123
123
|
|
|
124
124
|
it("should return false for non-existent provider", async () => {
|
|
125
|
-
await registry.
|
|
125
|
+
await registry.loadFromCheckpoint("test-project");
|
|
126
126
|
|
|
127
127
|
expect(registry.hasProvider("nonexistent")).toBe(false);
|
|
128
128
|
});
|
|
@@ -130,7 +130,7 @@ describe("OAuthProviderRegistry", () => {
|
|
|
130
130
|
|
|
131
131
|
describe("getProviderNames", () => {
|
|
132
132
|
it("should return all provider names", async () => {
|
|
133
|
-
await registry.
|
|
133
|
+
await registry.loadFromCheckpoint("test-project");
|
|
134
134
|
|
|
135
135
|
const names = registry.getProviderNames();
|
|
136
136
|
expect(names).toContain("github");
|