fix: accept the 'local' compute id in compute tools

The compute_get/compute_images MCP tools typed compute_id as a UUID, so
passing 'local' (the actual id of the built-in compute, which the
compute_images description itself pointed to) was rejected by schema
validation. Both tools now take a string defaulting to 'local', and the
compute_get REST route resolves 'local' through the controller since the
local compute has no database entry.
This commit is contained in:
YueGuobin committed 2026-08-26 00:44:57 +08:00
1 parent 6703e50487
commit df25e037ea
5 files changed
+63 -16

No files matched your search

+38
View File
@@ -553,6 +553,44 @@ class TestImage:
assert result == {"message": "Image installation completed"}
class TestCompute:
mod = "computes"
def test_get_local_by_default(self, ctx):
from gns3server.agent.mcp.computes import get_compute_handler
with patch(f"{BASE}.{self.mod}._get_connector") as m:
conn = _mock_conn({"compute_id": "local", "name": "local"})
m.return_value = conn
result = get_compute_handler({}, ctx)
assert result["compute_id"] == "local"
url = conn.http_call.call_args[0][1]
assert url.endswith("/computes/local")
def test_get_explicit_compute_id(self, ctx):
from gns3server.agent.mcp.computes import get_compute_handler
with patch(f"{BASE}.{self.mod}._get_connector") as m:
conn = _mock_conn({"compute_id": "4fcfb6b5-5b0b-4f43-bd5e-e8ae2a69c8e6"})
m.return_value = conn
get_compute_handler({"compute_id": "4fcfb6b5-5b0b-4f43-bd5e-e8ae2a69c8e6"}, ctx)
url = conn.http_call.call_args[0][1]
assert url.endswith("/computes/4fcfb6b5-5b0b-4f43-bd5e-e8ae2a69c8e6")
def test_images_local_by_default(self, ctx):
from gns3server.agent.mcp.computes import get_compute_images_handler
with patch(f"{BASE}.{self.mod}._get_connector") as m:
conn = _mock_conn(["img1.qcow2"])
m.return_value = conn
result = get_compute_images_handler({"emulator": "qemu"}, ctx)
assert result["count"] == 1
url = conn.http_call.call_args[0][1]
assert url.endswith("/computes/local/qemu/images")
def test_images_requires_emulator(self, ctx):
from gns3server.agent.mcp.computes import get_compute_images_handler
assert "error" in get_compute_images_handler({}, ctx)
# ── Marker (traffic-insight) ────────────────────────────────────────────
@@ -79,6 +79,16 @@ class TestComputeRoutes:
assert response.status_code == status.HTTP_200_OK
assert response.json()["compute_id"] == str(test_compute.compute_id)
async def test_compute_get_local(self, app: FastAPI, client: AsyncClient, controller) -> None:
await controller.add_compute(
compute_id="local", name="local", host="127.0.0.1", port=3080, force=True, connect=False)
response = await client.get(app.url_path_for("get_compute", compute_id="local"))
assert response.status_code == status.HTTP_200_OK
assert response.json()["compute_id"] == "local"
assert response.json()["name"] == "local"
async def test_compute_update(self, app: FastAPI, client: AsyncClient, test_compute: Compute) -> None:
params = {