-
Notifications
You must be signed in to change notification settings - Fork 96
MCP Support for Consumption #8788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Bhavd13
wants to merge
1
commit into
Azure:main
Choose a base branch
from
Bhavd13:mcp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
301 changes: 301 additions & 0 deletions
301
...gic-apps-shared/src/designer-client-services/lib/consumption/__tests__/connection.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,301 @@ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
| import { ConsumptionConnectionService } from '../connection'; | ||
| import type { Connector } from '../../../../utils/src'; | ||
| import type { ConnectionCreationInfo } from '../../connection'; | ||
| import { InitLoggerService } from '../../logger'; | ||
|
|
||
| // Mock the LoggerService | ||
| const mockLoggerService = { | ||
| log: vi.fn(), | ||
| startTrace: vi.fn().mockReturnValue('mock-trace-id'), | ||
| endTrace: vi.fn(), | ||
| logErrorWithFormatting: vi.fn(), | ||
| }; | ||
|
|
||
| describe('ConsumptionConnectionService', () => { | ||
| const mockHttpClient = { | ||
| get: vi.fn(), | ||
| post: vi.fn(), | ||
| put: vi.fn(), | ||
| delete: vi.fn(), | ||
| }; | ||
|
|
||
| const mockOptions = { | ||
| apiVersion: '2018-07-01-preview', | ||
| baseUrl: 'https://management.azure.com', | ||
| subscriptionId: 'test-sub', | ||
| resourceGroup: 'test-rg', | ||
| location: 'eastus', | ||
| httpClient: mockHttpClient, | ||
| apiHubServiceDetails: { | ||
| apiVersion: '2018-07-01-preview', | ||
| baseUrl: 'https://management.azure.com', | ||
| subscriptionId: 'test-sub', | ||
| resourceGroup: 'test-rg', | ||
| location: 'eastus', | ||
| httpClient: mockHttpClient, | ||
| }, | ||
| }; | ||
|
|
||
| let service: ConsumptionConnectionService; | ||
|
|
||
| beforeEach(() => { | ||
| // Initialize the logger service before each test | ||
| InitLoggerService([mockLoggerService]); | ||
|
|
||
| service = new ConsumptionConnectionService(mockOptions as any); | ||
| vi.clearAllMocks(); | ||
|
|
||
| // Re-setup logger mocks after clearAllMocks | ||
| mockLoggerService.startTrace.mockReturnValue('mock-trace-id'); | ||
| }); | ||
|
|
||
| describe('createBuiltInMcpConnection', () => { | ||
| it('should create a built-in MCP connection with correct structure', async () => { | ||
| const connector: Partial<Connector> = { | ||
| id: 'connectionProviders/mcpclient', | ||
| type: 'connectionProviders/mcpclient', | ||
| name: 'mcpclient', | ||
| properties: { | ||
| displayName: 'MCP Client', | ||
| iconUri: 'https://example.com/icon.png', | ||
| brandColor: '#000000', | ||
| capabilities: ['builtin'], | ||
| description: 'MCP Client Connector', | ||
| generalInformation: { | ||
| displayName: 'MCP Client', | ||
| iconUrl: 'https://example.com/icon.png', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const connectionInfo: ConnectionCreationInfo = { | ||
| displayName: 'test-mcp-connection', | ||
| connectionParameters: { | ||
| serverUrl: { value: 'https://mcp-server.example.com' }, | ||
| }, | ||
| connectionParametersSet: { | ||
| name: 'ApiKey', | ||
| values: { | ||
| key: { value: 'test-api-key' }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const result = await service.createConnection('test-connection-id', connector as Connector, connectionInfo); | ||
|
|
||
| expect(result).toBeDefined(); | ||
| expect(result.name).toBe('test-mcp-connection'); | ||
| expect(result.id).toContain('connectionProviders/mcpclient/connections/'); | ||
| expect((result.properties as any).parameterValues.mcpServerUrl).toBe('https://mcp-server.example.com'); | ||
| expect((result.properties as any).parameterValues.authenticationType).toBe('ApiKey'); | ||
| }); | ||
|
|
||
| it('should throw error when serverUrl is missing', async () => { | ||
| const connector: Partial<Connector> = { | ||
| id: 'connectionProviders/mcpclient', | ||
| type: 'connectionProviders/mcpclient', | ||
| name: 'mcpclient', | ||
| properties: { | ||
| displayName: 'MCP Client', | ||
| capabilities: ['builtin'], | ||
| generalInformation: { | ||
| displayName: 'MCP Client', | ||
| }, | ||
| iconUri: '', | ||
| }, | ||
| }; | ||
|
|
||
| const connectionInfo: ConnectionCreationInfo = { | ||
| displayName: 'test-mcp-connection', | ||
| connectionParameters: {}, | ||
| }; | ||
|
|
||
| await expect(service.createConnection('test-connection-id', connector as Connector, connectionInfo)).rejects.toThrow( | ||
| 'Server URL is required for MCP connection' | ||
| ); | ||
| }); | ||
|
|
||
| it('should use connectionId as fallback name when displayName is not provided', async () => { | ||
| const connector: Partial<Connector> = { | ||
| id: 'connectionProviders/mcpclient', | ||
| type: 'connectionProviders/mcpclient', | ||
| name: 'mcpclient', | ||
| properties: { | ||
| displayName: 'MCP Client', | ||
| capabilities: ['builtin'], | ||
| generalInformation: { | ||
| displayName: 'MCP Client', | ||
| }, | ||
| iconUri: '', | ||
| }, | ||
| }; | ||
|
|
||
| const connectionInfo: ConnectionCreationInfo = { | ||
| connectionParameters: { | ||
| serverUrl: { value: 'https://mcp-server.example.com' }, | ||
| }, | ||
| }; | ||
|
|
||
| const result = await service.createConnection( | ||
| '/subscriptions/sub/connections/my-connection-name', | ||
| connector as Connector, | ||
| connectionInfo | ||
| ); | ||
|
|
||
| expect(result.name).toBe('my-connection-name'); | ||
| }); | ||
|
|
||
| it('should handle None authentication type', async () => { | ||
| const connector: Partial<Connector> = { | ||
| id: 'connectionProviders/mcpclient', | ||
| type: 'connectionProviders/mcpclient', | ||
| name: 'mcpclient', | ||
| properties: { | ||
| displayName: 'MCP Client', | ||
| capabilities: ['builtin'], | ||
| generalInformation: { | ||
| displayName: 'MCP Client', | ||
| }, | ||
| iconUri: '', | ||
| }, | ||
| }; | ||
|
|
||
| const connectionInfo: ConnectionCreationInfo = { | ||
| displayName: 'test-mcp-connection', | ||
| connectionParameters: { | ||
| serverUrl: { value: 'https://mcp-server.example.com' }, | ||
| }, | ||
| connectionParametersSet: { | ||
| name: 'None', | ||
| values: {}, | ||
| }, | ||
| }; | ||
|
|
||
| const result = await service.createConnection('test-connection-id', connector as Connector, connectionInfo); | ||
|
|
||
| expect((result.properties as any).parameterValues.authenticationType).toBe('None'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('extractParameterValue', () => { | ||
| it('should extract value from wrapped object', () => { | ||
| const result = (service as any).extractParameterValue({ value: 'test' }); | ||
| expect(result).toBe('test'); | ||
| }); | ||
|
|
||
| it('should return direct value if not wrapped', () => { | ||
| const result = (service as any).extractParameterValue('direct-value'); | ||
| expect(result).toBe('direct-value'); | ||
| }); | ||
|
|
||
| it('should handle null value', () => { | ||
| const result = (service as any).extractParameterValue(null); | ||
| expect(result).toBe(null); | ||
| }); | ||
|
|
||
| it('should handle undefined value', () => { | ||
| const result = (service as any).extractParameterValue(undefined); | ||
| expect(result).toBe(undefined); | ||
| }); | ||
|
|
||
| it('should handle object without value property', () => { | ||
| const result = (service as any).extractParameterValue({ other: 'prop' }); | ||
| expect(result).toEqual({ other: 'prop' }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('extractAuthParameters', () => { | ||
| it('should extract authentication parameters correctly', () => { | ||
| const result = (service as any).extractAuthParameters({ | ||
| name: 'ApiKey', | ||
| values: { | ||
| key: { value: 'my-api-key' }, | ||
| keyHeaderName: { value: 'X-API-Key' }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(result.authenticationType).toBe('ApiKey'); | ||
| expect(result.authParams.key).toBe('my-api-key'); | ||
| expect(result.authParams.keyHeaderName).toBe('X-API-Key'); | ||
| }); | ||
|
|
||
| it('should return None for undefined connectionParametersSet', () => { | ||
| const result = (service as any).extractAuthParameters(undefined); | ||
|
|
||
| expect(result.authenticationType).toBe('None'); | ||
| expect(result.authParams).toEqual({}); | ||
| }); | ||
|
|
||
| it('should return None for null connectionParametersSet', () => { | ||
| const result = (service as any).extractAuthParameters(null); | ||
|
|
||
| expect(result.authenticationType).toBe('None'); | ||
| expect(result.authParams).toEqual({}); | ||
| }); | ||
|
|
||
| it('should handle BasicAuth parameters', () => { | ||
| const result = (service as any).extractAuthParameters({ | ||
| name: 'BasicAuth', | ||
| values: { | ||
| username: { value: 'testuser' }, | ||
| password: { value: 'testpass' }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(result.authenticationType).toBe('BasicAuth'); | ||
| expect(result.authParams.username).toBe('testuser'); | ||
| expect(result.authParams.password).toBe('testpass'); | ||
| }); | ||
|
|
||
| it('should handle OAuth2 parameters', () => { | ||
| const result = (service as any).extractAuthParameters({ | ||
| name: 'OAuth2', | ||
| values: { | ||
| clientId: { value: 'client-123' }, | ||
| secret: { value: 'secret-456' }, | ||
| tenant: { value: 'tenant-789' }, | ||
| authority: { value: 'https://login.microsoftonline.com' }, | ||
| audience: { value: 'api://my-app' }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(result.authenticationType).toBe('OAuth2'); | ||
| expect(result.authParams.clientId).toBe('client-123'); | ||
| expect(result.authParams.secret).toBe('secret-456'); | ||
| expect(result.authParams.tenant).toBe('tenant-789'); | ||
| expect(result.authParams.authority).toBe('https://login.microsoftonline.com'); | ||
| expect(result.authParams.audience).toBe('api://my-app'); | ||
| }); | ||
|
|
||
| it('should only extract known auth keys', () => { | ||
| const result = (service as any).extractAuthParameters({ | ||
| name: 'Custom', | ||
| values: { | ||
| key: { value: 'valid-key' }, | ||
| unknownParam: { value: 'should-be-ignored' }, | ||
| anotherUnknown: { value: 'also-ignored' }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(result.authParams.key).toBe('valid-key'); | ||
| expect(result.authParams.unknownParam).toBeUndefined(); | ||
| expect(result.authParams.anotherUnknown).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getConnector', () => { | ||
| it('should return mcpclient connector for mcpclient connectorId', async () => { | ||
| const result = await service.getConnector('connectionProviders/mcpclient'); | ||
|
|
||
| expect(result).toBeDefined(); | ||
| expect(result.id).toContain('mcpclient'); | ||
| }); | ||
|
|
||
| it('should return agent connector for agent connectorId', async () => { | ||
| const result = await service.getConnector('connectionProviders/agent'); | ||
|
|
||
| expect(result).toBeDefined(); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test expects authenticationType to be 'ApiKey' but the connection info specifies 'ApiKey' on line 78. However, the connector manifest defines 'Key' as the authentication type name (line 275). This inconsistency should be resolved to match the actual authentication type names defined in the manifest.