Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- `cloudsmith mcp start` now exposes only read-only tools by default. Tools that change data or return credentials need `--allow-destructive-tools` (`-D`). A tool changes data when it uses POST, PUT, PATCH or DELETE, or when its name contains `delete`, `destroy` or `remove`. `--all-tools` (`-a`) enables every tool group and ignores `mcp_allowed_tools` and `mcp_allowed_tool_groups`. It no longer enables these tools without `-D`. When your allowlist matches tools that need `-D`, `mcp start`, `mcp list_tools` and `mcp list_groups` show a warning. `mcp configure` now accepts `-a` and `-D` and keeps them in the client configuration. Tools that change data now have `destructiveHint` set to `true`. (#620)

- `repos create`/`update`, `upstream <format> create`/`update` and `policy deny|license|vulnerability create`/`update` now report a usage error when the config file isn't valid JSON or doesn't hold a JSON object, for example a file with a trailing comma. Previously the command crashed with a `JSONDecodeError` or `AttributeError` traceback.

- Fixed `cloudsmith download` choosing a package that can't be downloaded. The command also found packages that failed to sync or haven't finished, such as a failed duplicate upload of the same version. With `--yes`, it then chose the failed package, because it was uploaded last, and the download failed with HTTP 404. The command now searches only packages that have finished syncing.

## [1.31.3] - 2026-11-17
Expand Down
60 changes: 52 additions & 8 deletions cloudsmith_cli/cli/commands/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ def start(
with handle_api_exceptions(
ctx, opts=opts, context_msg=SPEC_LOAD_ERROR_MESSAGE, err=True
):
mcp_server.run()
mcp_server.run(
on_tools_loaded=lambda: warn_hidden_tools(
mcp_server,
"run `cloudsmith mcp configure --allow-destructive-tools`, "
"then restart the MCP client",
)
)


@mcp_.command(name="list_tools")
Expand All @@ -88,6 +94,10 @@ def list_tools(
):
tools = mcp_server.list_tools()

warn_hidden_tools(
mcp_server, "run `cloudsmith mcp list_tools --allow-destructive-tools`"
)

if not use_stderr:
click.secho("OK", fg="green", err=use_stderr)

Expand Down Expand Up @@ -125,6 +135,10 @@ def list_groups(
):
groups = mcp_server.list_groups()

warn_hidden_tools(
mcp_server, "run `cloudsmith mcp list_groups --allow-destructive-tools`"
)

if not use_stderr:
click.secho("OK", fg="green", err=use_stderr)

Expand All @@ -136,6 +150,21 @@ def list_groups(
print_groups(groups)


def warn_hidden_tools(mcp_server: server.DynamicMCPServer, fix: str) -> None:
"""Warn on stderr about allowlisted tools that need --allow-destructive-tools."""
hidden = mcp_server.hidden_allowlisted_tools
if not hidden:
return
count = len(hidden)
click.secho(
f"Warning: {count} {'tools' if count != 1 else 'tool'} in your MCP allowlist "
f"{'are' if count != 1 else 'is'} hidden without --allow-destructive-tools: "
f"{', '.join(hidden)}\nFix: {fix}",
fg="yellow",
err=True,
)


def print_tools(tool_list: dict[str, OpenAPITool]):
"""Print tools as a table or output in another format."""

Expand Down Expand Up @@ -214,10 +243,17 @@ def print_groups(group_list: dict[str, list[str]]):
default=True,
help="Configure globally (default) or in current project directory (local)",
)
@decorators.MCP_ALL_TOOLS_OPTION
@decorators.MCP_ALLOW_DESTRUCTIVE_TOOLS_OPTION
@decorators.initialise_api
@click.pass_context
def configure( # pylint: disable=unused-argument
ctx: click.Context, opts: Options, client: str | None, is_global: bool
ctx: click.Context,
opts: Options,
client: str | None,
is_global: bool,
all_tools: bool,
allow_destructive_tools: bool,
) -> None:
"""
Configure the Cloudsmith MCP server for supported clients.
Expand Down Expand Up @@ -249,7 +285,7 @@ def configure( # pylint: disable=unused-argument
profile = ctx.meta.get("profile")

# Determine the best command to run the MCP server
server_config = _get_server_config(profile)
server_config = _get_server_config(profile, all_tools, allow_destructive_tools)

clients_to_configure = []
if client:
Expand Down Expand Up @@ -318,7 +354,9 @@ def configure( # pylint: disable=unused-argument
click.echo(click.style("\nNo clients were configured successfully", fg="red"))


def _get_server_config(profile=None):
def _get_server_config(
profile=None, all_tools: bool = False, allow_destructive_tools: bool = False
):
"""Determine the first available command configuration to run the MCP server."""
is_frozen = getattr(sys, "frozen", False)
in_venv = hasattr(sys, "real_prefix") or (
Expand All @@ -330,24 +368,30 @@ def _get_server_config(profile=None):
if profile:
base_args.extend(["-P", profile])

start_args = ["mcp", "start"]
if all_tools:
start_args.append("--all-tools")
if allow_destructive_tools:
start_args.append("--allow-destructive-tools")

if is_frozen:
return {"command": sys.executable, "args": base_args + ["mcp", "start"]}
return {"command": sys.executable, "args": base_args + start_args}

# In a venv, always use python -m to ensure we use the venv's packages
if in_venv:
return {
"command": sys.executable,
"args": ["-m", "cloudsmith_cli"] + base_args + ["mcp", "start"],
"args": ["-m", "cloudsmith_cli"] + base_args + start_args,
}

# Otherwise, try to find cloudsmith in PATH, fall back to python -m
cloudsmith_cmd = shutil.which("cloudsmith")
if cloudsmith_cmd:
return {"command": cloudsmith_cmd, "args": base_args + ["mcp", "start"]}
return {"command": cloudsmith_cmd, "args": base_args + start_args}

return {
"command": sys.executable,
"args": ["-m", "cloudsmith_cli"] + base_args + ["mcp", "start"],
"args": ["-m", "cloudsmith_cli"] + base_args + start_args,
}


Expand Down
40 changes: 26 additions & 14 deletions cloudsmith_cli/cli/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,21 +930,33 @@ def call_print_rate_limit_info_with_opts(rate_info):
return resolve_credentials(wrapper)


MCP_ALL_TOOLS_OPTION = click.option(
"-a",
"--all-tools",
default=False,
is_flag=True,
help=(
"Enable every tool group and ignore mcp_allowed_tools and "
"mcp_allowed_tool_groups. Tools that change data or return credentials "
"also need --allow-destructive-tools"
),
)

MCP_ALLOW_DESTRUCTIVE_TOOLS_OPTION = click.option(
"-D",
"--allow-destructive-tools",
default=False,
is_flag=True,
help=(
"Allow tools that change data or return credentials in the enabled tool "
"groups. Add --all-tools to enable every tool group"
),
)


def initialise_mcp(f):
@click.option(
"-a",
"--all-tools",
default=False,
is_flag=True,
help="Show all tools",
)
@click.option(
"-D",
"--allow-destructive-tools",
default=False,
is_flag=True,
help="Allow destructive tools to be used",
)
@MCP_ALL_TOOLS_OPTION
@MCP_ALLOW_DESTRUCTIVE_TOOLS_OPTION
@click.pass_context
@functools.wraps(f)
def wrapper(ctx, *args, **kwargs):
Expand Down
Loading
Loading