@@ -404,13 +404,20 @@ def version():
404404
405405@cli .command (help = "Start the MCP server" )
406406def mcp_server ():
407- from fastmcp import FastMCP
408- from fastmcp .exceptions import ToolError
407+ try :
408+ from fastmcp import FastMCP
409+ from fastmcp .exceptions import ToolError
410+ except ImportError :
411+ raise RSConnectException (
412+ "The fastmcp package is required for MCP server functionality. "
413+ "Install it with: pip install rsconnect-python[mcp]"
414+ )
409415
410416 mcp = FastMCP ("Connect MCP" )
411417
412418 # Discover all commands at startup
413419 from .mcp_deploy_context import discover_all_commands
420+
414421 all_commands_info = discover_all_commands (cli )
415422
416423 @mcp .tool ()
@@ -431,10 +438,7 @@ def get_command_info(
431438 parts = command_path .strip ().split ()
432439 if not parts :
433440 available_commands = list (all_commands_info ["commands" ].keys ())
434- return {
435- "error" : "Command path cannot be empty" ,
436- "available_commands" : available_commands
437- }
441+ return {"error" : "Command path cannot be empty" , "available_commands" : available_commands }
438442
439443 current_info = all_commands_info
440444 current_path = []
@@ -451,11 +455,8 @@ def get_command_info(
451455 # try to return useful messaging for invalid subcommands
452456 if part not in current_info ["commands" ]:
453457 available = list (current_info ["commands" ].keys ())
454- path_str = ' ' .join (current_path ) if current_path else "top level"
455- return {
456- "error" : f"Command '{ part } ' not found in { path_str } " ,
457- "available_commands" : available
458- }
458+ path_str = " " .join (current_path ) if current_path else "top level"
459+ return {"error" : f"Command '{ part } ' not found in { path_str } " , "available_commands" : available }
459460
460461 current_info = current_info ["commands" ][part ]
461462 current_path .append (part )
@@ -467,7 +468,7 @@ def get_command_info(
467468 "name" : current_info .get ("name" , parts [- 1 ]),
468469 "description" : current_info .get ("description" ),
469470 "available_subcommands" : list (current_info ["commands" ].keys ()),
470- "message" : f"The '{ ' ' .join (parts )} ' command requires a subcommand."
471+ "message" : f"The '{ ' ' .join (parts )} ' command requires a subcommand." ,
471472 }
472473 else :
473474 return {
@@ -476,7 +477,7 @@ def get_command_info(
476477 "name" : current_info .get ("name" , parts [- 1 ]),
477478 "description" : current_info .get ("description" ),
478479 "parameters" : current_info .get ("parameters" , []),
479- "shell" : "bash"
480+ "shell" : "bash" ,
480481 }
481482 except Exception as e :
482483 raise ToolError (f"Failed to retrieve command info: { str (e )} " )
0 commit comments