@google/gemini-cli-core 0.35.0-preview.2 → 0.36.0-nightly.20260318.e2658ccda
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/dist/docs/changelogs/latest.md +6 -3
- package/dist/docs/changelogs/preview.md +7 -3
- package/dist/docs/reference/configuration.md +191 -8
- package/dist/docs/tools/todos.md +2 -1
- package/dist/{google-gemini-cli-core-0.35.0-preview.1.tgz → google-gemini-cli-core-0.36.0-nightly.20260317.2f90b4653.tgz} +0 -0
- package/dist/src/agents/a2a-client-manager.d.ts +2 -11
- package/dist/src/agents/a2a-client-manager.js +3 -19
- package/dist/src/agents/a2a-client-manager.js.map +1 -1
- package/dist/src/agents/a2a-client-manager.test.js +6 -10
- package/dist/src/agents/a2a-client-manager.test.js.map +1 -1
- package/dist/src/agents/registry.js +6 -3
- package/dist/src/agents/registry.js.map +1 -1
- package/dist/src/agents/registry.test.js +23 -24
- package/dist/src/agents/registry.test.js.map +1 -1
- package/dist/src/agents/remote-invocation.d.ts +3 -1
- package/dist/src/agents/remote-invocation.js +10 -5
- package/dist/src/agents/remote-invocation.js.map +1 -1
- package/dist/src/agents/remote-invocation.test.js +64 -41
- package/dist/src/agents/remote-invocation.test.js.map +1 -1
- package/dist/src/agents/subagent-tool-wrapper.js +1 -1
- package/dist/src/agents/subagent-tool-wrapper.js.map +1 -1
- package/dist/src/config/config.d.ts +6 -0
- package/dist/src/config/config.js +35 -6
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +4 -1
- package/dist/src/config/config.test.js.map +1 -1
- package/dist/src/config/defaultModelConfigs.js +120 -8
- package/dist/src/config/defaultModelConfigs.js.map +1 -1
- package/dist/src/config/models.d.ts +13 -2
- package/dist/src/config/models.js +20 -3
- package/dist/src/config/models.js.map +1 -1
- package/dist/src/config/models.test.js +52 -0
- package/dist/src/config/models.test.js.map +1 -1
- package/dist/src/core/client.js +1 -1
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/contentGenerator.js +1 -1
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/geminiChat.js +2 -2
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/prompts.test.js +8 -0
- package/dist/src/core/prompts.test.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +2 -2
- package/dist/src/generated/git-commit.js +2 -2
- package/dist/src/generated/git-commit.js.map +1 -1
- package/dist/src/policy/policy-engine.test.js +3 -3
- package/dist/src/policy/policy-engine.test.js.map +1 -1
- package/dist/src/policy/types.d.ts +5 -0
- package/dist/src/policy/types.js +5 -0
- package/dist/src/policy/types.js.map +1 -1
- package/dist/src/prompts/promptProvider.js +3 -3
- package/dist/src/prompts/promptProvider.js.map +1 -1
- package/dist/src/prompts/snippets.legacy.d.ts +4 -0
- package/dist/src/prompts/snippets.legacy.js +25 -1
- package/dist/src/prompts/snippets.legacy.js.map +1 -1
- package/dist/src/routing/strategies/classifierStrategy.js +1 -1
- package/dist/src/routing/strategies/classifierStrategy.js.map +1 -1
- package/dist/src/routing/strategies/defaultStrategy.js +1 -1
- package/dist/src/routing/strategies/defaultStrategy.js.map +1 -1
- package/dist/src/routing/strategies/fallbackStrategy.js +1 -1
- package/dist/src/routing/strategies/fallbackStrategy.js.map +1 -1
- package/dist/src/routing/strategies/numericalClassifierStrategy.js +1 -1
- package/dist/src/routing/strategies/numericalClassifierStrategy.js.map +1 -1
- package/dist/src/routing/strategies/overrideStrategy.js +1 -1
- package/dist/src/routing/strategies/overrideStrategy.js.map +1 -1
- package/dist/src/services/modelConfigService.d.ts +28 -1
- package/dist/src/services/modelConfigService.js +48 -0
- package/dist/src/services/modelConfigService.js.map +1 -1
- package/dist/src/services/trackerTypes.d.ts +1 -0
- package/dist/src/services/trackerTypes.js +1 -0
- package/dist/src/services/trackerTypes.js.map +1 -1
- package/dist/src/tools/definitions/model-family-sets/default-legacy.js +8 -1
- package/dist/src/tools/definitions/model-family-sets/default-legacy.js.map +1 -1
- package/dist/src/tools/definitions/model-family-sets/gemini-3.js +8 -1
- package/dist/src/tools/definitions/model-family-sets/gemini-3.js.map +1 -1
- package/dist/src/tools/mcp-client-manager.d.ts +22 -3
- package/dist/src/tools/mcp-client-manager.js +84 -32
- package/dist/src/tools/mcp-client-manager.js.map +1 -1
- package/dist/src/tools/mcp-client-manager.test.js +76 -56
- package/dist/src/tools/mcp-client-manager.test.js.map +1 -1
- package/dist/src/tools/mcp-client.d.ts +15 -6
- package/dist/src/tools/mcp-client.js +85 -71
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +195 -88
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/tool-registry.d.ts +2 -1
- package/dist/src/tools/tool-registry.js +12 -1
- package/dist/src/tools/tool-registry.js.map +1 -1
- package/dist/src/tools/tool-registry.test.js +15 -0
- package/dist/src/tools/tool-registry.test.js.map +1 -1
- package/dist/src/tools/tools.d.ts +1 -1
- package/dist/src/tools/tools.js.map +1 -1
- package/dist/src/tools/trackerTools.js +6 -1
- package/dist/src/tools/trackerTools.js.map +1 -1
- package/dist/src/tools/trackerTools.test.js +9 -1
- package/dist/src/tools/trackerTools.test.js.map +1 -1
- package/dist/src/tools/write-todos.js +1 -0
- package/dist/src/tools/write-todos.js.map +1 -1
- package/dist/src/tools/write-todos.test.js +4 -1
- package/dist/src/tools/write-todos.test.js.map +1 -1
- package/dist/src/utils/compatibility.d.ts +16 -0
- package/dist/src/utils/compatibility.js +58 -9
- package/dist/src/utils/compatibility.js.map +1 -1
- package/dist/src/utils/compatibility.test.js +127 -29
- package/dist/src/utils/compatibility.test.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.js +11 -19
- package/dist/src/utils/memoryDiscovery.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.test.js +15 -47
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
6
7
|
import * as ClientLib from '@modelcontextprotocol/sdk/client/index.js';
|
|
7
8
|
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
8
9
|
import * as SdkClientStdioLib from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
@@ -112,9 +113,13 @@ describe('mcp-client', () => {
|
|
|
112
113
|
};
|
|
113
114
|
const client = new McpClient('test-server', {
|
|
114
115
|
command: 'test-command',
|
|
115
|
-
},
|
|
116
|
+
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
116
117
|
await client.connect();
|
|
117
|
-
await client.
|
|
118
|
+
await client.discoverInto(MOCK_CONTEXT, {
|
|
119
|
+
toolRegistry: mockedToolRegistry,
|
|
120
|
+
promptRegistry,
|
|
121
|
+
resourceRegistry,
|
|
122
|
+
});
|
|
118
123
|
expect(mockedClient.listTools).toHaveBeenCalledWith({}, expect.objectContaining({ timeout: 600000, progressReporter: client }));
|
|
119
124
|
});
|
|
120
125
|
it('should not skip tools even if a parameter is missing a type', async () => {
|
|
@@ -177,9 +182,13 @@ describe('mcp-client', () => {
|
|
|
177
182
|
};
|
|
178
183
|
const client = new McpClient('test-server', {
|
|
179
184
|
command: 'test-command',
|
|
180
|
-
},
|
|
185
|
+
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
181
186
|
await client.connect();
|
|
182
|
-
await client.
|
|
187
|
+
await client.discoverInto(MOCK_CONTEXT, {
|
|
188
|
+
toolRegistry: mockedToolRegistry,
|
|
189
|
+
promptRegistry,
|
|
190
|
+
resourceRegistry,
|
|
191
|
+
});
|
|
183
192
|
expect(mockedToolRegistry.registerTool).toHaveBeenCalledTimes(2);
|
|
184
193
|
expect(consoleWarnSpy).not.toHaveBeenCalled();
|
|
185
194
|
consoleWarnSpy.mockRestore();
|
|
@@ -214,9 +223,13 @@ describe('mcp-client', () => {
|
|
|
214
223
|
};
|
|
215
224
|
const client = new McpClient('test-server', {
|
|
216
225
|
command: 'test-command',
|
|
217
|
-
},
|
|
226
|
+
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
218
227
|
await client.connect();
|
|
219
|
-
await expect(client.
|
|
228
|
+
await expect(client.discoverInto(MOCK_CONTEXT, {
|
|
229
|
+
toolRegistry: mockedToolRegistry,
|
|
230
|
+
promptRegistry,
|
|
231
|
+
resourceRegistry,
|
|
232
|
+
})).rejects.toThrow('Test error');
|
|
220
233
|
expect(MOCK_CONTEXT.emitMcpDiagnostic).toHaveBeenCalledWith('error', `Error discovering prompts from test-server: Test error`, expect.any(Error), 'test-server');
|
|
221
234
|
});
|
|
222
235
|
it('should not discover tools if server does not support them', async () => {
|
|
@@ -252,9 +265,13 @@ describe('mcp-client', () => {
|
|
|
252
265
|
};
|
|
253
266
|
const client = new McpClient('test-server', {
|
|
254
267
|
command: 'test-command',
|
|
255
|
-
},
|
|
268
|
+
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
256
269
|
await client.connect();
|
|
257
|
-
await expect(client.
|
|
270
|
+
await expect(client.discoverInto(MOCK_CONTEXT, {
|
|
271
|
+
toolRegistry: mockedToolRegistry,
|
|
272
|
+
promptRegistry,
|
|
273
|
+
resourceRegistry,
|
|
274
|
+
})).rejects.toThrow('No prompts, tools, or resources found on the server.');
|
|
258
275
|
});
|
|
259
276
|
it('should discover tools if server supports them', async () => {
|
|
260
277
|
const mockedClient = {
|
|
@@ -298,9 +315,13 @@ describe('mcp-client', () => {
|
|
|
298
315
|
};
|
|
299
316
|
const client = new McpClient('test-server', {
|
|
300
317
|
command: 'test-command',
|
|
301
|
-
},
|
|
318
|
+
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
302
319
|
await client.connect();
|
|
303
|
-
await client.
|
|
320
|
+
await client.discoverInto(MOCK_CONTEXT, {
|
|
321
|
+
toolRegistry: mockedToolRegistry,
|
|
322
|
+
promptRegistry,
|
|
323
|
+
resourceRegistry,
|
|
324
|
+
});
|
|
304
325
|
expect(mockedToolRegistry.registerTool).toHaveBeenCalledOnce();
|
|
305
326
|
});
|
|
306
327
|
it('should register tool with readOnlyHint and preserve annotations', async () => {
|
|
@@ -348,9 +369,13 @@ describe('mcp-client', () => {
|
|
|
348
369
|
setResourcesForServer: vi.fn(),
|
|
349
370
|
removeResourcesByServer: vi.fn(),
|
|
350
371
|
};
|
|
351
|
-
const client = new McpClient('test-server', { command: 'test-command' },
|
|
372
|
+
const client = new McpClient('test-server', { command: 'test-command' }, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
352
373
|
await client.connect();
|
|
353
|
-
await client.
|
|
374
|
+
await client.discoverInto(mockConfig, {
|
|
375
|
+
toolRegistry: mockedToolRegistry,
|
|
376
|
+
promptRegistry,
|
|
377
|
+
resourceRegistry,
|
|
378
|
+
});
|
|
354
379
|
// Verify tool registration
|
|
355
380
|
expect(mockedToolRegistry.registerTool).toHaveBeenCalledOnce();
|
|
356
381
|
// Verify addRule is NOT called (annotation-based rules are in plan.toml now)
|
|
@@ -405,9 +430,13 @@ describe('mcp-client', () => {
|
|
|
405
430
|
setResourcesForServer: vi.fn(),
|
|
406
431
|
removeResourcesByServer: vi.fn(),
|
|
407
432
|
};
|
|
408
|
-
const client = new McpClient('test-server', { command: 'test-command' },
|
|
433
|
+
const client = new McpClient('test-server', { command: 'test-command' }, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
409
434
|
await client.connect();
|
|
410
|
-
await client.
|
|
435
|
+
await client.discoverInto(mockConfig, {
|
|
436
|
+
toolRegistry: mockedToolRegistry,
|
|
437
|
+
promptRegistry,
|
|
438
|
+
resourceRegistry,
|
|
439
|
+
});
|
|
411
440
|
expect(mockedToolRegistry.registerTool).toHaveBeenCalledOnce();
|
|
412
441
|
expect(mockPolicyEngine.addRule).not.toHaveBeenCalled();
|
|
413
442
|
// Verify annotations are undefined for tools without annotations
|
|
@@ -460,9 +489,13 @@ describe('mcp-client', () => {
|
|
|
460
489
|
setResourcesForServer: vi.fn(),
|
|
461
490
|
removeResourcesByServer: vi.fn(),
|
|
462
491
|
};
|
|
463
|
-
const client = new McpClient('test-server', { command: 'test-command' },
|
|
492
|
+
const client = new McpClient('test-server', { command: 'test-command' }, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
464
493
|
await client.connect();
|
|
465
|
-
await client.
|
|
494
|
+
await client.discoverInto(mockConfig, {
|
|
495
|
+
toolRegistry: mockedToolRegistry,
|
|
496
|
+
promptRegistry,
|
|
497
|
+
resourceRegistry,
|
|
498
|
+
});
|
|
466
499
|
expect(mockedToolRegistry.registerTool).toHaveBeenCalledOnce();
|
|
467
500
|
const registeredTool = mockedToolRegistry.registerTool.mock.calls[0][0];
|
|
468
501
|
expect(registeredTool.toolAnnotations).toEqual({
|
|
@@ -529,9 +562,13 @@ describe('mcp-client', () => {
|
|
|
529
562
|
};
|
|
530
563
|
const client = new McpClient('test-server', {
|
|
531
564
|
command: 'test-command',
|
|
532
|
-
},
|
|
565
|
+
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
533
566
|
await client.connect();
|
|
534
|
-
await client.
|
|
567
|
+
await client.discoverInto(MOCK_CONTEXT, {
|
|
568
|
+
toolRegistry: mockedToolRegistry,
|
|
569
|
+
promptRegistry,
|
|
570
|
+
resourceRegistry,
|
|
571
|
+
});
|
|
535
572
|
expect(mockedToolRegistry.registerTool).toHaveBeenCalledOnce();
|
|
536
573
|
const registeredTool = vi.mocked(mockedToolRegistry.registerTool).mock
|
|
537
574
|
.calls[0][0];
|
|
@@ -600,9 +637,13 @@ describe('mcp-client', () => {
|
|
|
600
637
|
};
|
|
601
638
|
const client = new McpClient('test-server', {
|
|
602
639
|
command: 'test-command',
|
|
603
|
-
},
|
|
640
|
+
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
604
641
|
await client.connect();
|
|
605
|
-
await client.
|
|
642
|
+
await client.discoverInto(MOCK_CONTEXT, {
|
|
643
|
+
toolRegistry: mockedToolRegistry,
|
|
644
|
+
promptRegistry,
|
|
645
|
+
resourceRegistry,
|
|
646
|
+
});
|
|
606
647
|
expect(resourceRegistry.setResourcesForServer).toHaveBeenCalledWith('test-server', [
|
|
607
648
|
expect.objectContaining({
|
|
608
649
|
uri: 'file:///tmp/resource.txt',
|
|
@@ -671,9 +712,13 @@ describe('mcp-client', () => {
|
|
|
671
712
|
};
|
|
672
713
|
const client = new McpClient('test-server', {
|
|
673
714
|
command: 'test-command',
|
|
674
|
-
},
|
|
715
|
+
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
675
716
|
await client.connect();
|
|
676
|
-
await client.
|
|
717
|
+
await client.discoverInto(MOCK_CONTEXT, {
|
|
718
|
+
toolRegistry: mockedToolRegistry,
|
|
719
|
+
promptRegistry,
|
|
720
|
+
resourceRegistry,
|
|
721
|
+
});
|
|
677
722
|
expect(mockedClient.setNotificationHandler).toHaveBeenCalledTimes(2);
|
|
678
723
|
expect(resourceListHandler).toBeDefined();
|
|
679
724
|
await resourceListHandler?.({
|
|
@@ -733,9 +778,13 @@ describe('mcp-client', () => {
|
|
|
733
778
|
};
|
|
734
779
|
const client = new McpClient('test-server', {
|
|
735
780
|
command: 'test-command',
|
|
736
|
-
},
|
|
781
|
+
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
737
782
|
await client.connect();
|
|
738
|
-
await client.
|
|
783
|
+
await client.discoverInto(MOCK_CONTEXT, {
|
|
784
|
+
toolRegistry: mockedToolRegistry,
|
|
785
|
+
promptRegistry,
|
|
786
|
+
resourceRegistry,
|
|
787
|
+
});
|
|
739
788
|
expect(mockedClient.setNotificationHandler).toHaveBeenCalledTimes(2);
|
|
740
789
|
expect(promptListHandler).toBeDefined();
|
|
741
790
|
await promptListHandler?.({
|
|
@@ -790,9 +839,13 @@ describe('mcp-client', () => {
|
|
|
790
839
|
};
|
|
791
840
|
const client = new McpClient('test-server', {
|
|
792
841
|
command: 'test-command',
|
|
793
|
-
},
|
|
842
|
+
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
794
843
|
await client.connect();
|
|
795
|
-
await client.
|
|
844
|
+
await client.discoverInto(MOCK_CONTEXT, {
|
|
845
|
+
toolRegistry: mockedToolRegistry,
|
|
846
|
+
promptRegistry: mockedPromptRegistry,
|
|
847
|
+
resourceRegistry,
|
|
848
|
+
});
|
|
796
849
|
expect(mockedToolRegistry.registerTool).toHaveBeenCalledOnce();
|
|
797
850
|
expect(mockedPromptRegistry.registerPrompt).toHaveBeenCalledOnce();
|
|
798
851
|
await client.disconnect();
|
|
@@ -827,16 +880,22 @@ describe('mcp-client', () => {
|
|
|
827
880
|
getToolsByServer: vi.fn().mockReturnValue([]),
|
|
828
881
|
getMessageBus: vi.fn().mockReturnValue(undefined),
|
|
829
882
|
};
|
|
830
|
-
const client = new McpClient('test-server', { command: 'test-command' },
|
|
831
|
-
getPromptsByServer: vi.fn().mockReturnValue([]),
|
|
832
|
-
registerPrompt: vi.fn(),
|
|
833
|
-
}, {
|
|
834
|
-
getResourcesByServer: vi.fn().mockReturnValue([]),
|
|
835
|
-
registerResource: vi.fn(),
|
|
836
|
-
removeResourcesByServer: vi.fn(),
|
|
837
|
-
setResourcesForServer: vi.fn(),
|
|
838
|
-
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
883
|
+
const client = new McpClient('test-server', { command: 'test-command' }, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
839
884
|
await client.connect();
|
|
885
|
+
// INJECTED REGISTRIES
|
|
886
|
+
client.registeredRegistries?.add({
|
|
887
|
+
toolRegistry: mockedToolRegistry,
|
|
888
|
+
promptRegistry: {
|
|
889
|
+
getPromptsByServer: vi.fn().mockReturnValue([]),
|
|
890
|
+
registerPrompt: vi.fn(),
|
|
891
|
+
},
|
|
892
|
+
resourceRegistry: {
|
|
893
|
+
getResourcesByServer: vi.fn().mockReturnValue([]),
|
|
894
|
+
registerResource: vi.fn(),
|
|
895
|
+
removeResourcesByServer: vi.fn(),
|
|
896
|
+
setResourcesForServer: vi.fn(),
|
|
897
|
+
},
|
|
898
|
+
});
|
|
840
899
|
expect(mockedClient.setNotificationHandler).toHaveBeenCalledWith(ToolListChangedNotificationSchema, expect.any(Function));
|
|
841
900
|
});
|
|
842
901
|
it('should NOT set up notification handler if server lacks capability', async () => {
|
|
@@ -850,20 +909,26 @@ describe('mcp-client', () => {
|
|
|
850
909
|
};
|
|
851
910
|
vi.mocked(ClientLib.Client).mockReturnValue(mockedClient);
|
|
852
911
|
vi.spyOn(SdkClientStdioLib, 'StdioClientTransport').mockReturnValue({});
|
|
853
|
-
const client = new McpClient('test-server', { command: 'test-command' },
|
|
854
|
-
getToolsByServer: vi.fn().mockReturnValue([]),
|
|
855
|
-
registerTool: vi.fn(),
|
|
856
|
-
sortTools: vi.fn(),
|
|
857
|
-
}, {
|
|
858
|
-
getPromptsByServer: vi.fn().mockReturnValue([]),
|
|
859
|
-
registerPrompt: vi.fn(),
|
|
860
|
-
}, {
|
|
861
|
-
getResourcesByServer: vi.fn().mockReturnValue([]),
|
|
862
|
-
registerResource: vi.fn(),
|
|
863
|
-
removeResourcesByServer: vi.fn(),
|
|
864
|
-
setResourcesForServer: vi.fn(),
|
|
865
|
-
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
912
|
+
const client = new McpClient('test-server', { command: 'test-command' }, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
866
913
|
await client.connect();
|
|
914
|
+
// INJECTED REGISTRIES
|
|
915
|
+
client.registeredRegistries?.add({
|
|
916
|
+
toolRegistry: {
|
|
917
|
+
getToolsByServer: vi.fn().mockReturnValue([]),
|
|
918
|
+
registerTool: vi.fn(),
|
|
919
|
+
sortTools: vi.fn(),
|
|
920
|
+
},
|
|
921
|
+
promptRegistry: {
|
|
922
|
+
getPromptsByServer: vi.fn().mockReturnValue([]),
|
|
923
|
+
registerPrompt: vi.fn(),
|
|
924
|
+
},
|
|
925
|
+
resourceRegistry: {
|
|
926
|
+
getResourcesByServer: vi.fn().mockReturnValue([]),
|
|
927
|
+
registerResource: vi.fn(),
|
|
928
|
+
removeResourcesByServer: vi.fn(),
|
|
929
|
+
setResourcesForServer: vi.fn(),
|
|
930
|
+
},
|
|
931
|
+
});
|
|
867
932
|
// Should be called for ProgressNotificationSchema, even if no other capabilities
|
|
868
933
|
expect(mockedClient.setNotificationHandler).toHaveBeenCalled();
|
|
869
934
|
const progressCall = mockedClient.setNotificationHandler.mock.calls.find((call) => call[0] === ProgressNotificationSchema);
|
|
@@ -882,20 +947,26 @@ describe('mcp-client', () => {
|
|
|
882
947
|
setRequestHandler: vi.fn().mockResolvedValue({}),
|
|
883
948
|
};
|
|
884
949
|
vi.mocked(ClientLib.Client).mockReturnValue(mockedClient);
|
|
885
|
-
const client = new McpClient('test-server', { command: 'test-command' },
|
|
886
|
-
getToolsByServer: vi.fn().mockReturnValue([]),
|
|
887
|
-
registerTool: vi.fn(),
|
|
888
|
-
sortTools: vi.fn(),
|
|
889
|
-
}, {
|
|
890
|
-
getPromptsByServer: vi.fn().mockReturnValue([]),
|
|
891
|
-
registerPrompt: vi.fn(),
|
|
892
|
-
}, {
|
|
893
|
-
getResourcesByServer: vi.fn().mockReturnValue([]),
|
|
894
|
-
registerResource: vi.fn(),
|
|
895
|
-
removeResourcesByServer: vi.fn(),
|
|
896
|
-
setResourcesForServer: vi.fn(),
|
|
897
|
-
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
950
|
+
const client = new McpClient('test-server', { command: 'test-command' }, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
898
951
|
await client.connect();
|
|
952
|
+
// INJECTED REGISTRIES
|
|
953
|
+
client.registeredRegistries?.add({
|
|
954
|
+
toolRegistry: {
|
|
955
|
+
getToolsByServer: vi.fn().mockReturnValue([]),
|
|
956
|
+
registerTool: vi.fn(),
|
|
957
|
+
sortTools: vi.fn(),
|
|
958
|
+
},
|
|
959
|
+
promptRegistry: {
|
|
960
|
+
getPromptsByServer: vi.fn().mockReturnValue([]),
|
|
961
|
+
registerPrompt: vi.fn(),
|
|
962
|
+
},
|
|
963
|
+
resourceRegistry: {
|
|
964
|
+
getResourcesByServer: vi.fn().mockReturnValue([]),
|
|
965
|
+
registerResource: vi.fn(),
|
|
966
|
+
removeResourcesByServer: vi.fn(),
|
|
967
|
+
setResourcesForServer: vi.fn(),
|
|
968
|
+
},
|
|
969
|
+
});
|
|
899
970
|
const toolUpdateCall = mockedClient.setNotificationHandler.mock.calls.find((call) => call[0] === ToolListChangedNotificationSchema);
|
|
900
971
|
expect(toolUpdateCall).toBeDefined();
|
|
901
972
|
});
|
|
@@ -932,12 +1003,18 @@ describe('mcp-client', () => {
|
|
|
932
1003
|
};
|
|
933
1004
|
const onContextUpdatedSpy = vi.fn().mockResolvedValue(undefined);
|
|
934
1005
|
// Initialize client with onContextUpdated callback
|
|
935
|
-
const client = new McpClient('test-server', { command: 'test-command' },
|
|
936
|
-
removeMcpResourcesByServer: vi.fn(),
|
|
937
|
-
registerResource: vi.fn(),
|
|
938
|
-
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1', onContextUpdatedSpy);
|
|
1006
|
+
const client = new McpClient('test-server', { command: 'test-command' }, workspaceContext, MOCK_CONTEXT, false, '0.0.1', onContextUpdatedSpy);
|
|
939
1007
|
// 1. Connect (sets up listener)
|
|
940
1008
|
await client.connect();
|
|
1009
|
+
// INJECTED REGISTRIES
|
|
1010
|
+
client.registeredRegistries?.add({
|
|
1011
|
+
toolRegistry: mockedToolRegistry,
|
|
1012
|
+
promptRegistry: {},
|
|
1013
|
+
resourceRegistry: {
|
|
1014
|
+
removeMcpResourcesByServer: vi.fn(),
|
|
1015
|
+
registerResource: vi.fn(),
|
|
1016
|
+
},
|
|
1017
|
+
});
|
|
941
1018
|
// 2. Extract the callback passed to setNotificationHandler for tools
|
|
942
1019
|
const toolUpdateCall = mockedClient.setNotificationHandler.mock.calls.find((call) => call[0] === ToolListChangedNotificationSchema);
|
|
943
1020
|
const notificationCallback = toolUpdateCall[1];
|
|
@@ -975,8 +1052,14 @@ describe('mcp-client', () => {
|
|
|
975
1052
|
getToolsByServer: vi.fn().mockReturnValue([]),
|
|
976
1053
|
getMessageBus: vi.fn().mockReturnValue(undefined),
|
|
977
1054
|
};
|
|
978
|
-
const client = new McpClient('test-server', { command: 'test-command' },
|
|
1055
|
+
const client = new McpClient('test-server', { command: 'test-command' }, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
979
1056
|
await client.connect();
|
|
1057
|
+
// INJECTED REGISTRIES
|
|
1058
|
+
client.registeredRegistries?.add({
|
|
1059
|
+
toolRegistry: mockedToolRegistry,
|
|
1060
|
+
promptRegistry: {},
|
|
1061
|
+
resourceRegistry: {},
|
|
1062
|
+
});
|
|
980
1063
|
const toolUpdateCall = mockedClient.setNotificationHandler.mock.calls.find((call) => call[0] === ToolListChangedNotificationSchema);
|
|
981
1064
|
const notificationCallback = toolUpdateCall[1];
|
|
982
1065
|
// Trigger notification - should fail internally but catch the error
|
|
@@ -1020,10 +1103,22 @@ describe('mcp-client', () => {
|
|
|
1020
1103
|
getMessageBus: vi.fn().mockReturnValue(undefined),
|
|
1021
1104
|
};
|
|
1022
1105
|
const onContextUpdatedSpy = vi.fn().mockResolvedValue(undefined);
|
|
1023
|
-
const clientA = new McpClient('server-A', { command: 'cmd-a' },
|
|
1024
|
-
const clientB = new McpClient('server-B', { command: 'cmd-b' },
|
|
1106
|
+
const clientA = new McpClient('server-A', { command: 'cmd-a' }, workspaceContext, MOCK_CONTEXT, false, '0.0.1', onContextUpdatedSpy);
|
|
1107
|
+
const clientB = new McpClient('server-B', { command: 'cmd-b' }, workspaceContext, MOCK_CONTEXT, false, '0.0.1', onContextUpdatedSpy);
|
|
1025
1108
|
await clientA.connect();
|
|
1109
|
+
// INJECTED REGISTRIES
|
|
1110
|
+
clientA.registeredRegistries?.add({
|
|
1111
|
+
toolRegistry: mockedToolRegistry,
|
|
1112
|
+
promptRegistry: {},
|
|
1113
|
+
resourceRegistry: {},
|
|
1114
|
+
});
|
|
1026
1115
|
await clientB.connect();
|
|
1116
|
+
// INJECTED REGISTRIES
|
|
1117
|
+
clientB.registeredRegistries?.add({
|
|
1118
|
+
toolRegistry: mockedToolRegistry,
|
|
1119
|
+
promptRegistry: {},
|
|
1120
|
+
resourceRegistry: {},
|
|
1121
|
+
});
|
|
1027
1122
|
const toolUpdateCallA = mockClientA.setNotificationHandler.mock.calls.find((call) => call[0] === ToolListChangedNotificationSchema);
|
|
1028
1123
|
const handlerA = toolUpdateCallA[1];
|
|
1029
1124
|
const toolUpdateCallB = mockClientB.setNotificationHandler.mock.calls.find((call) => call[0] === ToolListChangedNotificationSchema);
|
|
@@ -1074,17 +1169,23 @@ describe('mcp-client', () => {
|
|
|
1074
1169
|
};
|
|
1075
1170
|
const client = new McpClient('test-server',
|
|
1076
1171
|
// Set a very short timeout
|
|
1077
|
-
{ command: 'test-command', timeout: 50 },
|
|
1078
|
-
getPromptsByServer: vi.fn().mockReturnValue([]),
|
|
1079
|
-
registerPrompt: vi.fn(),
|
|
1080
|
-
removePromptsByServer: vi.fn(),
|
|
1081
|
-
}, {
|
|
1082
|
-
getResourcesByServer: vi.fn().mockReturnValue([]),
|
|
1083
|
-
registerResource: vi.fn(),
|
|
1084
|
-
removeResourcesByServer: vi.fn(),
|
|
1085
|
-
setResourcesForServer: vi.fn(),
|
|
1086
|
-
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
1172
|
+
{ command: 'test-command', timeout: 50 }, workspaceContext, MOCK_CONTEXT, false, '0.0.1');
|
|
1087
1173
|
await client.connect();
|
|
1174
|
+
// INJECTED REGISTRIES
|
|
1175
|
+
client.registeredRegistries?.add({
|
|
1176
|
+
toolRegistry: mockedToolRegistry,
|
|
1177
|
+
promptRegistry: {
|
|
1178
|
+
getPromptsByServer: vi.fn().mockReturnValue([]),
|
|
1179
|
+
registerPrompt: vi.fn(),
|
|
1180
|
+
removePromptsByServer: vi.fn(),
|
|
1181
|
+
},
|
|
1182
|
+
resourceRegistry: {
|
|
1183
|
+
getResourcesByServer: vi.fn().mockReturnValue([]),
|
|
1184
|
+
registerResource: vi.fn(),
|
|
1185
|
+
removeResourcesByServer: vi.fn(),
|
|
1186
|
+
setResourcesForServer: vi.fn(),
|
|
1187
|
+
},
|
|
1188
|
+
});
|
|
1088
1189
|
const toolUpdateCall = mockedClient.setNotificationHandler.mock.calls.find((call) => call[0] === ToolListChangedNotificationSchema);
|
|
1089
1190
|
const notificationCallback = toolUpdateCall[1];
|
|
1090
1191
|
const refreshPromise = notificationCallback();
|
|
@@ -1119,17 +1220,23 @@ describe('mcp-client', () => {
|
|
|
1119
1220
|
getMessageBus: vi.fn().mockReturnValue(undefined),
|
|
1120
1221
|
};
|
|
1121
1222
|
const onContextUpdatedSpy = vi.fn().mockResolvedValue(undefined);
|
|
1122
|
-
const client = new McpClient('test-server', { command: 'test-command' },
|
|
1123
|
-
getPromptsByServer: vi.fn().mockReturnValue([]),
|
|
1124
|
-
registerPrompt: vi.fn(),
|
|
1125
|
-
removePromptsByServer: vi.fn(),
|
|
1126
|
-
}, {
|
|
1127
|
-
getResourcesByServer: vi.fn().mockReturnValue([]),
|
|
1128
|
-
registerResource: vi.fn(),
|
|
1129
|
-
removeResourcesByServer: vi.fn(),
|
|
1130
|
-
setResourcesForServer: vi.fn(),
|
|
1131
|
-
}, workspaceContext, MOCK_CONTEXT, false, '0.0.1', onContextUpdatedSpy);
|
|
1223
|
+
const client = new McpClient('test-server', { command: 'test-command' }, workspaceContext, MOCK_CONTEXT, false, '0.0.1', onContextUpdatedSpy);
|
|
1132
1224
|
await client.connect();
|
|
1225
|
+
// INJECTED REGISTRIES
|
|
1226
|
+
client.registeredRegistries?.add({
|
|
1227
|
+
toolRegistry: mockedToolRegistry,
|
|
1228
|
+
promptRegistry: {
|
|
1229
|
+
getPromptsByServer: vi.fn().mockReturnValue([]),
|
|
1230
|
+
registerPrompt: vi.fn(),
|
|
1231
|
+
removePromptsByServer: vi.fn(),
|
|
1232
|
+
},
|
|
1233
|
+
resourceRegistry: {
|
|
1234
|
+
getResourcesByServer: vi.fn().mockReturnValue([]),
|
|
1235
|
+
registerResource: vi.fn(),
|
|
1236
|
+
removeResourcesByServer: vi.fn(),
|
|
1237
|
+
setResourcesForServer: vi.fn(),
|
|
1238
|
+
},
|
|
1239
|
+
});
|
|
1133
1240
|
const toolUpdateCall = mockedClient.setNotificationHandler.mock.calls.find((call) => call[0] === ToolListChangedNotificationSchema);
|
|
1134
1241
|
const notificationCallback = toolUpdateCall[1];
|
|
1135
1242
|
vi.useFakeTimers();
|