mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 17:30:16 +01:00
✨ feat: Add Normalization for MCP Server Names (#7421)
This commit is contained in:
parent
353adceb0c
commit
26780bddf0
4 changed files with 63 additions and 1 deletions
28
packages/mcp/src/utils.test.ts
Normal file
28
packages/mcp/src/utils.test.ts
Normal 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_.-]+$/);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue