Skip to content

Commit dd2a9ea

Browse files
committed
fix: --active-only and toggle fixes for all resource groups
Branch: InitialCLI Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
1 parent 4f78fbb commit dd2a9ea

6 files changed

Lines changed: 54 additions & 34 deletions

File tree

cforge/commands/resources/a2a.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828

2929

3030
def a2a_list(
31+
active_only: bool = typer.Option(False, "--active-only", help="Show only active agents"),
3132
json_output: bool = typer.Option(False, "--json", help="Output as JSON"),
3233
) -> None:
3334
"""List all A2A agents."""
3435
console = get_console()
3536

3637
try:
37-
result = make_authenticated_request("GET", "/a2a")
38+
result = make_authenticated_request("GET", "/a2a", params={"include_inactive": not active_only})
3839

3940
if json_output:
4041
print_json(result, "A2A Agents")

cforge/commands/resources/mcp_servers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828

2929

3030
def mcp_servers_list(
31+
active_only: bool = typer.Option(False, "--active-only", help="Show only active MCP servers"),
3132
json_output: bool = typer.Option(False, "--json", help="Output as JSON"),
3233
) -> None:
3334
"""List all MCP server peers."""
3435
console = get_console()
3536

3637
try:
37-
result = make_authenticated_request("GET", "/gateways")
38+
result = make_authenticated_request("GET", "/gateways", params={"include_inactive": not active_only})
3839

3940
if json_output:
4041
print_json(result, "MCP Servers")

cforge/commands/resources/prompts.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929

3030
def prompts_list(
3131
mcp_server_id: Optional[str] = typer.Option(None, "--mcp-server-id", "-m", help="Filter by MCP Server ID"),
32+
active_only: bool = typer.Option(False, "--active-only", help="Show only active prompts"),
3233
json_output: bool = typer.Option(False, "--json", help="Output as JSON"),
3334
) -> None:
3435
"""List all prompts in the gateway."""
3536
console = get_console()
3637

3738
try:
38-
params: Dict[str, Any] = {}
39+
params: Dict[str, Any] = {"include_inactive": not active_only}
3940
if mcp_server_id:
4041
params["gateway_id"] = mcp_server_id
4142

