Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 23:15 UTC
feat: added test for providers that have MCP support (#1696)
Apoorv Taneja committed
Jun 25, 2025 at 15:22 UTC
b0433873b62e5362eeab610c7e80cdec861e9981
3 files changed
+279
ts/packages/providers/anthropic/test/anthropic.test.ts
+108
@@ -380,4 +380,112 @@ describe('AnthropicProvider', () => {
380
expect(mockExecuteToolFn).toHaveBeenCalledWith(toolSlug, toolParams, modifiers);
381
});
382
});
383
+
384
+ describe('MCP functionality', () => {
385
+ describe('wrapMcpServerResponse', () => {
386
+ it('should transform McpUrlResponse to AnthropicMcpServerGetResponse format', () => {
387
+ const mcpResponse = [
388
+ { name: 'server-1', url: 'https://mcp1.example.com' },
389
+ { name: 'server-2', url: 'https://mcp2.example.com' },
390
+ { name: 'server-3', url: 'https://mcp3.example.com' },
391
+ ];
392
+
393
+ const result = provider.wrapMcpServerResponse(mcpResponse);
394
+
395
+ expect(Array.isArray(result)).toBe(true);
396
+ expect(result).toHaveLength(3);
397
+ expect(result[0]).toEqual({
398
+ url: 'https://mcp1.example.com',
399
+ name: 'server-1',
400
+ type: 'url',
401
+ });
402
+ expect(result[1]).toEqual({
403
+ url: 'https://mcp2.example.com',
404
+ name: 'server-2',
405
+ type: 'url',
406
+ });
407
+ expect(result[2]).toEqual({
408
+ url: 'https://mcp3.example.com',
409
+ name: 'server-3',
410
+ type: 'url',
411
+ });
412
+ });
413
+
414
+ it('should handle empty array', () => {
415
+ const mcpResponse: Array<{ name: string; url: string }> = [];
416
+
417
+ const result = provider.wrapMcpServerResponse(mcpResponse);
418
+
419
+ expect(Array.isArray(result)).toBe(true);
420
+ expect(result).toHaveLength(0);
421
+ });
422
+
423
+ it('should handle single item array', () => {
424
+ const mcpResponse = [{ name: 'single-server', url: 'https://single.example.com' }];
425
+
426
+ const result = provider.wrapMcpServerResponse(mcpResponse);
427
+
428
+ expect(Array.isArray(result)).toBe(true);
429
+ expect(result).toHaveLength(1);
430
+ expect(result[0]).toEqual({
431
+ url: 'https://single.example.com',
432
+ name: 'single-server',
433
+ type: 'url',
434
+ });
435
+ });
436
+
437
+ it('should preserve URL strings exactly', () => {
438
+ const mcpResponse = [
439
+ { name: 'http-server', url: 'http://insecure.example.com' },
440
+ { name: 'https-server', url: 'https://secure.example.com' },
441
+ { name: 'port-server', url: 'https://example.com:8080/path' },
442
+ { name: 'query-server', url: 'https://example.com?param=value' },
443
+ { name: 'fragment-server', url: 'https://example.com#section' },
444
+ ];
445
+
446
+ const result = provider.wrapMcpServerResponse(mcpResponse);
447
+
448
+ expect(result).toHaveLength(5);
449
+
450
+ // Verify URLs are preserved as strings exactly
451
+ expect(result[0].url).toBe('http://insecure.example.com');
452
+ expect(result[1].url).toBe('https://secure.example.com');
453
+ expect(result[2].url).toBe('https://example.com:8080/path');
454
+ expect(result[3].url).toBe('https://example.com?param=value');
455
+ expect(result[4].url).toBe('https://example.com#section');
456
+
457
+ // All should have type 'url'
458
+ result.forEach(item => {
459
+ expect(item.type).toBe('url');
460
+ });
461
+ });
462
+ });
463
+
464
+ describe('MCP integration with provider', () => {
465
+ it('should correctly type the MCP response transformation', () => {
466
+ const mcpResponse = [{ name: 'test-server', url: 'https://test.example.com' }];
467
+
468
+ const result = provider.wrapMcpServerResponse(mcpResponse);
469
+
470
+ // TypeScript should infer this as AnthropicMcpServerGetResponse
471
+ expect(result[0]).toHaveProperty('url');
472
+ expect(result[0]).toHaveProperty('name');
473
+ expect(result[0]).toHaveProperty('type');
474
+ expect(result[0].url).toBe('https://test.example.com');
475
+ expect(result[0].type).toBe('url');
476
+ });
477
+
478
+ it('should work with MCP provider instance', () => {
479
+ // Verify the provider can transform MCP responses
480
+ const newProvider = new AnthropicProvider();
481
+ const testResponse = [{ name: 'test', url: 'https://test.com' }];
482
+
483
+ const result = newProvider.wrapMcpServerResponse(testResponse);
484
+ expect(result).toHaveLength(1);
485
+ expect(result[0].name).toBe('test');
486
+ expect(result[0].url).toBe('https://test.com');
487
+ expect(result[0].type).toBe('url');
488
+ });
489
+ });
490
+ });
491
});
ts/packages/providers/mastra/test/mastra.test.ts
+95
@@ -458,4 +458,99 @@ describe('MastraProvider', () => {
458
expect(Array.isArray(wrapped)).toBe(false);
459
});
460
});
461
+
462
+ describe('MCP functionality', () => {
463
+ describe('wrapMcpServerResponse', () => {
464
+ it('should transform McpUrlResponse to MastraUrlMap format', () => {
465
+ const mcpResponse = [
466
+ { name: 'server-1', url: 'https://mcp1.example.com' },
467
+ { name: 'server-2', url: 'https://mcp2.example.com' },
468
+ { name: 'server-3', url: 'https://mcp3.example.com' },
469
+ ];
470
+
471
+ const result = provider.wrapMcpServerResponse(mcpResponse);
472
+
473
+ expect(result).toEqual({
474
+ 'server-1': { url: 'https://mcp1.example.com' },
475
+ 'server-2': { url: 'https://mcp2.example.com' },
476
+ 'server-3': { url: 'https://mcp3.example.com' },
477
+ });
478
+ });
479
+
480
+ it('should handle empty array', () => {
481
+ const mcpResponse: Array<{ name: string; url: string }> = [];
482
+
483
+ const result = provider.wrapMcpServerResponse(mcpResponse);
484
+
485
+ expect(result).toEqual({});
486
+ });
487
+
488
+ it('should handle single item array', () => {
489
+ const mcpResponse = [{ name: 'single-server', url: 'https://single.example.com' }];
490
+
491
+ const result = provider.wrapMcpServerResponse(mcpResponse);
492
+
493
+ expect(result).toEqual({
494
+ 'single-server': { url: 'https://single.example.com' },
495
+ });
496
+ });
497
+
498
+ it('should handle duplicate names by overwriting', () => {
499
+ const mcpResponse = [
500
+ { name: 'duplicate', url: 'https://first.example.com' },
501
+ { name: 'duplicate', url: 'https://second.example.com' },
502
+ { name: 'unique', url: 'https://unique.example.com' },
503
+ ];
504
+
505
+ const result = provider.wrapMcpServerResponse(mcpResponse);
506
+
507
+ // The second duplicate should overwrite the first
508
+ expect(result).toEqual({
509
+ duplicate: { url: 'https://second.example.com' },
510
+ unique: { url: 'https://unique.example.com' },
511
+ });
512
+ });
513
+
514
+ it('should preserve URL format exactly', () => {
515
+ const mcpResponse = [
516
+ { name: 'http-server', url: 'http://insecure.example.com' },
517
+ { name: 'https-server', url: 'https://secure.example.com' },
518
+ { name: 'port-server', url: 'https://example.com:8080/path' },
519
+ { name: 'query-server', url: 'https://example.com?param=value' },
520
+ { name: 'fragment-server', url: 'https://example.com#section' },
521
+ ];
522
+
523
+ const result = provider.wrapMcpServerResponse(mcpResponse);
524
+
525
+ expect(result).toEqual({
526
+ 'http-server': { url: 'http://insecure.example.com' },
527
+ 'https-server': { url: 'https://secure.example.com' },
528
+ 'port-server': { url: 'https://example.com:8080/path' },
529
+ 'query-server': { url: 'https://example.com?param=value' },
530
+ 'fragment-server': { url: 'https://example.com#section' },
531
+ });
532
+ });
533
+ });
534
+
535
+ describe('MCP integration with provider', () => {
536
+ it('should correctly type the MCP response transformation', () => {
537
+ const mcpResponse = [{ name: 'test-server', url: 'https://test.example.com' }];
538
+
539
+ const result = provider.wrapMcpServerResponse(mcpResponse);
540
+
541
+ // TypeScript should infer this as MastraUrlMap
542
+ const urlMap: { [name: string]: { url: string } } = result;
543
+ expect(urlMap['test-server'].url).toBe('https://test.example.com');
544
+ });
545
+
546
+ it('should work with MCP provider instance', () => {
547
+ // Verify the provider can transform MCP responses
548
+ const newProvider = new MastraProvider();
549
+ const testResponse = [{ name: 'test', url: 'https://test.com' }];
550
+
551
+ const result = newProvider.wrapMcpServerResponse(testResponse);
552
+ expect(result).toEqual({ test: { url: 'https://test.com' } });
553
+ });
554
+ });
555
+ });
556
});
ts/packages/providers/openai-agents/test/openai-agents.test.ts
+76
@@ -200,4 +200,80 @@ describe('OpenAIAgentsProvider', () => {
200
expect(mockExecuteToolFn).toHaveBeenCalledWith(toolSlug, toolParams, modifiers);
201
});
202
});
203
+
204
+ describe('MCP functionality', () => {
205
+ describe('wrapMcpServerResponse', () => {
206
+ it('should transform McpUrlResponse to standard McpServerGetResponse format', () => {
207
+ const mcpResponse = [
208
+ { name: 'server-1', url: 'https://mcp1.example.com' },
209
+ { name: 'server-2', url: 'https://mcp2.example.com' },
210
+ { name: 'server-3', url: 'https://mcp3.example.com' },
211
+ ];
212
+
213
+ const result = provider.wrapMcpServerResponse(mcpResponse);
214
+
215
+ expect(Array.isArray(result)).toBe(true);
216
+ expect(result).toHaveLength(3);
217
+ expect(result[0]).toEqual({
218
+ url: new URL('https://mcp1.example.com'),
219
+ name: 'server-1',
220
+ });
221
+ expect(result[1]).toEqual({
222
+ url: new URL('https://mcp2.example.com'),
223
+ name: 'server-2',
224
+ });
225
+ expect(result[2]).toEqual({
226
+ url: new URL('https://mcp3.example.com'),
227
+ name: 'server-3',
228
+ });
229
+ });
230
+
231
+ it('should handle empty array', () => {
232
+ const mcpResponse: Array<{ name: string; url: string }> = [];
233
+
234
+ const result = provider.wrapMcpServerResponse(mcpResponse);
235
+
236
+ expect(Array.isArray(result)).toBe(true);
237
+ expect(result).toHaveLength(0);
238
+ });
239
+
240
+ it('should handle single item array', () => {
241
+ const mcpResponse = [{ name: 'single-server', url: 'https://single.example.com' }];
242
+
243
+ const result = provider.wrapMcpServerResponse(mcpResponse);
244
+
245
+ expect(Array.isArray(result)).toBe(true);
246
+ expect(result).toHaveLength(1);
247
+ expect(result[0]).toEqual({
248
+ url: new URL('https://single.example.com'),
249
+ name: 'single-server',
250
+ });
251
+ });
252
+ });
253
+
254
+ describe('MCP integration with provider', () => {
255
+ it('should correctly type the MCP response transformation', () => {
256
+ const mcpResponse = [{ name: 'test-server', url: 'https://test.example.com' }];
257
+
258
+ const result = provider.wrapMcpServerResponse(mcpResponse);
259
+
260
+ // TypeScript should infer this as McpServerGetResponse
261
+ expect(result[0]).toHaveProperty('url');
262
+ expect(result[0]).toHaveProperty('name');
263
+ expect(result[0].url).toBeInstanceOf(URL);
264
+ expect(result[0].url.href).toBe('https://test.example.com/');
265
+ });
266
+
267
+ it('should work with MCP provider instance', () => {
268
+ // Verify the provider can transform MCP responses
269
+ const newProvider = new OpenAIAgentsProvider();
270
+ const testResponse = [{ name: 'test', url: 'https://test.com' }];
271
+
272
+ const result = newProvider.wrapMcpServerResponse(testResponse);
273
+ expect(result).toHaveLength(1);
274
+ expect(result[0].name).toBe('test');
275
+ expect(result[0].url.href).toBe('https://test.com/');
276
+ });
277
+ });
278
+ });
279
});