mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-24 02:39:19 -05:00
Fix URL routing for MCP servers with slashes in names (#396)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: samanhappy <2755122+samanhappy@users.noreply.github.com>
This commit is contained in:
@@ -299,4 +299,16 @@ describe('OpenAPI Granular Endpoints', () => {
|
||||
const group = mockGetGroupByIdOrName('nonexistent');
|
||||
expect(group).toBeNull();
|
||||
});
|
||||
|
||||
test('should decode URL-encoded server and tool names with slashes', () => {
|
||||
// Test that URL-encoded names with slashes are properly decoded
|
||||
const encodedServerName = 'com.atlassian%2Fatlassian-mcp-server';
|
||||
const encodedToolName = 'atlassianUserInfo';
|
||||
|
||||
const decodedServerName = decodeURIComponent(encodedServerName);
|
||||
const decodedToolName = decodeURIComponent(encodedToolName);
|
||||
|
||||
expect(decodedServerName).toBe('com.atlassian/atlassian-mcp-server');
|
||||
expect(decodedToolName).toBe('atlassianUserInfo');
|
||||
});
|
||||
});
|
||||
@@ -65,6 +65,27 @@ describe('OpenAPI Generator Service', () => {
|
||||
expect(spec).toHaveProperty('paths');
|
||||
expect(typeof spec.paths).toBe('object');
|
||||
});
|
||||
|
||||
it('should URL-encode server and tool names with slashes in paths', async () => {
|
||||
const spec = await generateOpenAPISpec();
|
||||
|
||||
// Check if any paths contain URL-encoded values
|
||||
// Paths with slashes in server/tool names should be encoded
|
||||
const paths = Object.keys(spec.paths);
|
||||
|
||||
// If there are any servers with slashes, verify encoding
|
||||
// e.g., "com.atlassian/atlassian-mcp-server" should become "com.atlassian%2Fatlassian-mcp-server"
|
||||
for (const path of paths) {
|
||||
// Path should not have unencoded slashes in the middle segments
|
||||
// Valid format: /tools/{encoded-server}/{encoded-tool}
|
||||
const pathSegments = path.split('/').filter((s) => s.length > 0);
|
||||
if (pathSegments[0] === 'tools' && pathSegments.length >= 3) {
|
||||
// The server name (segment 1) and tool name (segment 2+) should not create extra segments
|
||||
// If properly encoded, there should be exactly 3 segments: ['tools', serverName, toolName]
|
||||
expect(pathSegments.length).toBe(3);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('getToolStats', () => {
|
||||
|
||||
Reference in New Issue
Block a user