fix(ui): Block spaces and hyphens in MCP server names and aliases

- Update validateMCPServerName to reject both spaces and hyphens
- Apply shared validation to alias field in create form (was inline)
- Update tooltips to mention space restriction
- Ensures consistency across create/edit forms for server_name and alias fields
This commit is contained in:
Milan 2026-02-13 01:11:06 +02:00
parent 2b00466d3a
commit 8fa2734830
2 changed files with 14 additions and 11 deletions

View file

@ -429,7 +429,7 @@ const CreateMCPServer: React.FC<CreateMCPServerProps> = ({
label={
<span className="text-sm font-medium text-gray-700 flex items-center">
MCP Server Name
<Tooltip title="Best practice: Use a descriptive name that indicates the server's purpose (e.g., 'GitHub_MCP', 'Email_Service'). Hyphens '-' are not allowed; use underscores '_' instead. Names must comply with SEP-986 and will be rejected if invalid (https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool-names).">
<Tooltip title="Best practice: Use a descriptive name that indicates the server's purpose (e.g., 'GitHub_MCP', 'Email_Service'). Cannot contain spaces or hyphens; use underscores instead. Names must comply with SEP-986 and will be rejected if invalid (https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool-names).">
<InfoCircleOutlined className="ml-2 text-blue-400 hover:text-blue-600 cursor-help" />
</Tooltip>
</span>
@ -450,7 +450,7 @@ const CreateMCPServer: React.FC<CreateMCPServerProps> = ({
label={
<span className="text-sm font-medium text-gray-700 flex items-center">
Alias
<Tooltip title="A short, unique identifier for this server. Defaults to the server name with spaces replaced by underscores.">
<Tooltip title="A short, unique identifier for this server. Cannot contain spaces or hyphens; use underscores instead.">
<InfoCircleOutlined className="ml-2 text-blue-400 hover:text-blue-600 cursor-help" />
</Tooltip>
</span>
@ -458,12 +458,7 @@ const CreateMCPServer: React.FC<CreateMCPServerProps> = ({
name="alias"
rules={[
{ required: false },
{
validator: (_, value) =>
value && value.includes("-")
? Promise.reject("Alias cannot contain '-' (hyphen). Please use '_' (underscore) instead.")
: Promise.resolve(),
},
{ validator: (_, value) => validateMCPServerName(value) },
]}
>
<TextInput

View file

@ -47,7 +47,15 @@ export const validateMCPServerUrl = (value: string) => {
};
export const validateMCPServerName = (value: string) => {
return value && value.includes("-")
? Promise.reject("Server name cannot contain '-' (hyphen). Please use '_' (underscore) instead.")
: Promise.resolve();
if (!value) return Promise.resolve();
if (value.includes("-")) {
return Promise.reject("Server name cannot contain '-' (hyphen). Please use '_' (underscore) instead.");
}
if (value.includes(" ")) {
return Promise.reject("Server name cannot contain spaces. Please use '_' (underscore) instead.");
}
return Promise.resolve();
};