The platform for continuously improving AI agents.
Accept the IDs dedicated MCP tools return (#292)
Freyam Mehtac1f75db9ad4a
diff --git a/overbae/services/dedicated.py b/overbae/services/dedicated.pyindex af7cfb3c..ca6b10c7 100644--- a/overbae/services/dedicated.py+++ b/overbae/services/dedicated.py@@ -72,6 +72,19 @@ def live_for(deployed):)+def deployed_model(models, reference: str):+ """Find in `models` by id or model id, or by the id or public name of a dedicated row."""+ token = reference.strip().removeprefix("dedicated/")+ try:+ pk = uuid.UUID(token)+ except ValueError:+ pk = None+ found = None+ if pk is not None:+ found = models.filter(Q(pk=pk) | Q(dedicated_deployments__pk=pk)).first()+ return found or models.filter(model_id=token).first()++def lookup(model_id: str, project_ids):if not str(model_id).startswith("dedicated/"):return Nonediff --git a/overbae/services/mcp/resources.py b/overbae/services/mcp/resources.pyindex 0abeed24..0864f23d 100644--- a/overbae/services/mcp/resources.py+++ b/overbae/services/mcp/resources.py@@ -51,6 +51,7 @@ from overbae.models import ()from overbae.services import (activity,+ dedicated,dedicated_progress,inference_requests,model_workflows,@@ -1077,9 +1078,7 @@ def _finetune_resource(project, value: str, uri: str) -> dict:def _dedicated_payload(deployment) -> dict | None:- from overbae.services.dedicated import live_for-- row = live_for(deployment)+ row = dedicated.live_for(deployment)if row is None:return Nonereturn {@@ -1103,10 +1102,7 @@ def _deployment_resource(project, value: str, uri: str) -> dict:query = DeployedModel.objects.filter(project=project).select_related("finetuning_job__capability")- normalized_id = uuid_reference(value)- deployment = query.filter(id=normalized_id).first() if normalized_id else None- if deployment is None:- deployment = query.filter(model_id=value).first()+ deployment = dedicated.deployed_model(query, value)if deployment is None:raise _not_found("deployment", value)params = parse_qs(urlparse(uri).query, keep_blank_values=True)@@ -1543,6 +1539,8 @@ def _read_resource_sync(project, raw_uri: str) -> dict:raise _not_found("resource", raw_uri)segments = [unquote(part) for part in parsed.path.split("/") if part]host = parsed.netloc+ if host == "deployments" and len(segments) == 2 and segments[0] == "dedicated":+ return _deployment_resource(project, "/".join(segments), raw_uri)if host == "checkpoints" and len(segments) == 1:checkpoint = TrainingCheckpoint.objects.filter(job__project=project, pk=uuid_reference(segments[0])diff --git a/overbae/services/mcp/tools_dedicated.py b/overbae/services/mcp/tools_dedicated.pyindex ab812922..cd5fb99f 100644--- a/overbae/services/mcp/tools_dedicated.py+++ b/overbae/services/mcp/tools_dedicated.py@@ -17,25 +17,12 @@ from overbae.services.mcp.errors import MCPErrordef _deployed(context, value: str) -> DeployedModel:- query = DeployedModel.objects.filter(project=context.project)- row = query.filter(id=value).first() if _uuid(value) else None- if row is None:- row = query.filter(model_id=value).first()+ row = dedicated.deployed_model(DeployedModel.objects.filter(project=context.project), value)if row is None:raise MCPError("not_found", "Deployment not found.")return row-def _uuid(value: str) -> bool:- try:- from uuid import UUID-- UUID(value)- except ValueError:- return False- return True--def _output(row) -> DedicatedDeploymentOutput:return DedicatedDeploymentOutput(summary=f"Dedicated deployment {row.status} on {row.gpu_type}.",diff --git a/tests/test_mcp_inference.py b/tests/test_mcp_inference.pyindex 1e75980b..4968c6d2 100644--- a/tests/test_mcp_inference.py+++ b/tests/test_mcp_inference.py@@ -24,6 +24,7 @@ from overbae.models import ()from overbae.services import inference_live, inference_requestsfrom overbae.services.mcp.server import create_mcp_application+from overbae.services.provider_pricing import refresh_ratespytestmark = [pytest.mark.django_db, pytest.mark.covers("mcp-surface")]@@ -263,3 +264,46 @@ def test_job_poll_exposes_deployment_stage_and_status_change_time(serving):assert result["progress"]["stage"] == "warm"assert result["progress"]["deadline"] == serving.model.deployment_deadline.isoformat()assert result["updated_at"] == now.isoformat().replace("+00:00", "Z")+++@asgi_db+def test_dedicated_output_ids_reach_every_dedicated_tool_and_the_deployment_resource(+ serving, fake_modal+):+ refresh_rates()+ started = rpc(+ serving,+ "tools/call",+ {+ "name": "start_dedicated_deployment",+ "arguments": {"deployment": serving.model.model_id, "gpu_type": "H100"},+ },+ )["result"]["structuredContent"]++ for reference in (started["id"], started["model_id"]):+ offers = rpc(+ serving,+ "tools/call",+ {"name": "list_dedicated_gpus", "arguments": {"deployment": reference}},+ )["result"]["structuredContent"]+ assert offers["deployment"] == str(serving.model.id)+ contents = rpc(serving, "resources/read", {"uri": f"overmind://deployments/{reference}"})[+ "result"+ ]["contents"]+ assert json.loads(contents[0]["text"])["id"] == str(serving.model.id)++ updated = rpc(+ serving,+ "tools/call",+ {+ "name": "update_dedicated_deployment",+ "arguments": {"deployment": started["model_id"], "max_replicas": 2},+ },+ )["result"]["structuredContent"]+ assert updated["max_replicas"] == 2+ stopped = rpc(+ serving,+ "tools/call",+ {"name": "stop_dedicated_deployment", "arguments": {"deployment": started["id"]}},+ )["result"]["structuredContent"]+ assert stopped["status"] == "shutting_down"