@@ -8,7 +8,7 @@ import { Terminal, Globe, Loader2, PlusCircle, Trash2, Code, InfoIcon, AlertCirc
88import type { RemoteMCPServer , MCPServer , ToolServerCreateRequest } from "@/types" ;
99import { Select , SelectContent , SelectItem , SelectTrigger , SelectValue } from "@/components/ui/select" ;
1010import { Tooltip , TooltipContent , TooltipProvider , TooltipTrigger } from "@/components/ui/tooltip" ;
11- import { isResourceNameValid } from "@/lib/utils" ;
11+ import { createRFC1123ValidName , isResourceNameValid } from "@/lib/utils" ;
1212import { NamespaceCombobox } from "@/components/NamespaceCombobox" ;
1313import { Checkbox } from "./ui/checkbox" ;
1414
@@ -51,52 +51,6 @@ export function AddServerDialog({ open, onOpenChange, onAddServer, onError }: Ad
5151 const [ timeout , setTimeout ] = useState ( "5s" ) ;
5252 const [ sseReadTimeout , setSseReadTimeout ] = useState ( "300s" ) ;
5353 const [ terminateOnClose , setTerminateOnClose ] = useState ( true ) ;
54-
55-
56- // Clean up package name for server name
57- const cleanPackageName = ( pkgName : string ) : string => {
58- let cleaned = pkgName . trim ( ) . replace ( / ^ @ [ \w - ] + \/ / , "" ) ;
59-
60- if ( cleaned . startsWith ( "mcp-" ) && cleaned . length > 4 ) {
61- cleaned = cleaned . substring ( 4 ) ;
62- }
63-
64- // Convert to lowercase
65- cleaned = cleaned . toLowerCase ( ) ;
66- // Replace spaces and invalid characters with hyphens
67- cleaned = cleaned . replace ( / [ ^ a - z 0 - 9 . - ] / g, "-" ) ;
68- // Replace multiple consecutive hyphens with a single hyphen
69- cleaned = cleaned . replace ( / - + / g, "-" ) ;
70- // Remove hyphens at the beginning and end
71- cleaned = cleaned . replace ( / ^ - + | - + $ / g, "" ) ;
72- // If the string starts with a dot, prepend an 'a'
73- if ( cleaned . startsWith ( "." ) ) {
74- cleaned = "a" + cleaned ;
75- }
76-
77- // If the string ends with a dot, append an 'a'
78- if ( cleaned . endsWith ( "." ) ) {
79- cleaned = cleaned + "a" ;
80- }
81-
82- // Ensure the name starts and ends with an alphanumeric character
83- // If it doesn't start with alphanumeric, prepend 'server-'
84- if ( ! / ^ [ a - z 0 - 9 ] / . test ( cleaned ) ) {
85- cleaned = "server-" + cleaned ;
86- }
87-
88- // If it doesn't end with alphanumeric, append '-server'
89- if ( ! / [ a - z 0 - 9 ] $ / . test ( cleaned ) ) {
90- cleaned = cleaned + "-server" ;
91- }
92-
93- // If the string is empty (could happen after all the replacements), use a default name
94- if ( ! cleaned ) {
95- cleaned = "tool-server" ;
96- }
97-
98- return cleaned ;
99- } ;
10054
10155 // Handle server name input changes
10256 const handleServerNameChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
@@ -114,7 +68,7 @@ export function AddServerDialog({ open, onOpenChange, onAddServer, onError }: Ad
11468 let generatedName = "" ;
11569
11670 if ( activeTab === "command" && packageName . trim ( ) ) {
117- generatedName = cleanPackageName ( packageName . trim ( ) ) ;
71+ generatedName = createRFC1123ValidName ( [ packageName . trim ( ) ] ) ;
11872 } else if ( activeTab === "url" && url . trim ( ) ) {
11973 try {
12074 const urlObj = new URL ( url . trim ( ) ) ;
0 commit comments