-
Notifications
You must be signed in to change notification settings - Fork 27
feat: simple MCP server #710
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,15 +5,16 @@ description = "The Posit Connect command-line interface." | |
| authors = [{ name = "Posit, PBC", email = "rsconnect@posit.co" }] | ||
| license = { file = "LICENSE.md" } | ||
| readme = { file = "README.md", content-type = "text/markdown" } | ||
| requires-python = ">=3.8" | ||
| requires-python = ">=3.10" | ||
|
|
||
| dependencies = [ | ||
| "typing-extensions>=4.8.0", | ||
| "pip>=10.0.0", | ||
| "semver>=2.0.0,<4.0.0", | ||
| "pyjwt>=2.4.0", | ||
| "click>=8.0.0", | ||
| "toml>=0.10; python_version < '3.11'" | ||
| "toml>=0.10; python_version < '3.11'", | ||
| "fastmcp==2.12.4" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ] | ||
|
|
||
| dynamic = ["version"] | ||
|
|
||
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,123 @@ | ||
| """ | ||
| 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fastmcprequires >=3.10 which would be a breaking change... what's the protocol around doing something like this? Is this reason enough to move this work off ofrsconnect-python?