@kya-os/mcp-i-runtime 1.2.5 → 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 +2 -2
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/config/remote-config.d.ts +3 -3
- package/dist/config/remote-config.js +6 -6
- 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 +14 -11
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +51 -29
- 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 +4 -4
- package/dist/services/access-control.service.d.ts.map +1 -1
- package/dist/services/access-control.service.js +34 -34
- 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 +6 -4
- package/dist/services/oauth-provider-registry.d.ts.map +1 -1
- package/dist/services/oauth-provider-registry.js +9 -5
- package/dist/services/oauth-provider-registry.js.map +1 -1
- package/dist/services/oauth-service.d.ts +17 -10
- package/dist/services/oauth-service.d.ts.map +1 -1
- package/dist/services/oauth-service.js +14 -14
- 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 +7 -7
- package/dist/services/provider-resolver.js.map +1 -1
- package/dist/services/session-registration.service.d.ts +5 -5
- package/dist/services/session-registration.service.d.ts.map +1 -1
- package/dist/services/session-registration.service.js +9 -9
- package/dist/services/session-registration.service.js.map +1 -1
- package/dist/services/tool-protection.service.d.ts +15 -15
- package/dist/services/tool-protection.service.js +18 -18
- 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__/config/provider-runtime-config.test.ts +1 -1
- package/src/__tests__/config.test.ts +3 -3
- package/src/__tests__/index.test.ts +12 -0
- package/src/__tests__/integration/full-flow.test.ts +4 -4
- package/src/__tests__/regression/phase2-regression.test.ts +2 -2
- 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/process-tool-call-security.test.ts +326 -9
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +25 -10
- package/src/__tests__/runtime/verified-delegation.test.ts +129 -0
- 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/{agentshield-integration.test.ts → checkpoint-integration.test.ts} +3 -3
- 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 +15 -15
- package/src/__tests__/services/provider-resolver-edge-cases.test.ts +11 -11
- package/src/__tests__/services/tool-protection.service.test.ts +1 -1
- package/src/auth/types.ts +2 -2
- package/src/config/remote-config.ts +6 -6
- 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 +63 -32
- package/src/runtime/delegation-denial.ts +107 -0
- package/src/runtime/verified-delegation.ts +66 -0
- package/src/services/__tests__/access-control.integration.test.ts +3 -3
- package/src/services/__tests__/access-control.proof-response-validation.test.ts +15 -15
- package/src/services/__tests__/access-control.service.test.ts +14 -14
- 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 +11 -11
- 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 +31 -31
- 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 +4 -2
- package/src/services/oauth-provider-registry.ts +10 -5
- package/src/services/oauth-service.ts +30 -19
- package/src/services/oauth-token-retrieval.service.ts +8 -8
- package/src/services/provider-resolver.ts +7 -7
- package/src/services/session-registration.service.ts +10 -10
- package/src/services/tool-protection.service.ts +19 -19
- package/src/types/tool-protection.ts +13 -4
- package/vitest.config.mts +1 -1
|
@@ -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
|
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Tests the MCP-I provider-registry model where:
|
|
5
5
|
* - Client secrets are NOT sent via the API response
|
|
6
|
-
* - Agents receive metadata.clientSecretName from
|
|
6
|
+
* - Agents receive metadata.clientSecretName from Checkpoint
|
|
7
7
|
* - Secrets are resolved at runtime from secure storage
|
|
8
8
|
*
|
|
9
9
|
* @package @kya-os/mcp-i-core
|
|
@@ -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
|
});
|
|
@@ -416,7 +416,7 @@ describe("ProviderResolver - Edge Cases", () => {
|
|
|
416
416
|
await resolver.resolveProvider(toolProtection, "test-project");
|
|
417
417
|
} catch (error) {
|
|
418
418
|
const message = (error as Error).message;
|
|
419
|
-
expect(message).toContain("
|
|
419
|
+
expect(message).toContain("Checkpoint dashboard");
|
|
420
420
|
expect(message).toContain("Configure");
|
|
421
421
|
}
|
|
422
422
|
});
|
|
@@ -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
|
|
|
@@ -526,7 +526,7 @@ describe("ProviderResolver - Edge Cases", () => {
|
|
|
526
526
|
};
|
|
527
527
|
|
|
528
528
|
// Registry has providers but configuredProvider is null
|
|
529
|
-
// This simulates
|
|
529
|
+
// This simulates Checkpoint returning all providers but none configured
|
|
530
530
|
(mockRegistry.hasProvider as any).mockReturnValue(false);
|
|
531
531
|
(mockRegistry.getConfiguredProvider as any).mockReturnValue(null);
|
|
532
532
|
(mockRegistry.getAllProviders as any).mockReturnValue([
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tool Protection Service Tests
|
|
3
3
|
*
|
|
4
|
-
* Tests for fetching and caching tool protection configurations from
|
|
4
|
+
* Tests for fetching and caching tool protection configurations from Checkpoint API
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { describe, test, expect, beforeEach, vi, afterEach } from "vitest";
|
package/src/auth/types.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface VerifyDelegationResult {
|
|
|
19
19
|
/** The delegation record (if found) */
|
|
20
20
|
delegation?: DelegationRecord;
|
|
21
21
|
|
|
22
|
-
/** Credential from
|
|
22
|
+
/** Credential from Checkpoint API (includes authorization method) */
|
|
23
23
|
credential?: {
|
|
24
24
|
agent_did: string;
|
|
25
25
|
user_did: string;
|
|
@@ -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(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Remote Configuration Fetching
|
|
3
3
|
*
|
|
4
|
-
* Service for fetching configuration from remote APIs (
|
|
4
|
+
* Service for fetching configuration from remote APIs (Checkpoint dashboard)
|
|
5
5
|
* with caching support for performance optimization.
|
|
6
6
|
*
|
|
7
7
|
* C2 (#2916) classification: **product-layer, no DIF equivalent.** These are
|
|
@@ -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
|
/**
|
|
@@ -85,9 +85,9 @@ export interface RemoteConfigCache {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
-
* Fetch configuration from remote API (
|
|
88
|
+
* Fetch configuration from remote API (Checkpoint dashboard)
|
|
89
89
|
*
|
|
90
|
-
* Attempts to fetch configuration from the
|
|
90
|
+
* Attempts to fetch configuration from the Checkpoint API with caching support.
|
|
91
91
|
* Falls back gracefully if remote fetch fails.
|
|
92
92
|
*
|
|
93
93
|
* @param options - Remote config options
|
|
@@ -136,13 +136,13 @@ export async function fetchRemoteConfig(
|
|
|
136
136
|
console.error(
|
|
137
137
|
'[RemoteConfig] projectId is required for user-scoped delegation. ' +
|
|
138
138
|
'Agent-only scoping has been deprecated due to security concerns (cross-user delegation leakage). ' +
|
|
139
|
-
'Please configure
|
|
139
|
+
'Please configure CHECKPOINT_PROJECT_ID environment variable.'
|
|
140
140
|
);
|
|
141
141
|
return null;
|
|
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: {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Phase 5: Anonymous Sessions Until OAuth
|
|
7
7
|
* - Sessions start anonymous (no userDid) until OAuth completes
|
|
8
|
-
* - User DIDs are resolved via
|
|
8
|
+
* - User DIDs are resolved via Checkpoint identity/resolve after OAuth
|
|
9
9
|
* - Eliminates DID fragmentation (same user = same DID across sessions)
|
|
10
10
|
*
|
|
11
11
|
* DID Resolution Priority:
|
|
@@ -253,7 +253,7 @@ export class UserDidManager {
|
|
|
253
253
|
*
|
|
254
254
|
* @remarks
|
|
255
255
|
* - Phase 5: Sessions start anonymous, no ephemeral DID generation
|
|
256
|
-
* - User DIDs are resolved via
|
|
256
|
+
* - User DIDs are resolved via Checkpoint after OAuth completes
|
|
257
257
|
* - Returns null if no existing DID found (instead of generating ephemeral)
|
|
258
258
|
*/
|
|
259
259
|
async getOrCreateUserDid(
|
|
@@ -354,18 +354,18 @@ export class UserDidManager {
|
|
|
354
354
|
}
|
|
355
355
|
|
|
356
356
|
// PHASE 5: No ephemeral DID generation - session stays anonymous
|
|
357
|
-
// User DID will be resolved via
|
|
357
|
+
// User DID will be resolved via Checkpoint after OAuth completes
|
|
358
358
|
return null;
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
/**
|
|
362
362
|
* Set user DID for a session (Phase 5: After OAuth resolution)
|
|
363
363
|
*
|
|
364
|
-
* Called after
|
|
364
|
+
* Called after Checkpoint identity/resolve returns a persistent user DID.
|
|
365
365
|
* Caches the DID and optionally stores in session storage.
|
|
366
366
|
*
|
|
367
367
|
* @param sessionId - MCP session ID
|
|
368
|
-
* @param userDid - Persistent user DID from
|
|
368
|
+
* @param userDid - Persistent user DID from Checkpoint
|
|
369
369
|
* @param oauthIdentity - OAuth identity for creating persistent mappings
|
|
370
370
|
*/
|
|
371
371
|
async setUserDidForSession(
|
package/src/index.ts
CHANGED
|
@@ -48,6 +48,21 @@ export {
|
|
|
48
48
|
// C4 (#2918) 3c envelope flip — DelegationRequiredError → needs_authorization mapper.
|
|
49
49
|
export { toNeedsAuthorization } from "./runtime/needs-authorization";
|
|
50
50
|
|
|
51
|
+
// Verified delegation handed to protected tool handlers
|
|
52
|
+
export { toVerifiedDelegation } from "./runtime/verified-delegation";
|
|
53
|
+
export type { VerifiedDelegation } from "@kya-os/contracts/config";
|
|
54
|
+
|
|
55
|
+
// Verifier denial codes surfaced to clients and the audit ledger
|
|
56
|
+
export {
|
|
57
|
+
DEFAULT_DENIAL_MESSAGES,
|
|
58
|
+
nativeBindingDenial,
|
|
59
|
+
toDelegationDenial,
|
|
60
|
+
} from "./runtime/delegation-denial";
|
|
61
|
+
export type {
|
|
62
|
+
DelegationDenial,
|
|
63
|
+
DelegationDenialCode,
|
|
64
|
+
} from "./runtime/delegation-denial";
|
|
65
|
+
|
|
51
66
|
// Canonical KYA-OS audit trail integration
|
|
52
67
|
export {
|
|
53
68
|
RuntimeToolAuditInvocation,
|
package/src/runtime/audit.ts
CHANGED
|
@@ -6,6 +6,10 @@ import type {
|
|
|
6
6
|
AuthorizationEvidence,
|
|
7
7
|
PartyRef,
|
|
8
8
|
} from "@kya-os/mcp/audit" with { "resolution-mode": "import" };
|
|
9
|
+
// Type-only on purpose: package.json accepts contracts releases that predate
|
|
10
|
+
// the denial code list, so the known codes come from this package instead.
|
|
11
|
+
import type { DelegationDenialCode } from "@kya-os/contracts/config";
|
|
12
|
+
import { DEFAULT_DENIAL_MESSAGES } from "./delegation-denial.js";
|
|
9
13
|
|
|
10
14
|
const encoder = new TextEncoder();
|
|
11
15
|
const MAX_REFERENCE_LENGTH = 256;
|
|
@@ -584,8 +588,30 @@ export function terminalForToolResult(result: unknown): RuntimeToolTerminal {
|
|
|
584
588
|
return { phase: "failed", outcome: "failed", reasonCode: "HANDLER_ERROR_RESULT" };
|
|
585
589
|
}
|
|
586
590
|
|
|
591
|
+
// Read by shape, like the name checks below, because the error may come from
|
|
592
|
+
// another copy of this package. Only a known code counts as a denial.
|
|
593
|
+
function delegationDenialCode(error: unknown): DelegationDenialCode | undefined {
|
|
594
|
+
if (!isRecord(error) || !isRecord(error.denial)) return undefined;
|
|
595
|
+
const code = error.denial.code;
|
|
596
|
+
// Own keys only, so an inherited name such as "constructor" never matches.
|
|
597
|
+
return typeof code === "string" &&
|
|
598
|
+
Object.prototype.hasOwnProperty.call(DEFAULT_DENIAL_MESSAGES, code)
|
|
599
|
+
? (code as DelegationDenialCode)
|
|
600
|
+
: undefined;
|
|
601
|
+
}
|
|
602
|
+
|
|
587
603
|
export function terminalForToolError(error: unknown): RuntimeToolTerminal {
|
|
588
604
|
const name = error instanceof Error ? error.name : "UnknownError";
|
|
605
|
+
const denialCode =
|
|
606
|
+
name === "DelegationRequiredError" ? delegationDenialCode(error) : undefined;
|
|
607
|
+
if (denialCode !== undefined) {
|
|
608
|
+
// The verifier refused a presented grant: a denial, not a request for consent.
|
|
609
|
+
return {
|
|
610
|
+
phase: "denied",
|
|
611
|
+
outcome: "denied",
|
|
612
|
+
reasonCode: denialCode.toUpperCase(),
|
|
613
|
+
};
|
|
614
|
+
}
|
|
589
615
|
if (name === "DelegationRequiredError" || name === "OAuthRequiredError" ||
|
|
590
616
|
name === "AuthRequiredError") {
|
|
591
617
|
return {
|