Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

feat: added test for providers that have MCP support (#1696)

Apoorv Tanejab0433873b62e
diff --git a/ts/packages/providers/anthropic/test/anthropic.test.ts b/ts/packages/providers/anthropic/test/anthropic.test.ts
index 2a40a0f88..a6edb0016 100644
--- a/ts/packages/providers/anthropic/test/anthropic.test.ts
+++ b/ts/packages/providers/anthropic/test/anthropic.test.ts
@@ -380,4 +380,112 @@ describe('AnthropicProvider', () => {
expect(mockExecuteToolFn).toHaveBeenCalledWith(toolSlug, toolParams, modifiers);
});
});
+
+ describe('MCP functionality', () => {
+ describe('wrapMcpServerResponse', () => {
+ it('should transform McpUrlResponse to AnthropicMcpServerGetResponse format', () => {
+ const mcpResponse = [
+ { name: 'server-1', url: 'https://mcp1.example.com' },
+ { name: 'server-2', url: 'https://mcp2.example.com' },
+ { name: 'server-3', url: 'https://mcp3.example.com' },
+ ];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ expect(Array.isArray(result)).toBe(true);
+ expect(result).toHaveLength(3);
+ expect(result[0]).toEqual({
+ url: 'https://mcp1.example.com',
+ name: 'server-1',
+ type: 'url',
+ });
+ expect(result[1]).toEqual({
+ url: 'https://mcp2.example.com',
+ name: 'server-2',
+ type: 'url',
+ });
+ expect(result[2]).toEqual({
+ url: 'https://mcp3.example.com',
+ name: 'server-3',
+ type: 'url',
+ });
+ });
+
+ it('should handle empty array', () => {
+ const mcpResponse: Array<{ name: string; url: string }> = [];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ expect(Array.isArray(result)).toBe(true);
+ expect(result).toHaveLength(0);
+ });
+
+ it('should handle single item array', () => {
+ const mcpResponse = [{ name: 'single-server', url: 'https://single.example.com' }];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ expect(Array.isArray(result)).toBe(true);
+ expect(result).toHaveLength(1);
+ expect(result[0]).toEqual({
+ url: 'https://single.example.com',
+ name: 'single-server',
+ type: 'url',
+ });
+ });
+
+ it('should preserve URL strings exactly', () => {
+ const mcpResponse = [
+ { name: 'http-server', url: 'http://insecure.example.com' },
+ { name: 'https-server', url: 'https://secure.example.com' },
+ { name: 'port-server', url: 'https://example.com:8080/path' },
+ { name: 'query-server', url: 'https://example.com?param=value' },
+ { name: 'fragment-server', url: 'https://example.com#section' },
+ ];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ expect(result).toHaveLength(5);
+
+ // Verify URLs are preserved as strings exactly
+ expect(result[0].url).toBe('http://insecure.example.com');
+ expect(result[1].url).toBe('https://secure.example.com');
+ expect(result[2].url).toBe('https://example.com:8080/path');
+ expect(result[3].url).toBe('https://example.com?param=value');
+ expect(result[4].url).toBe('https://example.com#section');
+
+ // All should have type 'url'
+ result.forEach(item => {
+ expect(item.type).toBe('url');
+ });
+ });
+ });
+
+ describe('MCP integration with provider', () => {
+ it('should correctly type the MCP response transformation', () => {
+ const mcpResponse = [{ name: 'test-server', url: 'https://test.example.com' }];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ // TypeScript should infer this as AnthropicMcpServerGetResponse
+ expect(result[0]).toHaveProperty('url');
+ expect(result[0]).toHaveProperty('name');
+ expect(result[0]).toHaveProperty('type');
+ expect(result[0].url).toBe('https://test.example.com');
+ expect(result[0].type).toBe('url');
+ });
+
+ it('should work with MCP provider instance', () => {
+ // Verify the provider can transform MCP responses
+ const newProvider = new AnthropicProvider();
+ const testResponse = [{ name: 'test', url: 'https://test.com' }];
+
+ const result = newProvider.wrapMcpServerResponse(testResponse);
+ expect(result).toHaveLength(1);
+ expect(result[0].name).toBe('test');
+ expect(result[0].url).toBe('https://test.com');
+ expect(result[0].type).toBe('url');
+ });
+ });
+ });
});
diff --git a/ts/packages/providers/mastra/test/mastra.test.ts b/ts/packages/providers/mastra/test/mastra.test.ts
index 5273a4c03..5ef5b9a1c 100644
--- a/ts/packages/providers/mastra/test/mastra.test.ts
+++ b/ts/packages/providers/mastra/test/mastra.test.ts
@@ -458,4 +458,99 @@ describe('MastraProvider', () => {
expect(Array.isArray(wrapped)).toBe(false);
});
});
+
+ describe('MCP functionality', () => {
+ describe('wrapMcpServerResponse', () => {
+ it('should transform McpUrlResponse to MastraUrlMap format', () => {
+ const mcpResponse = [
+ { name: 'server-1', url: 'https://mcp1.example.com' },
+ { name: 'server-2', url: 'https://mcp2.example.com' },
+ { name: 'server-3', url: 'https://mcp3.example.com' },
+ ];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ expect(result).toEqual({
+ 'server-1': { url: 'https://mcp1.example.com' },
+ 'server-2': { url: 'https://mcp2.example.com' },
+ 'server-3': { url: 'https://mcp3.example.com' },
+ });
+ });
+
+ it('should handle empty array', () => {
+ const mcpResponse: Array<{ name: string; url: string }> = [];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ expect(result).toEqual({});
+ });
+
+ it('should handle single item array', () => {
+ const mcpResponse = [{ name: 'single-server', url: 'https://single.example.com' }];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ expect(result).toEqual({
+ 'single-server': { url: 'https://single.example.com' },
+ });
+ });
+
+ it('should handle duplicate names by overwriting', () => {
+ const mcpResponse = [
+ { name: 'duplicate', url: 'https://first.example.com' },
+ { name: 'duplicate', url: 'https://second.example.com' },
+ { name: 'unique', url: 'https://unique.example.com' },
+ ];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ // The second duplicate should overwrite the first
+ expect(result).toEqual({
+ duplicate: { url: 'https://second.example.com' },
+ unique: { url: 'https://unique.example.com' },
+ });
+ });
+
+ it('should preserve URL format exactly', () => {
+ const mcpResponse = [
+ { name: 'http-server', url: 'http://insecure.example.com' },
+ { name: 'https-server', url: 'https://secure.example.com' },
+ { name: 'port-server', url: 'https://example.com:8080/path' },
+ { name: 'query-server', url: 'https://example.com?param=value' },
+ { name: 'fragment-server', url: 'https://example.com#section' },
+ ];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ expect(result).toEqual({
+ 'http-server': { url: 'http://insecure.example.com' },
+ 'https-server': { url: 'https://secure.example.com' },
+ 'port-server': { url: 'https://example.com:8080/path' },
+ 'query-server': { url: 'https://example.com?param=value' },
+ 'fragment-server': { url: 'https://example.com#section' },
+ });
+ });
+ });
+
+ describe('MCP integration with provider', () => {
+ it('should correctly type the MCP response transformation', () => {
+ const mcpResponse = [{ name: 'test-server', url: 'https://test.example.com' }];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ // TypeScript should infer this as MastraUrlMap
+ const urlMap: { [name: string]: { url: string } } = result;
+ expect(urlMap['test-server'].url).toBe('https://test.example.com');
+ });
+
+ it('should work with MCP provider instance', () => {
+ // Verify the provider can transform MCP responses
+ const newProvider = new MastraProvider();
+ const testResponse = [{ name: 'test', url: 'https://test.com' }];
+
+ const result = newProvider.wrapMcpServerResponse(testResponse);
+ expect(result).toEqual({ test: { url: 'https://test.com' } });
+ });
+ });
+ });
});
diff --git a/ts/packages/providers/openai-agents/test/openai-agents.test.ts b/ts/packages/providers/openai-agents/test/openai-agents.test.ts
index 1cb26f680..0371157f0 100644
--- a/ts/packages/providers/openai-agents/test/openai-agents.test.ts
+++ b/ts/packages/providers/openai-agents/test/openai-agents.test.ts
@@ -200,4 +200,80 @@ describe('OpenAIAgentsProvider', () => {
expect(mockExecuteToolFn).toHaveBeenCalledWith(toolSlug, toolParams, modifiers);
});
});
+
+ describe('MCP functionality', () => {
+ describe('wrapMcpServerResponse', () => {
+ it('should transform McpUrlResponse to standard McpServerGetResponse format', () => {
+ const mcpResponse = [
+ { name: 'server-1', url: 'https://mcp1.example.com' },
+ { name: 'server-2', url: 'https://mcp2.example.com' },
+ { name: 'server-3', url: 'https://mcp3.example.com' },
+ ];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ expect(Array.isArray(result)).toBe(true);
+ expect(result).toHaveLength(3);
+ expect(result[0]).toEqual({
+ url: new URL('https://mcp1.example.com'),
+ name: 'server-1',
+ });
+ expect(result[1]).toEqual({
+ url: new URL('https://mcp2.example.com'),
+ name: 'server-2',
+ });
+ expect(result[2]).toEqual({
+ url: new URL('https://mcp3.example.com'),
+ name: 'server-3',
+ });
+ });
+
+ it('should handle empty array', () => {
+ const mcpResponse: Array<{ name: string; url: string }> = [];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ expect(Array.isArray(result)).toBe(true);
+ expect(result).toHaveLength(0);
+ });
+
+ it('should handle single item array', () => {
+ const mcpResponse = [{ name: 'single-server', url: 'https://single.example.com' }];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ expect(Array.isArray(result)).toBe(true);
+ expect(result).toHaveLength(1);
+ expect(result[0]).toEqual({
+ url: new URL('https://single.example.com'),
+ name: 'single-server',
+ });
+ });
+ });
+
+ describe('MCP integration with provider', () => {
+ it('should correctly type the MCP response transformation', () => {
+ const mcpResponse = [{ name: 'test-server', url: 'https://test.example.com' }];
+
+ const result = provider.wrapMcpServerResponse(mcpResponse);
+
+ // TypeScript should infer this as McpServerGetResponse
+ expect(result[0]).toHaveProperty('url');
+ expect(result[0]).toHaveProperty('name');
+ expect(result[0].url).toBeInstanceOf(URL);
+ expect(result[0].url.href).toBe('https://test.example.com/');
+ });
+
+ it('should work with MCP provider instance', () => {
+ // Verify the provider can transform MCP responses
+ const newProvider = new OpenAIAgentsProvider();
+ const testResponse = [{ name: 'test', url: 'https://test.com' }];
+
+ const result = newProvider.wrapMcpServerResponse(testResponse);
+ expect(result).toHaveLength(1);
+ expect(result[0].name).toBe('test');
+ expect(result[0].url.href).toBe('https://test.com/');
+ });
+ });
+ });
});