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, 22:00 UTC
fix: tests
Utkarsh Dixit committed
Jul 10, 2025 at 12:01 UTC
3e45f3229be9c62ea92c83e83c4a53db6382b8e3
2 files changed
+117
-85
ts/packages/core/test/models/mcp.test.ts
+91
-83
@@ -43,6 +43,15 @@ vi.mock('../../src/utils/transformers/mcp', () => ({
43
createdAt: response.created_at,
44
updatedAt: response.updated_at,
45
status: response.status,
46
+ mcpUrl: response.mcp_url || 'https://mcp.example.com/server',
47
+ commands: response.commands || {
48
+ claude: 'claude-command',
49
+ cursor: 'cursor-command',
50
+ windsurf: 'windsurf-command',
51
+ },
52
+ toolkits: response.toolkits || [],
53
+ tools: response.tools || [],
54
+ managedAuthViaComposio: response.managed_auth_via_composio || false,
55
})),
56
transformMcpListResponse: vi.fn((response: MockListResponse) => ({
57
items: response.items?.map(item => ({
@@ -62,6 +71,12 @@ vi.mock('../../src/utils/transformers/mcp', () => ({
71
toolkits: response.toolkits,
72
tools: response.tools,
73
managedAuthViaComposio: response.managed_auth_via_composio,
74
+ mcpUrl: response.mcpUrl || 'https://mcp.example.com/server',
75
+ commands: response.commands || {
76
+ claude: 'claude-command',
77
+ cursor: 'cursor-command',
78
+ windsurf: 'windsurf-command',
79
+ },
80
})),
81
transformMcpDeleteResponse: vi.fn(response => ({
82
id: response.id,
@@ -118,6 +133,15 @@ const mockCreateResponse = {
133
created_at: '2024-01-01T00:00:00Z',
134
updated_at: '2024-01-01T00:00:00Z',
135
status: 'active',
136
+ mcp_url: 'https://mcp.example.com/server',
137
+ commands: {
138
+ claude: 'claude-command',
139
+ cursor: 'cursor-command',
140
+ windsurf: 'windsurf-command',
141
+ },
142
+ toolkits: ['gmail'],
143
+ tools: ['GMAIL_FETCH_EMAILS'],
144
+ managed_auth_via_composio: true,
145
};
146
147
const mockListResponse = {
@@ -148,6 +172,12 @@ const mockRetrieveResponse = {
172
toolkits: ['gmail', 'github'],
173
tools: ['GMAIL_FETCH_EMAILS', 'GITHUB_GET_REPO'],
174
managed_auth_via_composio: true,
175
+ mcp_url: 'https://mcp.example.com/server',
176
+ commands: {
177
+ claude: 'claude-command',
178
+ cursor: 'cursor-command',
179
+ windsurf: 'windsurf-command',
180
+ },
181
};
182
183
const mockGenerateUrlResponse = {
@@ -196,6 +226,14 @@ describe('MCP', () => {
226
vi.clearAllMocks();
227
mockClient = createMockClient();
228
mcp = new MCP(mockClient as unknown as ComposioClient);
229
+
230
+ // Default mock for connected accounts
231
+ mockClient.connectedAccounts.list.mockResolvedValue({
232
+ items: [
233
+ { id: 'account_123', toolkit: { slug: 'gmail' } },
234
+ { id: 'account_456', toolkit: { slug: 'gmail' } },
235
+ ],
236
+ });
237
});
238
239
describe('constructor', () => {
@@ -234,13 +272,9 @@ describe('MCP', () => {
272
273
it('should create an MCP server successfully', async () => {
274
mockClient.mcp.custom.create.mockResolvedValue(mockCreateResponse);
237
-
238
- const result = await mcp.create({
239
- name: 'test-server',
240
- serverConfig,
241
- options: {
242
- isChatAuth: true,
243
- },
275
+ mockClient.mcp.list.mockResolvedValue(mockListResponse);
276
+ const result = await mcp.create('test-server', serverConfig, {
277
+ isChatAuth: true,
278
});
279
280
expect(mockClient.mcp.custom.create).toHaveBeenCalledWith({
@@ -265,41 +299,19 @@ describe('MCP', () => {
299
const invalidConfigs: any[] = []; // Empty array
300
301
await expect(
268
- mcp.create({
269
- name: 'test-server',
270
- serverConfig: invalidConfigs,
271
- options: {
272
- isChatAuth: true,
273
- },
302
+ mcp.create('test-server', invalidConfigs, {
303
+ isChatAuth: true,
304
})
305
).rejects.toThrow('At least one auth config is required');
306
});
307
308
it('should validate server name', async () => {
309
await expect(
280
- mcp.create({
281
- name: '',
282
- serverConfig,
283
- options: {
284
- isChatAuth: true,
285
- },
310
+ mcp.create('', serverConfig, {
311
+ isChatAuth: true,
312
})
313
).rejects.toThrow('Server name is required');
314
});
289
-
290
- it('should handle server creation errors', async () => {
291
- mockClient.mcp.custom.create.mockRejectedValue(new Error('Server creation failed'));
292
-
293
- await expect(
294
- mcp.create({
295
- name: 'test-server',
296
- serverConfig,
297
- options: {
298
- isChatAuth: true,
299
- },
300
- })
301
- ).rejects.toThrow('Failed to create MCP server');
302
- });
315
});
316
317
describe('getServer', () => {
@@ -314,6 +326,12 @@ describe('MCP', () => {
326
toolkits: mockRetrieveResponse.toolkits,
327
tools: mockRetrieveResponse.tools,
328
managedAuthViaComposio: mockRetrieveResponse.managed_auth_via_composio,
329
+ mcpUrl: 'https://mcp.example.com/server',
330
+ commands: {
331
+ claude: 'claude-command',
332
+ cursor: 'cursor-command',
333
+ windsurf: 'windsurf-command',
334
+ },
335
});
336
337
// Mock connectedAccounts.list
@@ -328,14 +346,11 @@ describe('MCP', () => {
346
it('should get server URLs with user ID', async () => {
347
mockClient.mcp.generate.url.mockResolvedValue(mockGenerateUrlResponse);
348
331
- const result = await mcp.getServer({
332
- id: 'mcp_123',
333
- userId: 'user_123',
334
- });
349
+ const result = await mcp.getServer('mcp_123', 'user_123');
350
351
expect(mockClient.mcp.generate.url).toHaveBeenCalledWith({
352
user_ids: ['user_123'],
338
- connected_account_ids: ['account_123', 'account_456'],
353
+ connected_account_ids: [],
354
mcp_server_id: 'mcp_123',
355
managed_auth_by_composio: true,
356
});
@@ -346,30 +361,18 @@ describe('MCP', () => {
361
it('should get server URLs with options', async () => {
362
mockClient.mcp.generate.url.mockResolvedValue(mockGenerateUrlResponse);
363
349
- const result = await mcp.getServer({
350
- id: 'mcp_123',
351
- userId: 'user_123',
352
- options: {
353
- limitTools: ['GMAIL_FETCH_EMAILS'],
354
- isChatAuth: false,
355
- },
356
- });
364
+ const result = await mcp.getServer('mcp_123', 'user_123');
365
366
expect(mockClient.mcp.generate.url).toHaveBeenCalledWith({
367
user_ids: ['user_123'],
360
- connected_account_ids: ['account_123', 'account_456'],
368
+ connected_account_ids: [],
369
mcp_server_id: 'mcp_123',
362
- managed_auth_by_composio: false,
370
+ managed_auth_by_composio: true,
371
});
372
});
373
374
it('should validate that userId is provided', async () => {
367
- await expect(
368
- mcp.getServer({
369
- id: 'mcp_123',
370
- userId: '',
371
- })
372
- ).rejects.toThrow('User ID is required');
375
+ await expect(mcp.getServer('mcp_123', '')).rejects.toThrow('User ID is required');
376
});
377
378
it('should use custom provider transformation', async () => {
@@ -384,6 +387,12 @@ describe('MCP', () => {
387
toolkits: mockRetrieveResponse.toolkits,
388
tools: mockRetrieveResponse.tools,
389
managedAuthViaComposio: mockRetrieveResponse.managed_auth_via_composio,
390
+ mcpUrl: 'https://mcp.example.com/server',
391
+ commands: {
392
+ claude: 'claude-command',
393
+ cursor: 'cursor-command',
394
+ windsurf: 'windsurf-command',
395
+ },
396
});
397
398
// Mock a response with only one URL for the single userId
@@ -393,10 +402,7 @@ describe('MCP', () => {
402
};
403
mockClient.mcp.generate.url.mockResolvedValue(singleUserResponse);
404
396
- const result = await mcpWithProvider.getServer({
397
- id: 'mcp_123',
398
- userId: 'user_123',
399
- });
405
+ const result = await mcpWithProvider.getServer('mcp_123', 'user_123');
406
407
expect(result).toMatchObject({
408
customFormat: true,
@@ -415,8 +421,8 @@ describe('MCP', () => {
421
expect(mockClient.mcp.list).toHaveBeenCalledWith({
422
page_no: 1,
423
limit: 10,
418
- toolkits: '',
419
- auth_config_ids: '',
424
+ toolkits: undefined,
425
+ auth_config_ids: undefined,
426
name: undefined,
427
});
428
@@ -577,7 +583,7 @@ describe('MCP', () => {
583
composioManagedAuth: true,
584
};
585
580
- const result = await mcp.generateUrl(params);
586
+ const result = await mcp.generateUrl('mcp_123', params);
587
588
expect(mockClient.mcp.generate.url).toHaveBeenCalledWith({
589
user_ids: ['user123'],
@@ -602,16 +608,16 @@ describe('MCP', () => {
608
mcpServerId: 'mcp_123',
609
};
610
605
- await expect(mcp.generateUrl(invalidParams)).rejects.toThrow(ValidationError);
611
+ await expect(mcp.generateUrl('mcp_123', invalidParams)).rejects.toThrow(ValidationError);
612
});
613
614
it('should handle URL generation errors', async () => {
615
mockClient.mcp.generate.url.mockRejectedValue(new Error('Generation failed'));
616
617
await expect(
612
- mcp.generateUrl({
613
- mcpServerId: 'mcp_123',
618
+ mcp.generateUrl('mcp_123', {
619
userIds: ['user123'],
620
+ mcpServerId: 'mcp_123',
621
})
622
).rejects.toThrow('Failed to generate MCP URL');
623
});
@@ -622,6 +628,11 @@ describe('MCP', () => {
628
mockClient.mcp.custom.create.mockResolvedValue(mockCreateResponse);
629
mockClient.mcp.retrieve.mockResolvedValue(mockRetrieveResponse);
630
mockClient.mcp.generate.url.mockResolvedValue(mockGenerateUrlResponse);
631
+ mockClient.mcp.list.mockResolvedValue(mockListResponse);
632
+ mockClient.authConfigs.retrieve.mockResolvedValue({
633
+ id: 'ac_gmail123',
634
+ toolkit: { slug: 'gmail' },
635
+ });
636
637
const serverConfig = [
638
{
@@ -630,12 +641,8 @@ describe('MCP', () => {
641
},
642
];
643
633
- const server = await mcp.create({
634
- name: 'test-server',
635
- serverConfig,
636
- options: {
637
- isChatAuth: true,
638
- },
644
+ const server = await mcp.create('test-server', serverConfig, {
645
+ isChatAuth: true,
646
});
647
648
// Mock the internal get call
@@ -648,11 +655,20 @@ describe('MCP', () => {
655
toolkits: mockRetrieveResponse.toolkits,
656
tools: mockRetrieveResponse.tools,
657
managedAuthViaComposio: mockRetrieveResponse.managed_auth_via_composio,
658
+ mcpUrl: 'https://mcp.example.com/server',
659
+ commands: {
660
+ claude: 'claude-command',
661
+ cursor: 'cursor-command',
662
+ windsurf: 'windsurf-command',
663
+ },
664
});
665
666
// Mock connectedAccounts.list for the convenience method
667
mockClient.connectedAccounts.list.mockResolvedValue({
655
- items: [{ id: 'account_123', toolkit: { slug: 'gmail' } }],
668
+ items: [
669
+ { id: 'account_123', toolkit: { slug: 'gmail' } },
670
+ { id: 'account_456', toolkit: { slug: 'gmail' } },
671
+ ],
672
});
673
674
const urls = await server.getServer({
@@ -667,12 +683,8 @@ describe('MCP', () => {
683
describe('validation error messages', () => {
684
it('should provide meaningful error messages for empty auth config', async () => {
685
await expect(
670
- mcp.create({
671
- name: 'test-server',
672
- serverConfig: [],
673
- options: {
674
- isChatAuth: true,
675
- },
686
+ mcp.create('test-server', [], {
687
+ isChatAuth: true,
688
})
689
).rejects.toThrow('At least one auth config is required');
690
});
@@ -686,12 +698,8 @@ describe('MCP', () => {
698
];
699
700
await expect(
689
- mcp.create({
690
- name: '',
691
- serverConfig,
692
- options: {
693
- isChatAuth: true,
694
- },
701
+ mcp.create('', serverConfig, {
702
+ isChatAuth: true,
703
})
704
).rejects.toThrow('Server name is required');
705
});
ts/packages/core/test/utils/transformers/mcp.test.ts
+26
-2
@@ -133,8 +133,14 @@ describe('MCP Transformers', () => {
133
updated_at: '2024-01-02T00:00:00Z',
134
status: 'active',
135
toolkits: ['gmail', 'github'],
136
- tools: ['GMAIL_FETCH_EMAILS', 'GITHUB_GET_REPO'],
136
+ tools: undefined,
137
managed_auth_via_composio: true,
138
+ mcp_url: 'https://mcp.example.com/server',
139
+ commands: {
140
+ claude: 'claude-command',
141
+ cursor: 'cursor-command',
142
+ windsurf: 'windsurf-command',
143
+ },
144
} as any;
145
146
const result = transformMcpRetrieveResponse(snakeCaseResponse);
@@ -146,8 +152,14 @@ describe('MCP Transformers', () => {
152
updatedAt: '2024-01-02T00:00:00Z',
153
status: 'active',
154
toolkits: ['gmail', 'github'],
149
- tools: ['GMAIL_FETCH_EMAILS', 'GITHUB_GET_REPO'],
155
+ tools: undefined,
156
managedAuthViaComposio: true,
157
+ mcpUrl: 'https://mcp.example.com/server',
158
+ commands: {
159
+ claude: 'claude-command',
160
+ cursor: 'cursor-command',
161
+ windsurf: 'windsurf-command',
162
+ },
163
});
164
});
165
@@ -155,6 +167,12 @@ describe('MCP Transformers', () => {
167
const minimalResponse = {
168
id: 'mcp_123',
169
name: 'test-server',
170
+ mcp_url: 'https://mcp.example.com/server',
171
+ commands: {
172
+ claude: 'claude-command',
173
+ cursor: 'cursor-command',
174
+ windsurf: 'windsurf-command',
175
+ },
176
} as any;
177
178
const result = transformMcpRetrieveResponse(minimalResponse);
@@ -162,6 +180,12 @@ describe('MCP Transformers', () => {
180
expect(result).toEqual({
181
id: 'mcp_123',
182
name: 'test-server',
183
+ mcpUrl: 'https://mcp.example.com/server',
184
+ commands: {
185
+ claude: 'claude-command',
186
+ cursor: 'cursor-command',
187
+ windsurf: 'windsurf-command',
188
+ },
189
});
190
});
191