Skip to content

Commit dd0b824

Browse files
copiplot review changes
1 parent 2c0a77a commit dd0b824

5 files changed

Lines changed: 30 additions & 8 deletions

File tree

cloudsmith_cli/cli/commands/mcp.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import Dict, List
99

1010
import click
11+
import json5
1112

1213
from ...core.mcp import server
1314
from ...core.mcp.data import OpenAPITool
@@ -398,9 +399,14 @@ def configure_client(client_name, server_config, is_global=True, profile=None):
398399
if config_path.exists():
399400
with open(config_path) as f:
400401
try:
401-
config = json.load(f)
402-
except json.JSONDecodeError:
403-
raise ValueError(f"Invalid JSON in config file: {config_path}")
402+
# VS Code settings.json supports JSONC (comments and trailing commas)
403+
# Use json5 for VS Code to handle this, standard json for others
404+
if client_name == "vscode":
405+
config = json5.load(f)
406+
else:
407+
config = json.load(f)
408+
except (json.JSONDecodeError, ValueError) as e:
409+
raise ValueError(f"Invalid JSON in config file: {config_path}: {e}")
404410

405411
# Determine server name based on profile
406412
server_name = f"cloudsmith-{profile}" if profile else "cloudsmith"

cloudsmith_cli/cli/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def initialise_mcp(f):
348348
help="Show all tools",
349349
)
350350
@click.option(
351-
"-d",
351+
"-D",
352352
"--allow-destructive-tools",
353353
default=False,
354354
is_flag=True,

cloudsmith_cli/core/mcp/server.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,16 @@ async def load_openapi_spec(self):
209209
) as http_client:
210210
for version, endpoint in API_VERSIONS_TO_DISCOVER.items():
211211
spec_url = f"{self.api_base_url}/{version}/{endpoint}"
212-
response = await http_client.get(spec_url)
213-
response.raise_for_status()
212+
try:
213+
response = await http_client.get(spec_url)
214+
response.raise_for_status()
215+
except httpx.HTTPStatusError:
216+
# This version is not available, try the next one
217+
continue
214218
self.spec = response.json()
215219
await self._generate_tools_from_spec()
220+
# Stop after the first successful spec load to avoid duplicate tools
221+
break
216222

217223
def _get_tool_groups(self, tool_name: str) -> List[str]:
218224
"""
@@ -436,7 +442,9 @@ def _get_request_params(
436442
if "enum" in param_schema:
437443
if value not in param_schema["enum"]:
438444
allowed_values = ", ".join(param_schema["enum"])
439-
return f"Invalid value '{value}' for parameter '{key}'. Allowed values: {allowed_values}"
445+
raise ValueError(
446+
f"Invalid value '{value}' for parameter '{key}'. Allowed values: {allowed_values}"
447+
)
440448

441449
validated_arguments[key] = value
442450
else:
@@ -473,7 +481,12 @@ async def _execute_api_call(
473481
# Build URL with path parameters
474482
url = tool.base_url + tool.path
475483

476-
url, query_params, body_params = self._get_request_params(url, tool, arguments)
484+
try:
485+
url, query_params, body_params = self._get_request_params(
486+
url, tool, arguments
487+
)
488+
except ValueError as e:
489+
return str(e)
477490

478491
if tool.query_filter:
479492
parsed_simplified_filter = parse.parse_qs(tool.query_filter)

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ jaraco-context==6.1.0
9494
# via keyring
9595
jaraco-functools==4.4.0
9696
# via keyring
97+
json5==0.13.0
98+
# via cloudsmith-cli (setup.py)
9799
keyring==25.7.0
98100
# via cloudsmith-cli (setup.py)
99101
mccabe==0.7.0

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def get_long_description():
5454
"click-didyoumean>=0.0.3",
5555
"click-spinner>=0.1.7",
5656
"cloudsmith-api>=2.0.22,<3.0", # Compatible upto (but excluding) 3.0+
57+
"json5>=0.9.0", # For parsing JSONC (JSON with comments) in VS Code settings
5758
"keyring>=25.4.1",
5859
"mcp==1.9.1",
5960
"toon-python==0.1.2",

0 commit comments

Comments
 (0)