-
Notifications
You must be signed in to change notification settings - Fork 6
Add custom MCP server URL support in Node.js SDK #129
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
74ded7b
Initial plan
Copilot 092abad
Add support for custom MCP server URLs in ToolingManifest.json
Copilot 2b89568
Address code review feedback: cleanup unused variables and improve ty…
Copilot c00b41a
Revert url field to required in MCPServerConfig interface
Copilot 4d75806
Validate full URL in tests using Utility.BuildMcpServerUrl
Copilot bd15415
Use mcpServerUniqueName as fallback when mcpServerName is not set
Copilot 9e810dd
Merge branch 'main' into copilot/add-custom-mcp-url-support
pontemonti 98f17bb
Replace 'any' type with proper MCPServerManifestEntry interface
Copilot d8ca535
Fix test environment variable handling to match existing pattern
Copilot 4c37d49
Add --experimental-vm-modules flag to test scripts for ESM support
Copilot de9a135
Use cross-env for cross-platform NODE_OPTIONS compatibility
Copilot 328a5af
Update packages/agents-a365-tooling/src/McpToolServerConfigurationSer…
pontemonti 4a03d0b
Add test coverage for custom headers in manifest
Copilot a209e79
Merge branch 'main' into copilot/add-custom-mcp-url-support
pontemonti 62cf978
Merge branch 'main' into copilot/add-custom-mcp-url-support
pontemonti 6651506
Refactor MCPServerManifestEntry type definition and update test scrip…
10f495d
Merge branch 'main' into copilot/add-custom-mcp-url-support
pontemonti f7303ae
Remove unused MCP server configuration comments
pontemonti 4cb92a0
Merge branch 'main' into copilot/add-custom-mcp-url-support
pontemonti 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
Some comments aren't visible on the classic Files Changed page.
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
266 changes: 266 additions & 0 deletions
266
tests/tooling/McpToolServerConfigurationService.test.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,266 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { describe, it, expect, jest, beforeEach, afterEach } from '@jest/globals'; | ||
| import { McpToolServerConfigurationService } from '../../packages/agents-a365-tooling/src/McpToolServerConfigurationService'; | ||
| import { Utility } from '../../packages/agents-a365-tooling/src/Utility'; | ||
| import fs from 'fs'; | ||
|
|
||
| describe('McpToolServerConfigurationService', () => { | ||
| let service: McpToolServerConfigurationService; | ||
| const originalEnv = process.env; | ||
|
|
||
| beforeEach(() => { | ||
| service = new McpToolServerConfigurationService(); | ||
| process.env = { ...originalEnv }; | ||
| // Set to development mode to read from manifest | ||
| process.env.NODE_ENV = 'Development'; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.env = originalEnv; | ||
| jest.restoreAllMocks(); | ||
|
pontemonti marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| describe('listToolServers with custom URLs', () => { | ||
| it('should use custom URL when provided in manifest', async () => { | ||
| // Arrange | ||
| const manifestContent = { | ||
| mcpServers: [ | ||
| { | ||
| mcpServerName: 'customServer', | ||
| url: 'http://localhost:3000/custom-mcp' | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| jest.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
| jest.spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify(manifestContent)); | ||
|
|
||
| // Act | ||
| const servers = await service.listToolServers('test-agent-id', 'mock-auth-token'); | ||
|
|
||
| // Assert | ||
| expect(servers).toHaveLength(1); | ||
| expect(servers[0].mcpServerName).toBe('customServer'); | ||
| expect(servers[0].url).toBe('http://localhost:3000/custom-mcp'); | ||
| }); | ||
|
|
||
| it('should build URL when not provided in manifest', async () => { | ||
| // Arrange | ||
| const manifestContent = { | ||
| mcpServers: [ | ||
| { | ||
| mcpServerName: 'mcp_MailTools' | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| jest.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
| jest.spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify(manifestContent)); | ||
|
|
||
| // Act | ||
| const servers = await service.listToolServers('test-agent-id', 'mock-auth-token'); | ||
|
|
||
| // Assert | ||
| expect(servers).toHaveLength(1); | ||
| expect(servers[0].mcpServerName).toBe('mcp_MailTools'); | ||
| // In development mode, should use mock server URL | ||
| expect(servers[0].url).toBe(Utility.BuildMcpServerUrl('mcp_MailTools')); | ||
| }); | ||
|
|
||
| it('should handle mix of custom and default URLs in manifest', async () => { | ||
| // Arrange | ||
| const manifestContent = { | ||
| mcpServers: [ | ||
| { | ||
| mcpServerName: 'customServer', | ||
| url: 'https://custom.example.com/mcp' | ||
| }, | ||
| { | ||
| mcpServerName: 'mcp_MailTools' | ||
| }, | ||
| { | ||
| mcpServerName: 'anotherCustom', | ||
| url: 'http://localhost:5000/mcp-server' | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| jest.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
| jest.spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify(manifestContent)); | ||
|
|
||
| // Act | ||
| const servers = await service.listToolServers('test-agent-id', 'mock-auth-token'); | ||
|
|
||
| // Assert | ||
| expect(servers).toHaveLength(3); | ||
|
|
||
| // First server has custom URL | ||
| expect(servers[0].mcpServerName).toBe('customServer'); | ||
| expect(servers[0].url).toBe('https://custom.example.com/mcp'); | ||
|
|
||
| // Second server uses default URL building | ||
| expect(servers[1].mcpServerName).toBe('mcp_MailTools'); | ||
| expect(servers[1].url).toBe(Utility.BuildMcpServerUrl('mcp_MailTools')); | ||
|
|
||
| // Third server has custom URL | ||
| expect(servers[2].mcpServerName).toBe('anotherCustom'); | ||
| expect(servers[2].url).toBe('http://localhost:5000/mcp-server'); | ||
| }); | ||
|
|
||
| it('should return empty array when manifest file does not exist', async () => { | ||
| // Arrange | ||
| jest.spyOn(fs, 'existsSync').mockReturnValue(false); | ||
| const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
|
|
||
| // Act | ||
| const servers = await service.listToolServers('test-agent-id', 'mock-auth-token'); | ||
|
|
||
| // Assert | ||
| expect(servers).toHaveLength(0); | ||
| expect(consoleWarnSpy).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should handle empty mcpServers array in manifest', async () => { | ||
| // Arrange | ||
| const manifestContent = { | ||
| mcpServers: [] | ||
| }; | ||
|
|
||
| jest.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
| jest.spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify(manifestContent)); | ||
|
|
||
| // Act | ||
| const servers = await service.listToolServers('test-agent-id', 'mock-auth-token'); | ||
|
|
||
| // Assert | ||
| expect(servers).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('should handle missing mcpServers property in manifest', async () => { | ||
| // Arrange | ||
| const manifestContent = {}; | ||
|
|
||
| jest.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
| jest.spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify(manifestContent)); | ||
|
|
||
| // Act | ||
| const servers = await service.listToolServers('test-agent-id', 'mock-auth-token'); | ||
|
|
||
| // Assert | ||
| expect(servers).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('should use mcpServerUniqueName as fallback when mcpServerName is not provided', async () => { | ||
| // Arrange | ||
| const manifestContent = { | ||
| mcpServers: [ | ||
| { | ||
| mcpServerUniqueName: 'mcp_UniqueServer' | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| jest.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
| jest.spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify(manifestContent)); | ||
|
|
||
| // Act | ||
| const servers = await service.listToolServers('test-agent-id', 'mock-auth-token'); | ||
|
|
||
| // Assert | ||
| expect(servers).toHaveLength(1); | ||
| expect(servers[0].mcpServerName).toBe('mcp_UniqueServer'); | ||
| expect(servers[0].url).toBe(Utility.BuildMcpServerUrl('mcp_UniqueServer')); | ||
| }); | ||
|
|
||
| it('should prefer mcpServerName over mcpServerUniqueName when both are provided', async () => { | ||
| // Arrange | ||
| const manifestContent = { | ||
| mcpServers: [ | ||
| { | ||
| mcpServerName: 'mcp_PreferredName', | ||
| mcpServerUniqueName: 'mcp_FallbackName' | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| jest.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
| jest.spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify(manifestContent)); | ||
|
|
||
| // Act | ||
| const servers = await service.listToolServers('test-agent-id', 'mock-auth-token'); | ||
|
|
||
| // Assert | ||
| expect(servers).toHaveLength(1); | ||
| expect(servers[0].mcpServerName).toBe('mcp_PreferredName'); | ||
| expect(servers[0].url).toBe(Utility.BuildMcpServerUrl('mcp_PreferredName')); | ||
| }); | ||
|
|
||
| it('should return empty array and log error when neither mcpServerName nor mcpServerUniqueName is provided', async () => { | ||
| // Arrange | ||
| const manifestContent = { | ||
| mcpServers: [ | ||
| { | ||
| url: 'http://localhost:3000/custom-mcp' | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| jest.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
| jest.spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify(manifestContent)); | ||
| const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
|
||
| // Act | ||
| const servers = await service.listToolServers('test-agent-id', 'mock-auth-token'); | ||
|
|
||
| // Assert | ||
| expect(servers).toHaveLength(0); | ||
| expect(consoleErrorSpy).toHaveBeenCalledWith( | ||
| expect.stringContaining('Either mcpServerName or mcpServerUniqueName must be provided') | ||
| ); | ||
| }); | ||
|
|
||
| it('should preserve custom headers when provided in manifest', async () => { | ||
| // Arrange | ||
| const manifestContent = { | ||
| mcpServers: [ | ||
| { | ||
| mcpServerName: 'serverWithHeaders', | ||
| url: 'http://localhost:3000/custom-mcp', | ||
| headers: { | ||
| 'Authorization': 'Bearer token123', | ||
| 'X-Custom-Header': 'custom-value' | ||
| } | ||
| }, | ||
| { | ||
| mcpServerName: 'serverWithoutHeaders', | ||
| url: 'http://localhost:4000/another-mcp' | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| jest.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
| jest.spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify(manifestContent)); | ||
|
|
||
| // Act | ||
| const servers = await service.listToolServers('test-agent-id', 'mock-auth-token'); | ||
|
|
||
| // Assert | ||
| expect(servers).toHaveLength(2); | ||
|
|
||
| // First server should have headers preserved | ||
| expect(servers[0].mcpServerName).toBe('serverWithHeaders'); | ||
| expect(servers[0].url).toBe('http://localhost:3000/custom-mcp'); | ||
| expect(servers[0].headers).toEqual({ | ||
| 'Authorization': 'Bearer token123', | ||
| 'X-Custom-Header': 'custom-value' | ||
| }); | ||
|
|
||
| // Second server should have undefined headers | ||
| expect(servers[1].mcpServerName).toBe('serverWithoutHeaders'); | ||
| expect(servers[1].url).toBe('http://localhost:4000/another-mcp'); | ||
| expect(servers[1].headers).toBeUndefined(); | ||
| }); | ||
| }); | ||
| }); | ||
|
pontemonti marked this conversation as resolved.
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.