@@ -165,7 +166,16 @@ def prompts_toggle(
165166
console = get_console()
166167

167168
try:
168-
result = make_authenticated_request("POST", f"/prompts/{prompt_id}/toggle")
169+
current_status = make_authenticated_request("GET", "/prompts", params={"include_inactive": True})
170+
assert isinstance(current_status, list)
171+
this_status = [res for res in current_status if res.get("id") == prompt_id]
172+
if not this_status:
173+
console.print(f"[red]Prompt not found: {prompt_id}[/red]")
174+
raise typer.Exit(1)
175+
assert len(this_status) == 1, "Multiple prompts with same ID found"
176+
assert isinstance(this_status[0], dict)
177+
activate = not this_status[0].get("isActive")
178+
result = make_authenticated_request("POST", f"/prompts/{prompt_id}/toggle", params={"activate": activate})
169179
console.print("[green]✓ Prompt toggled successfully![/green]")
170180
print_json(result, "Prompt Status")
171181

cforge/commands/resources/resources.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929

3030
def resources_list(
3131
mcp_server_id: Optional[str] = typer.Option(None, "--mcp-server-id", "-m", help="Filter by MCP Server ID"),
32+
active_only: bool = typer.Option(False, "--active-only", help="Show only active resources"),
3233
json_output: bool = typer.Option(False, "--json", help="Output as JSON"),
3334
) -> None:
3435
"""List all resources in the gateway."""
3536
console = get_console()
3637

3738
try:
38-
params: Dict[str, Any] = {}
39+
params: Dict[str, Any] = {"include_inactive": not active_only}
3940
if mcp_server_id:
4041
params["gateway_id"] = mcp_server_id
4142

@@ -168,20 +169,15 @@ def resources_toggle(
168169
console = get_console()
169170

170171
try:
171-
current_status = make_authenticated_request("GET", "/resources")
172+
current_status = make_authenticated_request("GET", "/resources", params={"include_inactive": True})
172173
assert isinstance(current_status, list)
173174
this_status = [res for res in current_status if res.get("id") == resource_id]
174-
# NOTE: If the resources was previously deactivated, it will not show up
175-
# in a list call, but will still be in the database. The only way to
176-
# distinguish between this and a bad resource ID is to do a separate GET
177-
# call (which will not return the active status), but the simpler way is
178-
# to just try toggling and letting a 404 error be raised.
179175
if not this_status:
180-
activate = True
181-
else:
182-
assert len(this_status) == 1, "Multiple resources with same ID found"
183-
assert isinstance(this_status[0], dict)
184-
activate = not this_status[0].get("isActive")
176+
console.print(f"[red]Resource not found: {resource_id}[/red]")
177+
raise typer.Exit(1)
178+
assert len(this_status) == 1, "Multiple resources with same ID found"
179+
assert isinstance(this_status[0], dict)
180+
activate = not this_status[0].get("isActive")
185181
result = make_authenticated_request("POST", f"/resources/{resource_id}/toggle", params={"activate": activate})
186182
console.print("[green]✓ Resource toggled successfully![/green]")
187183
print_json(result, "Resource Status")

cforge/commands/resources/tools.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Standard
1111
import json
1212
from pathlib import Path
13-
from typing import Any, Optional
13+
from typing import Any, Dict, Optional
1414

1515
# Third-Party
1616
import typer
@@ -36,11 +36,9 @@ def tools_list(
3636
console = get_console()
3737

3838
try:
39-
params: dict[str, Any] = {}
39+
params: Dict[str, Any] = {"include_inactive": not active_only}
4040
if mcp_server_id:
4141
params["gateway_id"] = mcp_server_id
42-
if active_only:
43-
params["active"] = True
4442

4543
result = make_authenticated_request("GET", "/tools", params=params)
4644

@@ -63,7 +61,7 @@ def tools_list(
6361

6462

6563
def tools_get(
66-
tool_id: int = typer.Argument(..., help="Tool ID"),
64+
tool_id: str = typer.Argument(..., help="Tool ID"),
6765
json_output: bool = typer.Option(False, "--json", help="Output as JSON"),
6866
) -> None:
6967
"""Get details of a specific tool."""
@@ -117,7 +115,7 @@ def tools_create(
117115

118116

119117
def tools_update(
120-
tool_id: int = typer.Argument(..., help="Tool ID"),
118+
tool_id: str = typer.Argument(..., help="Tool ID"),
121119
data_file: Optional[Path] = typer.Argument(None, help="JSON file containing updated tool data"),
122120
) -> None:
123121
"""Update an existing tool."""
@@ -142,7 +140,7 @@ def tools_update(
142140

143141

144142
def tools_delete(
145-
tool_id: int = typer.Argument(..., help="Tool ID"),
143+
tool_id: str = typer.Argument(..., help="Tool ID"),
146144
confirm: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation"),
147145
) -> None:
148146
"""Delete a tool."""
@@ -163,13 +161,19 @@ def tools_delete(
163161

164162

165163
def tools_toggle(
166-
tool_id: int = typer.Argument(..., help="Tool ID"),
164+
tool_id: str = typer.Argument(..., help="Tool ID"),
167165
) -> None:
168166
"""Toggle tool active status."""
169167
console = get_console()
170168

171169
try:
172-
result = make_authenticated_request("POST", f"/tools/{tool_id}/toggle")
170+
current_status = make_authenticated_request("GET", f"/tools/{tool_id}")
171+
assert isinstance(current_status, dict)
172+
if current_status["enabled"]:
173+
activate = False
174+
else:
175+
activate = True
176+
result = make_authenticated_request("POST", f"/tools/{tool_id}/toggle", params={"activate": activate})
173177
console.print("[green]✓ Tool toggled successfully![/green]")
174178
print_json(result, "Tool Status")
175179

cforge/commands/resources/virtual_servers.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ def _fixup_payload(data: dict) -> dict:
4141

4242

4343
def virtual_servers_list(
44+
active_only: bool = typer.Option(False, "--active-only", help="Show only active virtual servers"),
4445
json_output: bool = typer.Option(False, "--json", help="Output as JSON"),
4546
) -> None:
4647
"""List all virtual servers."""
4748
console = get_console()
4849

4950
try:
50-
result = make_authenticated_request("GET", "/servers")
51+
result = make_authenticated_request("GET", "/servers", params={"include_inactive": not active_only})
5152

5253
if json_output:
5354
print_json(result, "Virtual Servers")
@@ -68,7 +69,7 @@ def virtual_servers_list(
6869

6970

7071
def virtual_servers_get(
71-
server_id: int = typer.Argument(..., help="Server ID"),
72+
server_id: str = typer.Argument(..., help="Server ID"),
7273
) -> None:
7374
"""Get details of a specific virtual server."""
7475
try:
@@ -122,7 +123,7 @@ def virtual_servers_create(
122123

123124

124125
def virtual_servers_update(
125-
server_id: int = typer.Argument(..., help="Server ID"),
126+
server_id: str = typer.Argument(..., help="Server ID"),
126127
data_file: Optional[Path] = typer.Argument(None, help="JSON file containing updated server data"),
127128
) -> None:
128129
"""Update an existing virtual server."""
@@ -148,7 +149,7 @@ def virtual_servers_update(
148149

149150

150151
def virtual_servers_delete(
151-
server_id: int = typer.Argument(..., help="Server ID"),
152+
server_id: str = typer.Argument(..., help="Server ID"),
152153
confirm: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation"),
153154
) -> None:
154155
"""Delete a virtual server."""
@@ -169,13 +170,20 @@ def virtual_servers_delete(
169170

170171

171172
def virtual_servers_toggle(
172-
server_id: int = typer.Argument(..., help="Server ID"),
173+
server_id: str = typer.Argument(..., help="Server ID"),
173174
) -> None:
174175
"""Toggle virtual server active status."""
175176
console = get_console()
176177

177178
try:
178-
result = make_authenticated_request("POST", f"/servers/{server_id}/toggle")
179+
current_status = make_authenticated_request("GET", f"/servers/{server_id}")
180+
assert isinstance(current_status, dict)
181+
if current_status["isActive"]:
182+
activate = False
183+
else:
184+
activate = True
185+
result = make_authenticated_request("POST", f"/servers/{server_id}/toggle", params={"activate": activate})
186+
assert isinstance(result, dict)
179187
console.print("[green]✓ Virtual server toggled successfully![/green]")
180188
print_json(result, "Virtual Server Status")
181189

@@ -184,7 +192,7 @@ def virtual_servers_toggle(
184192

185193

186194
def virtual_servers_tools(
187-
server_id: int = typer.Argument(..., help="Server ID"),
195+
server_id: str = typer.Argument(..., help="Server ID"),
188196
json_output: bool = typer.Option(False, "--json", help="Output as JSON"),
189197
) -> None:
190198
"""List tools available in a virtual server."""
@@ -207,7 +215,7 @@ def virtual_servers_tools(
207215

208216

209217
def virtual_servers_resources(
210-
server_id: int = typer.Argument(..., help="Server ID"),
218+
server_id: str = typer.Argument(..., help="Server ID"),
211219
json_output: bool = typer.Option(False, "--json", help="Output as JSON"),
212220
) -> None:
213221
"""List resources available in a virtual server."""
@@ -230,7 +238,7 @@ def virtual_servers_resources(
230238

231239

232240
def virtual_servers_prompts(
233-
server_id: int = typer.Argument(..., help="Server ID"),
241+
server_id: str = typer.Argument(..., help="Server ID"),
234242
json_output: bool = typer.Option(False, "--json", help="Output as JSON"),
235243
) -> None:
236244
"""List prompts available in a virtual server."""

0 commit comments

Comments
 (0)