@@ -355,6 +355,12 @@ def create_client(
355355 Note: Authentication is handled by start.bat/start.sh before this runs.
356356 The Claude SDK auto-detects credentials from the Claude CLI configuration
357357 """
358+ # Cache UI config once to avoid repeated file reads
359+ # This is used for both allowed_tools and MCP server configuration
360+ ui_mcp_disabled = os .getenv ("DISABLE_UI_MCP" , "" ).lower () == "true"
361+ ui_config = None if ui_mcp_disabled else get_ui_config_from_spec (project_dir )
362+ has_ui_mcp = ui_config is not None and ui_config .get ("has_mcp" , False )
363+
358364 # Select the feature MCP tools appropriate for this agent type
359365 feature_tools_map = {
360366 "coding" : CODING_AGENT_TOOLS ,
@@ -381,10 +387,8 @@ def create_client(
381387
382388 # Add UI MCP tools if the project uses a library with MCP support
383389 # UI MCP is available in both standard and YOLO mode
384- if os .getenv ("DISABLE_UI_MCP" , "" ).lower () != "true" :
385- ui_config = get_ui_config_from_spec (project_dir )
386- if ui_config and ui_config .get ("has_mcp" ):
387- allowed_tools .extend (UI_MCP_TOOLS )
390+ if has_ui_mcp :
391+ allowed_tools .extend (UI_MCP_TOOLS )
388392
389393 # Build permissions list.
390394 # We permit ALL feature MCP tools at the security layer (so the MCP server
@@ -421,10 +425,8 @@ def create_client(
421425 permissions_list .extend (PLAYWRIGHT_TOOLS )
422426
423427 # Add UI MCP tools to permissions if available
424- if os .getenv ("DISABLE_UI_MCP" , "" ).lower () != "true" :
425- ui_config = get_ui_config_from_spec (project_dir )
426- if ui_config and ui_config .get ("has_mcp" ):
427- permissions_list .extend (UI_MCP_TOOLS )
428+ if has_ui_mcp :
429+ permissions_list .extend (UI_MCP_TOOLS )
428430
429431 # Create comprehensive security settings
430432 # Note: Using relative paths ("./**") restricts access to project directory
@@ -509,52 +511,50 @@ def create_client(
509511
510512 # UI Components MCP server (available in both standard and YOLO mode)
511513 # Only added for libraries with MCP support (shadcn-ui, ark-ui)
512- if os .getenv ("DISABLE_UI_MCP" , "" ).lower () != "true" :
513- ui_config = get_ui_config_from_spec (project_dir )
514- if ui_config and ui_config .get ("has_mcp" ):
515- library = ui_config .get ("library" , "" )
516- framework = ui_config .get ("framework" , "react" )
514+ if has_ui_mcp and ui_config :
515+ library = ui_config .get ("library" , "" )
516+ framework = ui_config .get ("framework" , "react" )
517517
518- try :
519- npx_cmd = get_npx_command ()
520-
521- if library == "shadcn-ui" :
522- # shadcn/ui MCP server for React components
523- # Uses GitHub API - benefits from GITHUB_PERSONAL_ACCESS_TOKEN for rate limits
524- ui_mcp_args = [
525- "-y" ,
526- "--prefer-offline" ,
527- f"@jpisnice/shadcn-ui-mcp-server@{ SHADCN_MCP_VERSION } " ,
528- "--framework" , framework ,
529- ]
530- ui_mcp_env = {}
531- github_token = os . getenv ( "GITHUB_PERSONAL_ACCESS_TOKEN" )
532- if github_token :
533- ui_mcp_env [ "GITHUB_TOKEN" ] = github_token
534-
535- mcp_servers [ "ui_components" ] = {
536- "command" : npx_cmd ,
537- "args " : ui_mcp_args ,
538- "env" : ui_mcp_env if ui_mcp_env else None ,
539- }
540- print (f" - UI MCP: shadcn/ui ({ framework } )" )
541-
542- elif library == "ark-ui" :
543- # Ark UI MCP server for multi-framework headless components
544- ui_mcp_args = [
545- "-y" ,
546- "--prefer-offline" ,
547- f"@ark-ui/mcp@{ ARK_MCP_VERSION } " ,
548- ]
549- mcp_servers ["ui_components" ] = {
550- "command" : npx_cmd ,
551- "args" : ui_mcp_args ,
552- }
553- print (f" - UI MCP: Ark UI ({ framework } )" )
554-
555- except RuntimeError as e :
556- # npx not found - graceful degradation
557- print (f" - Warning: UI MCP disabled - { e } " )
518+ try :
519+ npx_cmd = get_npx_command ()
520+
521+ if library == "shadcn-ui" :
522+ # shadcn/ui MCP server for React components
523+ # Uses GitHub API - benefits from GITHUB_PERSONAL_ACCESS_TOKEN for rate limits
524+ ui_mcp_args = [
525+ "-y" ,
526+ "--prefer-offline" ,
527+ f"@jpisnice/shadcn-ui-mcp-server@{ SHADCN_MCP_VERSION } " ,
528+ "--framework" , framework ,
529+ ]
530+ ui_mcp_config : dict = {
531+ "command" : npx_cmd ,
532+ "args" : ui_mcp_args ,
533+ }
534+ # Only add env if there are environment variables to pass
535+ github_token = os . getenv ( "GITHUB_PERSONAL_ACCESS_TOKEN" )
536+ if github_token :
537+ ui_mcp_config [ "env" ] = { "GITHUB_TOKEN " : github_token }
538+
539+ mcp_servers [ "ui_components" ] = ui_mcp_config
540+ print (f" - UI MCP: shadcn/ui ({ framework } )" )
541+
542+ elif library == "ark-ui" :
543+ # Ark UI MCP server for multi-framework headless components
544+ ui_mcp_args = [
545+ "-y" ,
546+ "--prefer-offline" ,
547+ f"@ark-ui/mcp@{ ARK_MCP_VERSION } " ,
548+ ]
549+ mcp_servers ["ui_components" ] = {
550+ "command" : npx_cmd ,
551+ "args" : ui_mcp_args ,
552+ }
553+ print (f" - UI MCP: Ark UI ({ framework } )" )
554+
555+ except RuntimeError as e :
556+ # npx not found - graceful degradation
557+ print (f" - Warning: UI MCP disabled - { e } " )
558558
559559 # Build environment overrides for API endpoint configuration
560560 # Uses get_effective_sdk_env() which reads provider settings from the database,
0 commit comments