@kya-os/mcp-i-runtime 1.0.0 → 1.2.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/config.d.ts +5 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -6
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime/audit-logger.d.ts +6 -28
- package/dist/runtime/audit-logger.d.ts.map +1 -1
- package/dist/runtime/audit-logger.js +5 -3
- package/dist/runtime/audit-logger.js.map +1 -1
- package/dist/runtime/audit.d.ts +132 -0
- package/dist/runtime/audit.d.ts.map +1 -0
- package/dist/runtime/audit.js +424 -0
- package/dist/runtime/audit.js.map +1 -0
- package/dist/runtime/base.d.ts +9 -48
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +109 -89
- package/dist/runtime/base.js.map +1 -1
- package/dist/runtime/needs-authorization.d.ts +33 -0
- package/dist/runtime/needs-authorization.d.ts.map +1 -0
- package/dist/runtime/needs-authorization.js +43 -0
- package/dist/runtime/needs-authorization.js.map +1 -0
- package/dist/services/oauth-config.service.d.ts.map +1 -1
- package/dist/services/oauth-config.service.js +29 -0
- package/dist/services/oauth-config.service.js.map +1 -1
- package/package.json +7 -3
- package/src/__tests__/config/provider-runtime-config.test.ts +2 -9
- package/src/__tests__/config.test.ts +12 -11
- package/src/__tests__/integration/full-flow.test.ts +0 -5
- package/src/__tests__/integration.test.ts +2 -6
- package/src/__tests__/runtime/audit.test.ts +327 -0
- package/src/__tests__/runtime/base-extensions.test.ts +0 -46
- package/src/__tests__/runtime/base.test.ts +71 -102
- package/src/__tests__/runtime/delegation-flow.test.ts +0 -4
- package/src/__tests__/runtime/process-tool-call-security.test.ts +5 -11
- package/src/__tests__/runtime/proof-client-did.test.ts +0 -4
- package/src/__tests__/runtime/provider-selection.test.ts +0 -2
- package/src/__tests__/runtime/route-interception.test.ts +7 -4
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +23 -31
- package/src/__tests__/services/tool-protection-merged-config.test.ts +0 -40
- package/src/config/__tests__/merged-config.spec.ts +0 -26
- package/src/config.ts +9 -10
- package/src/index.ts +30 -5
- package/src/runtime/__tests__/audit-logger-compat.test.ts +15 -0
- package/src/runtime/__tests__/needs-authorization.test.ts +41 -0
- package/src/runtime/audit-logger.ts +6 -29
- package/src/runtime/audit.ts +598 -0
- package/src/runtime/base.ts +154 -99
- package/src/runtime/needs-authorization.ts +47 -0
- package/src/services/__tests__/oauth-config.service.test.ts +66 -0
- package/src/services/__tests__/proof-verifier.integration.test.ts +1 -1
- package/src/services/__tests__/proof-verifier.test.ts +6 -3
- package/src/services/oauth-config.service.ts +44 -1
- package/src/__tests__/runtime/audit-logger.test.ts +0 -154
|
@@ -28,11 +28,6 @@ describe("MCPIRuntimeBase", () => {
|
|
|
28
28
|
timestampSkewSeconds: 120,
|
|
29
29
|
ttlMinutes: 30,
|
|
30
30
|
},
|
|
31
|
-
audit: {
|
|
32
|
-
enabled: true,
|
|
33
|
-
logFunction: vi.fn(),
|
|
34
|
-
includePayloads: true,
|
|
35
|
-
},
|
|
36
31
|
wellKnown: {
|
|
37
32
|
enabled: true,
|
|
38
33
|
serviceName: "Test Service",
|
|
@@ -75,24 +70,29 @@ describe("MCPIRuntimeBase", () => {
|
|
|
75
70
|
expect(initializeFn).toHaveBeenCalled();
|
|
76
71
|
});
|
|
77
72
|
|
|
78
|
-
it("should
|
|
73
|
+
it("should emit explicitly-labelled development diagnostics", async () => {
|
|
74
|
+
const diagnostic = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
79
75
|
await runtime.initialize();
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
expect.stringContaining("runtime_initialized")
|
|
76
|
+
expect(diagnostic).toHaveBeenCalledWith(
|
|
77
|
+
"[MCP-I diagnostic]",
|
|
78
|
+
expect.stringContaining("runtime_initialized"),
|
|
83
79
|
);
|
|
84
|
-
|
|
85
|
-
const logCall = (config.audit!.logFunction as any).mock.calls[0][0];
|
|
86
|
-
const logData = JSON.parse(logCall);
|
|
80
|
+
const logData = JSON.parse(diagnostic.mock.calls[0][1] as string);
|
|
87
81
|
expect(logData.event).toBe("runtime_initialized");
|
|
88
82
|
expect(logData.data.did).toBe("did:key:zmock123");
|
|
89
83
|
expect(logData.data.environment).toBe("development");
|
|
84
|
+
diagnostic.mockRestore();
|
|
90
85
|
});
|
|
91
86
|
|
|
92
|
-
it("should
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
87
|
+
it("should suppress diagnostics in production", async () => {
|
|
88
|
+
const diagnostic = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
89
|
+
const production = new MCPIRuntimeBase({ ...config, environment: "production" });
|
|
90
|
+
await production.initialize();
|
|
91
|
+
expect(diagnostic).not.toHaveBeenCalledWith(
|
|
92
|
+
"[MCP-I diagnostic]",
|
|
93
|
+
expect.any(String),
|
|
94
|
+
);
|
|
95
|
+
diagnostic.mockRestore();
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
98
|
|
|
@@ -131,10 +131,50 @@ describe("MCPIRuntimeBase", () => {
|
|
|
131
131
|
expect(response.timestamp).toBe(
|
|
132
132
|
(mockProviders.clockProvider as MockClockProvider).now()
|
|
133
133
|
);
|
|
134
|
-
expect(response.capabilities).toEqual(["identity", "proof"
|
|
134
|
+
expect(response.capabilities).toEqual(["identity", "proof"]);
|
|
135
|
+
expect(response.auditAssurance).toEqual({
|
|
136
|
+
enabled: false,
|
|
137
|
+
profile: "AAP-0",
|
|
138
|
+
});
|
|
135
139
|
expect(response.signature).toBeDefined();
|
|
136
140
|
});
|
|
137
141
|
|
|
142
|
+
it("should advertise only mechanically reported canonical audit assurance", async () => {
|
|
143
|
+
const capabilities = {
|
|
144
|
+
profile: "AAP-2" as const,
|
|
145
|
+
recorderTopology: "managed" as const,
|
|
146
|
+
delivery: "buffered" as const,
|
|
147
|
+
journalDurability: "durable" as const,
|
|
148
|
+
atomicAppend: true,
|
|
149
|
+
sourceHighWater: false,
|
|
150
|
+
merkleCheckpoints: false,
|
|
151
|
+
independentObservation: false,
|
|
152
|
+
supportingAnchors: [] as const,
|
|
153
|
+
evidenceRetention: "separate" as const,
|
|
154
|
+
};
|
|
155
|
+
config.auditTrail = {
|
|
156
|
+
sourceId: "source:test",
|
|
157
|
+
context: { create: vi.fn() },
|
|
158
|
+
trail: {
|
|
159
|
+
capabilities,
|
|
160
|
+
record: vi.fn(),
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const response = await runtime.handleHandshake(handshakeRequest);
|
|
165
|
+
|
|
166
|
+
expect(response.capabilities).toEqual([
|
|
167
|
+
"identity",
|
|
168
|
+
"proof",
|
|
169
|
+
"audit-trail",
|
|
170
|
+
]);
|
|
171
|
+
expect(response.auditAssurance).toEqual({
|
|
172
|
+
enabled: true,
|
|
173
|
+
profile: "AAP-2",
|
|
174
|
+
capabilities,
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
138
178
|
it("should store session internally", async () => {
|
|
139
179
|
const response = await runtime.handleHandshake(handshakeRequest);
|
|
140
180
|
const session = await runtime.getCurrentSession();
|
|
@@ -296,10 +336,11 @@ describe("MCPIRuntimeBase", () => {
|
|
|
296
336
|
expect(proof.audience).toBe("https://client.example.com");
|
|
297
337
|
});
|
|
298
338
|
|
|
299
|
-
it("should
|
|
339
|
+
it("should label tool execution output as a diagnostic, not an audit record", async () => {
|
|
300
340
|
const clock = mockProviders.clockProvider as MockClockProvider;
|
|
301
341
|
const currentTime = Date.now();
|
|
302
342
|
clock.setTime(currentTime);
|
|
343
|
+
const diagnostic = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
303
344
|
|
|
304
345
|
await runtime.processToolCall(
|
|
305
346
|
"testTool",
|
|
@@ -308,21 +349,19 @@ describe("MCPIRuntimeBase", () => {
|
|
|
308
349
|
session
|
|
309
350
|
);
|
|
310
351
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const logCalls = (config.audit!.logFunction as any).mock.calls;
|
|
315
|
-
const toolLogCall = logCalls.find((call: any[]) => {
|
|
316
|
-
const log = JSON.parse(call[0]);
|
|
352
|
+
const toolLogCall = diagnostic.mock.calls.find((call: any[]) => {
|
|
353
|
+
if (call[0] !== "[MCP-I diagnostic]") return false;
|
|
354
|
+
const log = JSON.parse(call[1]);
|
|
317
355
|
return log.event === "tool_executed";
|
|
318
356
|
});
|
|
319
357
|
|
|
320
358
|
expect(toolLogCall).toBeDefined();
|
|
321
|
-
const logData = JSON.parse(toolLogCall[
|
|
359
|
+
const logData = JSON.parse(toolLogCall![1]);
|
|
322
360
|
expect(logData.event).toBe("tool_executed");
|
|
323
361
|
expect(logData.data.tool).toBe("testTool");
|
|
324
362
|
expect(logData.data.sessionId).toBe("session123");
|
|
325
363
|
expect(logData.data.timestamp).toBe(currentTime);
|
|
364
|
+
diagnostic.mockRestore();
|
|
326
365
|
});
|
|
327
366
|
|
|
328
367
|
it("should handle tool handler errors", async () => {
|
|
@@ -879,25 +918,6 @@ describe("MCPIRuntimeBase", () => {
|
|
|
879
918
|
});
|
|
880
919
|
});
|
|
881
920
|
|
|
882
|
-
describe("getAuditLogger", () => {
|
|
883
|
-
it("should return audit logger", () => {
|
|
884
|
-
const logger = runtime.getAuditLogger();
|
|
885
|
-
expect(logger).toBeDefined();
|
|
886
|
-
expect(logger.log).toBeDefined();
|
|
887
|
-
});
|
|
888
|
-
|
|
889
|
-
it("should log through runtime audit", async () => {
|
|
890
|
-
await runtime.initialize();
|
|
891
|
-
const logger = runtime.getAuditLogger();
|
|
892
|
-
|
|
893
|
-
logger.log("test_event", { test: "data" });
|
|
894
|
-
|
|
895
|
-
expect(config.audit!.logFunction).toHaveBeenCalledWith(
|
|
896
|
-
expect.stringContaining("test_event")
|
|
897
|
-
);
|
|
898
|
-
});
|
|
899
|
-
});
|
|
900
|
-
|
|
901
921
|
describe("rotateKeys", () => {
|
|
902
922
|
beforeEach(async () => {
|
|
903
923
|
await runtime.initialize();
|
|
@@ -915,78 +935,30 @@ describe("MCPIRuntimeBase", () => {
|
|
|
915
935
|
expect(currentIdentity).toEqual(newIdentity);
|
|
916
936
|
});
|
|
917
937
|
|
|
918
|
-
it("should
|
|
938
|
+
it("should emit key rotation only as a development diagnostic", async () => {
|
|
919
939
|
const clock = mockProviders.clockProvider as MockClockProvider;
|
|
920
940
|
const currentTime = Date.now();
|
|
921
941
|
clock.setTime(currentTime);
|
|
942
|
+
const diagnostic = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
922
943
|
|
|
923
944
|
// Get the old identity first
|
|
924
945
|
const oldIdentity = await runtime.getIdentity();
|
|
925
946
|
|
|
926
947
|
await runtime.rotateKeys();
|
|
927
948
|
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
const logCalls = (config.audit!.logFunction as any).mock.calls;
|
|
932
|
-
const rotateLogCall = logCalls.find((call: any[]) => {
|
|
933
|
-
const log = JSON.parse(call[0]);
|
|
949
|
+
const rotateLogCall = diagnostic.mock.calls.find((call: any[]) => {
|
|
950
|
+
if (call[0] !== "[MCP-I diagnostic]") return false;
|
|
951
|
+
const log = JSON.parse(call[1]);
|
|
934
952
|
return log.event === "keys_rotated";
|
|
935
953
|
});
|
|
936
954
|
|
|
937
955
|
expect(rotateLogCall).toBeDefined();
|
|
938
|
-
const logData = JSON.parse(rotateLogCall[
|
|
956
|
+
const logData = JSON.parse(rotateLogCall![1]);
|
|
939
957
|
expect(logData.event).toBe("keys_rotated");
|
|
940
958
|
expect(logData.data.oldDid).toBe(oldIdentity.did);
|
|
941
959
|
expect(logData.data.newDid).toBe("did:key:zmock456-1");
|
|
942
960
|
expect(logData.data.timestamp).toBe(currentTime);
|
|
943
|
-
|
|
944
|
-
});
|
|
945
|
-
|
|
946
|
-
describe("audit logging", () => {
|
|
947
|
-
it("should use custom log function if provided", async () => {
|
|
948
|
-
await runtime.initialize();
|
|
949
|
-
expect(config.audit!.logFunction).toHaveBeenCalled();
|
|
950
|
-
});
|
|
951
|
-
|
|
952
|
-
it("should console.error if no custom function", async () => {
|
|
953
|
-
const consoleErrorSpy = vi
|
|
954
|
-
.spyOn(console, "error")
|
|
955
|
-
.mockImplementation(() => {});
|
|
956
|
-
|
|
957
|
-
config.audit!.logFunction = undefined;
|
|
958
|
-
const runtimeNoLogFn = new MCPIRuntimeBase(config);
|
|
959
|
-
await runtimeNoLogFn.initialize();
|
|
960
|
-
|
|
961
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
962
|
-
"[AUDIT]",
|
|
963
|
-
expect.any(String)
|
|
964
|
-
);
|
|
965
|
-
consoleErrorSpy.mockRestore();
|
|
966
|
-
});
|
|
967
|
-
|
|
968
|
-
it("should exclude payloads if configured", async () => {
|
|
969
|
-
config.audit!.includePayloads = false;
|
|
970
|
-
const runtimeNoPayloads = new MCPIRuntimeBase(config);
|
|
971
|
-
await runtimeNoPayloads.initialize();
|
|
972
|
-
|
|
973
|
-
const logCall = (config.audit!.logFunction as any).mock.calls[0][0];
|
|
974
|
-
const logData = JSON.parse(logCall);
|
|
975
|
-
expect(logData.data).toBeUndefined();
|
|
976
|
-
});
|
|
977
|
-
|
|
978
|
-
it("should include formatted timestamp", async () => {
|
|
979
|
-
const clock = mockProviders.clockProvider as MockClockProvider;
|
|
980
|
-
const currentTime = Date.now();
|
|
981
|
-
clock.setTime(currentTime);
|
|
982
|
-
|
|
983
|
-
await runtime.initialize();
|
|
984
|
-
|
|
985
|
-
const logCall = (config.audit!.logFunction as any).mock.calls[0][0];
|
|
986
|
-
const logData = JSON.parse(logCall);
|
|
987
|
-
expect(logData.timestampFormatted).toBe(
|
|
988
|
-
new Date(currentTime).toISOString()
|
|
989
|
-
);
|
|
961
|
+
diagnostic.mockRestore();
|
|
990
962
|
});
|
|
991
963
|
});
|
|
992
964
|
|
|
@@ -1050,9 +1022,6 @@ describe("MCPIRuntimeBase", () => {
|
|
|
1050
1022
|
timestampSkewSeconds: 120,
|
|
1051
1023
|
ttlMinutes: 30,
|
|
1052
1024
|
},
|
|
1053
|
-
audit: {
|
|
1054
|
-
enabled: false, // Disable audit for cleaner tests
|
|
1055
|
-
},
|
|
1056
1025
|
toolProtectionService: mockToolProtectionService,
|
|
1057
1026
|
};
|
|
1058
1027
|
|
|
@@ -27,9 +27,6 @@ describe("Delegation Verification Flow", () => {
|
|
|
27
27
|
timestampSkewSeconds: 120,
|
|
28
28
|
ttlMinutes: 30,
|
|
29
29
|
},
|
|
30
|
-
audit: {
|
|
31
|
-
enabled: false, // Disable audit for cleaner test output
|
|
32
|
-
},
|
|
33
30
|
};
|
|
34
31
|
runtime = new MCPIRuntimeBase(config);
|
|
35
32
|
await runtime.initialize();
|
|
@@ -156,4 +153,3 @@ describe("Delegation Verification Flow", () => {
|
|
|
156
153
|
expect(session?.serverDid).not.toBe(agentDid); // ✅ Should NOT match agent DID
|
|
157
154
|
});
|
|
158
155
|
});
|
|
159
|
-
|
|
@@ -89,9 +89,6 @@ describe("processToolCall Security", () => {
|
|
|
89
89
|
timestampSkewSeconds: 120,
|
|
90
90
|
ttlMinutes: 30,
|
|
91
91
|
},
|
|
92
|
-
audit: {
|
|
93
|
-
enabled: false,
|
|
94
|
-
},
|
|
95
92
|
toolProtectionService: mockToolProtectionService,
|
|
96
93
|
};
|
|
97
94
|
|
|
@@ -212,7 +209,6 @@ describe("processToolCall Security", () => {
|
|
|
212
209
|
const consoleSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
213
210
|
|
|
214
211
|
// Enable audit to trigger logging
|
|
215
|
-
config.audit = { enabled: true };
|
|
216
212
|
runtime = new MCPIRuntimeBase(config);
|
|
217
213
|
(runtime as any).accessControlService = mockAccessControlService;
|
|
218
214
|
await runtime.initialize();
|
|
@@ -506,11 +502,10 @@ describe("processToolCall Security", () => {
|
|
|
506
502
|
});
|
|
507
503
|
|
|
508
504
|
describe("Access Control Service Not Configured", () => {
|
|
509
|
-
it("
|
|
505
|
+
it("logs and fails closed when AccessControlService is unavailable", async () => {
|
|
510
506
|
const consoleSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
511
507
|
|
|
512
508
|
// Enable audit for logging
|
|
513
|
-
config.audit = { enabled: true };
|
|
514
509
|
runtime = new MCPIRuntimeBase(config);
|
|
515
510
|
// Don't inject accessControlService
|
|
516
511
|
(runtime as any).accessControlService = undefined;
|
|
@@ -525,17 +520,16 @@ describe("processToolCall Security", () => {
|
|
|
525
520
|
|
|
526
521
|
const toolHandler = vi.fn().mockResolvedValue({ result: "success" });
|
|
527
522
|
|
|
528
|
-
|
|
529
|
-
await runtime.processToolCall(
|
|
523
|
+
await expect(runtime.processToolCall(
|
|
530
524
|
"protected-tool",
|
|
531
525
|
{ arg: "value" },
|
|
532
526
|
toolHandler,
|
|
533
527
|
session
|
|
534
|
-
);
|
|
528
|
+
)).rejects.toThrow(DelegationRequiredError);
|
|
535
529
|
|
|
536
|
-
expect(toolHandler).toHaveBeenCalled();
|
|
530
|
+
expect(toolHandler).not.toHaveBeenCalled();
|
|
537
531
|
expect(consoleSpy).toHaveBeenCalledWith(
|
|
538
|
-
expect.stringContaining("
|
|
532
|
+
expect.stringContaining("Delegation verifier unavailable"),
|
|
539
533
|
expect.any(Object)
|
|
540
534
|
);
|
|
541
535
|
|
|
@@ -24,9 +24,6 @@ describe('MCPIRuntimeBase - Proof Client DID', () => {
|
|
|
24
24
|
timestampSkewSeconds: 120,
|
|
25
25
|
ttlMinutes: 30
|
|
26
26
|
},
|
|
27
|
-
audit: {
|
|
28
|
-
enabled: false
|
|
29
|
-
}
|
|
30
27
|
};
|
|
31
28
|
runtime = new MCPIRuntimeBase(config);
|
|
32
29
|
await runtime.initialize();
|
|
@@ -373,4 +370,3 @@ describe('MCPIRuntimeBase - Proof Client DID', () => {
|
|
|
373
370
|
});
|
|
374
371
|
});
|
|
375
372
|
});
|
|
376
|
-
|
|
@@ -44,7 +44,6 @@ describe("Provider Selection in Consent URLs", () => {
|
|
|
44
44
|
|
|
45
45
|
config = {
|
|
46
46
|
...mockProviders,
|
|
47
|
-
audit: { enabled: false },
|
|
48
47
|
toolProtectionService: mockToolProtectionService as any,
|
|
49
48
|
clock: new MockClockProvider(),
|
|
50
49
|
};
|
|
@@ -289,4 +288,3 @@ describe("Provider Selection in Consent URLs", () => {
|
|
|
289
288
|
});
|
|
290
289
|
});
|
|
291
290
|
});
|
|
292
|
-
|
|
@@ -33,12 +33,16 @@ describe('MCPIRuntimeBase - Route Interception', () => {
|
|
|
33
33
|
timestampSkewSeconds: 120,
|
|
34
34
|
ttlMinutes: 30
|
|
35
35
|
},
|
|
36
|
-
audit: {
|
|
37
|
-
enabled: false
|
|
38
|
-
},
|
|
39
36
|
toolProtectionService: mockToolProtectionService as any
|
|
40
37
|
};
|
|
41
38
|
runtime = new MCPIRuntimeBase(config);
|
|
39
|
+
(runtime as any).accessControlService = {
|
|
40
|
+
verifyDelegation: vi.fn().mockResolvedValue({
|
|
41
|
+
data: {
|
|
42
|
+
valid: true,
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
};
|
|
42
46
|
await runtime.initialize();
|
|
43
47
|
});
|
|
44
48
|
|
|
@@ -667,4 +671,3 @@ describe('MCPIRuntimeBase - Route Interception', () => {
|
|
|
667
671
|
});
|
|
668
672
|
});
|
|
669
673
|
});
|
|
670
|
-
|
|
@@ -43,11 +43,6 @@ describe("MCPIRuntimeBase - Tool Protection Enforcement", () => {
|
|
|
43
43
|
timestampSkewSeconds: 120,
|
|
44
44
|
ttlMinutes: 30,
|
|
45
45
|
},
|
|
46
|
-
audit: {
|
|
47
|
-
enabled: true,
|
|
48
|
-
logFunction: vi.fn(),
|
|
49
|
-
includePayloads: true,
|
|
50
|
-
},
|
|
51
46
|
toolProtectionService: mockToolProtectionService as any,
|
|
52
47
|
};
|
|
53
48
|
runtime = new MCPIRuntimeBase(config);
|
|
@@ -306,7 +301,7 @@ describe("MCPIRuntimeBase - Tool Protection Enforcement", () => {
|
|
|
306
301
|
expect(mockHandler).not.toHaveBeenCalled();
|
|
307
302
|
});
|
|
308
303
|
|
|
309
|
-
it("
|
|
304
|
+
it("fails closed when access control service is not configured", async () => {
|
|
310
305
|
mockToolProtectionService.checkToolProtection.mockResolvedValue({
|
|
311
306
|
requiresDelegation: true,
|
|
312
307
|
requiredScopes: ["files:write"],
|
|
@@ -320,16 +315,14 @@ describe("MCPIRuntimeBase - Tool Protection Enforcement", () => {
|
|
|
320
315
|
delegationToken: "valid-delegation-token",
|
|
321
316
|
};
|
|
322
317
|
|
|
323
|
-
|
|
324
|
-
const result = await runtime.processToolCall(
|
|
318
|
+
await expect(runtime.processToolCall(
|
|
325
319
|
"protectedTool",
|
|
326
320
|
{ arg: "value" },
|
|
327
321
|
mockHandler,
|
|
328
322
|
sessionWithDelegation
|
|
329
|
-
);
|
|
323
|
+
)).rejects.toThrow(DelegationRequiredError);
|
|
330
324
|
|
|
331
|
-
expect(mockHandler).
|
|
332
|
-
expect(result).toEqual({ result: "success" });
|
|
325
|
+
expect(mockHandler).not.toHaveBeenCalled();
|
|
333
326
|
});
|
|
334
327
|
|
|
335
328
|
describe("user_identifier validation", () => {
|
|
@@ -748,7 +741,7 @@ describe("MCPIRuntimeBase - Tool Protection Enforcement", () => {
|
|
|
748
741
|
});
|
|
749
742
|
});
|
|
750
743
|
|
|
751
|
-
describe("
|
|
744
|
+
describe("development diagnostics", () => {
|
|
752
745
|
const mockHandler = vi.fn().mockResolvedValue({ result: "success" });
|
|
753
746
|
const session = {
|
|
754
747
|
id: "session123",
|
|
@@ -756,8 +749,9 @@ describe("MCPIRuntimeBase - Tool Protection Enforcement", () => {
|
|
|
756
749
|
nonce: "test-nonce",
|
|
757
750
|
};
|
|
758
751
|
|
|
759
|
-
it("should
|
|
752
|
+
it("should label tool execution as a diagnostic", async () => {
|
|
760
753
|
mockToolProtectionService.checkToolProtection.mockResolvedValue(null);
|
|
754
|
+
const diagnostic = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
761
755
|
|
|
762
756
|
await runtime.processToolCall(
|
|
763
757
|
"testTool",
|
|
@@ -766,20 +760,20 @@ describe("MCPIRuntimeBase - Tool Protection Enforcement", () => {
|
|
|
766
760
|
session
|
|
767
761
|
);
|
|
768
762
|
|
|
769
|
-
|
|
770
|
-
const logCalls = (config.audit!.logFunction as any).mock.calls;
|
|
771
|
-
const protectionLogCall = logCalls.find((call: any[]) => {
|
|
763
|
+
const protectionLogCall = diagnostic.mock.calls.find((call: any[]) => {
|
|
772
764
|
try {
|
|
773
|
-
|
|
765
|
+
if (call[0] !== "[MCP-I diagnostic]") return false;
|
|
766
|
+
const log = JSON.parse(call[1]);
|
|
774
767
|
return log.event === "tool_executed";
|
|
775
768
|
} catch {
|
|
776
769
|
return false;
|
|
777
770
|
}
|
|
778
771
|
});
|
|
779
772
|
expect(protectionLogCall).toBeDefined();
|
|
773
|
+
diagnostic.mockRestore();
|
|
780
774
|
});
|
|
781
775
|
|
|
782
|
-
it("should
|
|
776
|
+
it("should emit a development warning for a blocked tool call", async () => {
|
|
783
777
|
mockToolProtectionService.checkToolProtection.mockResolvedValue({
|
|
784
778
|
requiresDelegation: true,
|
|
785
779
|
requiredScopes: ["files:write"],
|
|
@@ -808,37 +802,35 @@ describe("MCPIRuntimeBase - Tool Protection Enforcement", () => {
|
|
|
808
802
|
consoleWarnSpy.mockRestore();
|
|
809
803
|
});
|
|
810
804
|
|
|
811
|
-
it("should
|
|
812
|
-
const
|
|
813
|
-
const
|
|
805
|
+
it("should suppress diagnostic tool output in production", async () => {
|
|
806
|
+
const diagnostic = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
807
|
+
const productionConfig = {
|
|
814
808
|
...config,
|
|
815
|
-
|
|
816
|
-
enabled: false,
|
|
817
|
-
logFunction: auditLogFn,
|
|
818
|
-
},
|
|
809
|
+
environment: "production" as const,
|
|
819
810
|
};
|
|
820
|
-
const
|
|
821
|
-
await
|
|
811
|
+
const productionRuntime = new MCPIRuntimeBase(productionConfig);
|
|
812
|
+
await productionRuntime.initialize();
|
|
822
813
|
|
|
823
814
|
mockToolProtectionService.checkToolProtection.mockResolvedValue(null);
|
|
824
815
|
|
|
825
|
-
await
|
|
816
|
+
await productionRuntime.processToolCall(
|
|
826
817
|
"testTool",
|
|
827
818
|
{ arg: "value" },
|
|
828
819
|
mockHandler,
|
|
829
820
|
session
|
|
830
821
|
);
|
|
831
822
|
|
|
832
|
-
|
|
833
|
-
const toolExecutionLogs = auditLogFn.mock.calls.filter((call: any[]) => {
|
|
823
|
+
const toolExecutionLogs = diagnostic.mock.calls.filter((call: any[]) => {
|
|
834
824
|
try {
|
|
835
|
-
|
|
825
|
+
if (call[0] !== "[MCP-I diagnostic]") return false;
|
|
826
|
+
const log = JSON.parse(call[1]);
|
|
836
827
|
return log.event === "tool_executed";
|
|
837
828
|
} catch {
|
|
838
829
|
return false;
|
|
839
830
|
}
|
|
840
831
|
});
|
|
841
832
|
expect(toolExecutionLogs.length).toBe(0);
|
|
833
|
+
diagnostic.mockRestore();
|
|
842
834
|
});
|
|
843
835
|
});
|
|
844
836
|
|
|
@@ -90,11 +90,6 @@ describe("ToolProtectionService - Merged Config API", () => {
|
|
|
90
90
|
},
|
|
91
91
|
},
|
|
92
92
|
},
|
|
93
|
-
audit: {
|
|
94
|
-
enabled: true,
|
|
95
|
-
includeProofHashes: true,
|
|
96
|
-
includePayloads: false,
|
|
97
|
-
},
|
|
98
93
|
session: { timestampSkewSeconds: 120, ttlMinutes: 30 },
|
|
99
94
|
platform: { type: "cloudflare" },
|
|
100
95
|
metadata: {
|
|
@@ -176,11 +171,6 @@ describe("ToolProtectionService - Merged Config API", () => {
|
|
|
176
171
|
},
|
|
177
172
|
},
|
|
178
173
|
},
|
|
179
|
-
audit: {
|
|
180
|
-
enabled: false,
|
|
181
|
-
includeProofHashes: false,
|
|
182
|
-
includePayloads: false,
|
|
183
|
-
},
|
|
184
174
|
session: { timestampSkewSeconds: 120, ttlMinutes: 30 },
|
|
185
175
|
platform: { type: "node" },
|
|
186
176
|
metadata: {
|
|
@@ -236,11 +226,6 @@ describe("ToolProtectionService - Merged Config API", () => {
|
|
|
236
226
|
source: "agentshield",
|
|
237
227
|
tools: {}, // No tools discovered yet
|
|
238
228
|
},
|
|
239
|
-
audit: {
|
|
240
|
-
enabled: false,
|
|
241
|
-
includeProofHashes: false,
|
|
242
|
-
includePayloads: false,
|
|
243
|
-
},
|
|
244
229
|
session: { timestampSkewSeconds: 120, ttlMinutes: 30 },
|
|
245
230
|
platform: { type: "node" },
|
|
246
231
|
metadata: {
|
|
@@ -304,11 +289,6 @@ describe("ToolProtectionService - Merged Config API", () => {
|
|
|
304
289
|
},
|
|
305
290
|
},
|
|
306
291
|
},
|
|
307
|
-
audit: {
|
|
308
|
-
enabled: false,
|
|
309
|
-
includeProofHashes: false,
|
|
310
|
-
includePayloads: false,
|
|
311
|
-
},
|
|
312
292
|
session: { timestampSkewSeconds: 120, ttlMinutes: 30 },
|
|
313
293
|
platform: { type: "cloudflare" },
|
|
314
294
|
metadata: {
|
|
@@ -376,11 +356,6 @@ describe("ToolProtectionService - Merged Config API", () => {
|
|
|
376
356
|
greet: { requiresDelegation: false, requiredScopes: [] },
|
|
377
357
|
},
|
|
378
358
|
},
|
|
379
|
-
audit: {
|
|
380
|
-
enabled: false,
|
|
381
|
-
includeProofHashes: false,
|
|
382
|
-
includePayloads: false,
|
|
383
|
-
},
|
|
384
359
|
session: { timestampSkewSeconds: 120, ttlMinutes: 30 },
|
|
385
360
|
platform: { type: "node" },
|
|
386
361
|
metadata: {
|
|
@@ -475,11 +450,6 @@ describe("ToolProtectionService - Merged Config API", () => {
|
|
|
475
450
|
source: "agentshield",
|
|
476
451
|
// No tools field - old format
|
|
477
452
|
},
|
|
478
|
-
audit: {
|
|
479
|
-
enabled: false,
|
|
480
|
-
includeProofHashes: false,
|
|
481
|
-
includePayloads: false,
|
|
482
|
-
},
|
|
483
453
|
session: { timestampSkewSeconds: 120, ttlMinutes: 30 },
|
|
484
454
|
platform: { type: "node" },
|
|
485
455
|
metadata: {
|
|
@@ -552,11 +522,6 @@ describe("ToolProtectionService - Merged Config API", () => {
|
|
|
552
522
|
},
|
|
553
523
|
},
|
|
554
524
|
},
|
|
555
|
-
audit: {
|
|
556
|
-
enabled: false,
|
|
557
|
-
includeProofHashes: false,
|
|
558
|
-
includePayloads: false,
|
|
559
|
-
},
|
|
560
525
|
session: { timestampSkewSeconds: 120, ttlMinutes: 30 },
|
|
561
526
|
platform: { type: "node" },
|
|
562
527
|
metadata: {
|
|
@@ -617,11 +582,6 @@ describe("ToolProtectionService - Merged Config API", () => {
|
|
|
617
582
|
},
|
|
618
583
|
},
|
|
619
584
|
},
|
|
620
|
-
audit: {
|
|
621
|
-
enabled: false,
|
|
622
|
-
includeProofHashes: false,
|
|
623
|
-
includePayloads: false,
|
|
624
|
-
},
|
|
625
585
|
session: { timestampSkewSeconds: 120, ttlMinutes: 30 },
|
|
626
586
|
platform: { type: "node" },
|
|
627
587
|
metadata: {
|
|
@@ -65,11 +65,6 @@ describe('fetchRemoteConfig - Merged Config Format', () => {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
|
-
audit: {
|
|
69
|
-
enabled: true,
|
|
70
|
-
includeProofHashes: true,
|
|
71
|
-
includePayloads: false
|
|
72
|
-
},
|
|
73
68
|
session: {
|
|
74
69
|
timestampSkewSeconds: 120,
|
|
75
70
|
ttlMinutes: 30
|
|
@@ -140,11 +135,6 @@ describe('fetchRemoteConfig - Merged Config Format', () => {
|
|
|
140
135
|
source: 'agentshield',
|
|
141
136
|
tools: {} // Empty - no tools discovered yet
|
|
142
137
|
},
|
|
143
|
-
audit: {
|
|
144
|
-
enabled: false,
|
|
145
|
-
includeProofHashes: false,
|
|
146
|
-
includePayloads: false
|
|
147
|
-
},
|
|
148
138
|
session: {
|
|
149
139
|
timestampSkewSeconds: 120,
|
|
150
140
|
ttlMinutes: 30
|
|
@@ -205,11 +195,6 @@ describe('fetchRemoteConfig - Merged Config Format', () => {
|
|
|
205
195
|
source: 'agentshield'
|
|
206
196
|
// No tools field - old format
|
|
207
197
|
},
|
|
208
|
-
audit: {
|
|
209
|
-
enabled: false,
|
|
210
|
-
includeProofHashes: false,
|
|
211
|
-
includePayloads: false
|
|
212
|
-
},
|
|
213
198
|
session: {
|
|
214
199
|
timestampSkewSeconds: 120,
|
|
215
200
|
ttlMinutes: 30
|
|
@@ -275,11 +260,6 @@ describe('fetchRemoteConfig - Merged Config Format', () => {
|
|
|
275
260
|
greet: { requiresDelegation: true, requiredScopes: ['greeting:write'] }
|
|
276
261
|
}
|
|
277
262
|
},
|
|
278
|
-
audit: {
|
|
279
|
-
enabled: false,
|
|
280
|
-
includeProofHashes: false,
|
|
281
|
-
includePayloads: false
|
|
282
|
-
},
|
|
283
263
|
session: {
|
|
284
264
|
timestampSkewSeconds: 120,
|
|
285
265
|
ttlMinutes: 30
|
|
@@ -358,11 +338,6 @@ describe('fetchRemoteConfig - Merged Config Format', () => {
|
|
|
358
338
|
greet: { requiresDelegation: true, requiredScopes: ['greeting:write'] }
|
|
359
339
|
}
|
|
360
340
|
},
|
|
361
|
-
audit: {
|
|
362
|
-
enabled: false,
|
|
363
|
-
includeProofHashes: false,
|
|
364
|
-
includePayloads: false
|
|
365
|
-
},
|
|
366
341
|
session: {
|
|
367
342
|
timestampSkewSeconds: 120,
|
|
368
343
|
ttlMinutes: 30
|
|
@@ -442,4 +417,3 @@ describe('fetchRemoteConfig - Merged Config Format', () => {
|
|
|
442
417
|
});
|
|
443
418
|
});
|
|
444
419
|
});
|
|
445
|
-
|