feat: Add Normalization for MCP Server Names (#7421)

This commit is contained in:
Danny Avila 2025-05-16 11:39:57 -04:00 committed by GitHub
parent 353adceb0c
commit 26780bddf0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 63 additions and 1 deletions

View file

@ -0,0 +1,28 @@
import { normalizeServerName } from './utils';
describe('normalizeServerName', () => {
it('should not modify server names that already match the pattern', () => {
const result = normalizeServerName('valid-server_name.123');
expect(result).toBe('valid-server_name.123');
});
it('should normalize server names with non-ASCII characters', () => {
const result = normalizeServerName('我的服务');
// Should generate a fallback name with a hash
expect(result).toMatch(/^server_\d+$/);
expect(result).toMatch(/^[a-zA-Z0-9_.-]+$/);
});
it('should normalize server names with special characters', () => {
const result = normalizeServerName('server@name!');
// The actual result doesn't have the trailing underscore after trimming
expect(result).toBe('server_name');
expect(result).toMatch(/^[a-zA-Z0-9_.-]+$/);
});
it('should trim leading and trailing underscores', () => {
const result = normalizeServerName('!server-name!');
expect(result).toBe('server-name');
expect(result).toMatch(/^[a-zA-Z0-9_.-]+$/);
});
});