- 
                Notifications
    You must be signed in to change notification settings 
- Fork 27
feat: simple MCP server #712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      dfc1252
              
                initial command
              
              
                joshyam-k b82ebf6
              
                testing new approach
              
              
                joshyam-k 5ad714a
              
                fix ordering of args and opts
              
              
                joshyam-k 7cd39c3
              
                generalize. tests written by claude
              
              
                joshyam-k 775bec3
              
                change fastmcp dependency approach
              
              
                joshyam-k c48063b
              
                improve docstrings
              
              
                joshyam-k 558408e
              
                add better docs
              
              
                joshyam-k 5413bf9
              
                update changelog
              
              
                joshyam-k File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ::: mkdocs-click | ||
| :module: rsconnect.main | ||
| :command: mcp_server | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| """ | ||
| Programmatically discover all parameters for rsconnect commands. | ||
| This helps MCP tools understand how to use the cli. | ||
| """ | ||
|  | ||
| import json | ||
| from typing import Any, Dict | ||
|  | ||
| import click | ||
|  | ||
|  | ||
| def extract_parameter_info(param: click.Parameter) -> Dict[str, Any]: | ||
| """Extract detailed information from a Click parameter.""" | ||
| info: Dict[str, Any] = {} | ||
|  | ||
| if isinstance(param, click.Option) and param.opts: | ||
| # Use the longest option name (usually the full form without dashes) | ||
| mcp_arg_name = max(param.opts, key=len).lstrip("-").replace("-", "_") | ||
| info["name"] = mcp_arg_name | ||
| info["cli_flags"] = param.opts | ||
| info["param_type"] = "option" | ||
| else: | ||
| info["name"] = param.name | ||
| if isinstance(param, click.Argument): | ||
| info["param_type"] = "argument" | ||
|  | ||
| # extract help text for added context | ||
| help_text = getattr(param, "help", None) | ||
| if help_text: | ||
| info["description"] = help_text | ||
|  | ||
| if isinstance(param, click.Option): | ||
| # Boolean flags | ||
| if param.is_flag: | ||
| info["type"] = "boolean" | ||
| info["default"] = param.default or False | ||
|  | ||
| # choices | ||
| elif param.type and hasattr(param.type, "choices"): | ||
| info["type"] = "string" | ||
| info["choices"] = list(param.type.choices) | ||
|  | ||
| # multiple | ||
| elif param.multiple: | ||
| info["type"] = "array" | ||
| info["items"] = {"type": "string"} | ||
|  | ||
| # files | ||
| elif isinstance(param.type, click.Path): | ||
| info["type"] = "string" | ||
| info["format"] = "path" | ||
| if param.type.exists: | ||
| info["path_must_exist"] = True | ||
| if param.type.file_okay and not param.type.dir_okay: | ||
| info["path_type"] = "file" | ||
| elif param.type.dir_okay and not param.type.file_okay: | ||
| info["path_type"] = "directory" | ||
|  | ||
| # default | ||
| else: | ||
| info["type"] = "string" | ||
|  | ||
| # defaults (important to avoid noise in returned command) | ||
| if param.default is not None and not param.is_flag: | ||
| if isinstance(param.default, tuple): | ||
| info["default"] = list(param.default) | ||
| elif isinstance(param.default, (str, int, float, bool, list, dict)): | ||
| info["default"] = param.default | ||
|  | ||
| # required params | ||
| info["required"] = param.required | ||
|  | ||
| return info | ||
|  | ||
|  | ||
| def discover_single_command(cmd: click.Command) -> Dict[str, Any]: | ||
| """Discover a single command and its parameters.""" | ||
| cmd_info = {"name": cmd.name, "description": cmd.help, "parameters": []} | ||
|  | ||
| for param in cmd.params: | ||
| if param.name in ["verbose", "v"]: | ||
| continue | ||
|  | ||
| param_info = extract_parameter_info(param) | ||
| cmd_info["parameters"].append(param_info) | ||
|  | ||
| return cmd_info | ||
|  | ||
|  | ||
| def discover_command_group(group: click.Group) -> Dict[str, Any]: | ||
| """Discover all commands in a command group and their parameters.""" | ||
| result = {"name": group.name, "description": group.help, "commands": {}} | ||
|  | ||
| for cmd_name, cmd in group.commands.items(): | ||
| if isinstance(cmd, click.Group): | ||
| # recursively discover nested command groups | ||
| result["commands"][cmd_name] = discover_command_group(cmd) | ||
| else: | ||
| result["commands"][cmd_name] = discover_single_command(cmd) | ||
|  | ||
| return result | ||
|  | ||
|  | ||
| def discover_all_commands(cli: click.Group) -> Dict[str, Any]: | ||
| """Discover all commands in the CLI and their parameters.""" | ||
| return discover_command_group(cli) | ||
|  | ||
|  | ||
| if __name__ == "__main__": | ||
| from rsconnect.main import cli | ||
|  | ||
| # Discover all commands in the CLI | ||
| # use this for testing/debugging | ||
| all_commands = discover_all_commands(cli) | ||
| print(json.dumps(all_commands, indent=2)) | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.