@@ -70,6 +70,28 @@ export interface MCPCConfig {
7070 agents : ComposeDefinition [ ] ;
7171}
7272
73+ /**
74+ * Extract server name from command and arguments
75+ * Simply sanitizes the first non-flag argument or command name
76+ */
77+ function extractServerName ( command : string , commandArgs : string [ ] ) : string {
78+ // Try first non-flag argument
79+ for ( const arg of commandArgs ) {
80+ if ( ! arg . startsWith ( "-" ) ) {
81+ const name = arg
82+ . replace ( / [ @ . , / \\ : ; ! ? # $ % ^ & * ( ) [ \] { } ] / g, "_" )
83+ . substring ( 0 , 64 ) ;
84+ if ( name ) return name ;
85+ }
86+ }
87+
88+ // Fall back to command itself
89+ const name = command
90+ . replace ( / [ @ . , / \\ : ; ! ? # $ % ^ & * ( ) [ \] { } ] / g, "_" )
91+ . substring ( 0 , 64 ) ;
92+ return name || "agentic-tool" ;
93+ }
94+
7395/**
7496 * Create proxy configuration from command-line arguments
7597 * This generates an MCPC config that wraps an existing MCP server
@@ -78,6 +100,7 @@ function createProxyConfig(args: {
78100 transportType ?: string ;
79101 proxyCommand ?: string [ ] ;
80102 mode ?: string ;
103+ name ?: string ;
81104} ) : MCPCConfig {
82105 if ( ! args . proxyCommand || args . proxyCommand . length === 0 ) {
83106 console . error ( "Error: --proxy requires a command after --" ) ;
@@ -106,19 +129,8 @@ function createProxyConfig(args: {
106129 const command = args . proxyCommand [ 0 ] ;
107130 const commandArgs = args . proxyCommand . slice ( 1 ) ;
108131
109- // Extract server name from command (e.g., "@wonderwhy-er/desktop-commander" -> "desktop-commander")
110- let serverName = "mcp-server" ;
111- const npmPackageMatch = command . match ( / @ [ \w - ] + \/ ( [ \w - ] + ) / ) ||
112- commandArgs . join ( " " ) . match ( / @ [ \w - ] + \/ ( [ \w - ] + ) / ) ;
113- if ( npmPackageMatch ) {
114- serverName = npmPackageMatch [ 1 ] ;
115- } else {
116- // Try to get name from command itself
117- const baseName = command . split ( "/" ) . pop ( ) ?. replace ( / \. j s $ / , "" ) ;
118- if ( baseName && baseName !== "npx" && baseName !== "node" ) {
119- serverName = baseName ;
120- }
121- }
132+ // Use custom name if provided, otherwise extract from command
133+ const serverName = args . name || extractServerName ( command , commandArgs ) ;
122134
123135 // Create configuration
124136 const config : MCPCConfig = {
@@ -131,9 +143,7 @@ function createProxyConfig(args: {
131143 agents : [
132144 {
133145 name : serverName ,
134- description :
135- `Agentic tool to orchestrate ${ serverName } MCP server tools:
136- <tool name="${ serverName } .__ALL__"/>` ,
146+ description : `Orchestrate ${ serverName } MCP server tools` ,
137147 deps : {
138148 mcpServers : {
139149 [ serverName ] : {
@@ -147,7 +157,10 @@ function createProxyConfig(args: {
147157 } ,
148158 } ,
149159 options : {
150- mode : ( args . mode || "agentic" ) as any ,
160+ mode : ( args . mode || "agentic" ) ,
161+ refs : [
162+ `<tool name="${ serverName } .__ALL__"/>` ,
163+ ] ,
151164 } ,
152165 } ,
153166 ] ,
@@ -194,6 +207,7 @@ OPTIONS:
194207 Example: --proxy --transport-type stdio -- npx -y @wonderwhy-er/desktop-commander
195208 --transport-type <type> Transport type for proxy mode
196209 Supported types: stdio, streamable-http, sse
210+ --name <name> Custom server name for proxy mode (overrides auto-detection)
197211
198212ENVIRONMENT VARIABLES:
199213 MCPC_CONFIG Inline JSON configuration (same as --config)
@@ -207,6 +221,9 @@ EXAMPLES:
207221 # Proxy mode - wrap an existing MCP server (stdio)
208222 mcpc --proxy --transport-type stdio -- npx -y @wonderwhy-er/desktop-commander
209223
224+ # Proxy mode with custom server name
225+ mcpc --proxy --transport-type stdio --name my-server -- npx shadcn@latest mcp
226+
210227 # Proxy mode - wrap an MCP server (streamable-http)
211228 mcpc --proxy --transport-type streamable-http -- https://api.example.com/mcp
212229
@@ -263,6 +280,7 @@ function parseArgs(): {
263280 transportType ?: string ;
264281 proxyCommand ?: string [ ] ;
265282 mode ?: string ;
283+ name ?: string ;
266284} {
267285 const args = process . argv . slice ( 2 ) ;
268286 const result : {
@@ -275,6 +293,7 @@ function parseArgs(): {
275293 transportType ?: string ;
276294 proxyCommand ?: string [ ] ;
277295 mode ?: string ;
296+ name ?: string ;
278297 } = { } ;
279298
280299 for ( let i = 0 ; i < args . length ; i ++ ) {
@@ -313,6 +332,8 @@ function parseArgs(): {
313332 result . transportType = args [ ++ i ] ;
314333 } else if ( arg === "--mode" && i + 1 < args . length ) {
315334 result . mode = args [ ++ i ] ;
335+ } else if ( arg === "--name" && i + 1 < args . length ) {
336+ result . name = args [ ++ i ] ;
316337 } else if ( arg === "--" ) {
317338 // Everything after -- is the proxy command
318339 result . proxyCommand = args . slice ( i + 1 ) ;
0 commit comments