fix: fix projection to TS when fetching agnet in MCP

This commit is contained in:
Abhishek Kumar 2026-05-23 14:45:50 +05:30
parent 3892b58486
commit bbb4f91a27
12 changed files with 392 additions and 63 deletions

View file

@ -2,7 +2,9 @@ from fastapi import HTTPException
from api.db import db_client
from api.mcp_server.auth import authenticate_mcp_request
from api.mcp_server.tools._workflow_projection import project_workflow_to_sdk_view
from api.mcp_server.tracing import traced_tool
from api.mcp_server.ts_bridge import TsBridgeError
@traced_tool
@ -10,9 +12,9 @@ async def list_workflows(status: str | None = "active") -> list[dict]:
"""List agents (workflows) in the caller's organization.
Returns id, name, status, and created_at for each agent. Use
`get_workflow` to fetch a single agent's full definition. Defaults
to active agents; pass `status="archived"` to list archived agents,
or `status=None` to list all.
`get_workflow` to fetch a single agent's current SDK view and
metadata. Defaults to active agents; pass `status="archived"` to
list archived agents, or `status=None` to list all.
"""
user = await authenticate_mcp_request()
workflows = await db_client.get_all_workflows_for_listing(
@ -32,7 +34,11 @@ async def list_workflows(status: str | None = "active") -> list[dict]:
@traced_tool
async def get_workflow(workflow_id: int) -> dict:
"""Fetch a single agent by id, including its current published definition."""
"""Fetch a single agent by id, projected into the SDK code view.
Output shape:
{"id": int, "name": str, "status": str, "version": "draft" | "published" | "legacy", "version_number": int | None, "code": "<TS source>"}
"""
user = await authenticate_mcp_request()
workflow = await db_client.get_workflow(
workflow_id, organization_id=user.selected_organization_id
@ -40,11 +46,16 @@ async def get_workflow(workflow_id: int) -> dict:
if not workflow:
raise HTTPException(status_code=404, detail=f"Workflow {workflow_id} not found")
current = workflow.current_definition
try:
view = await project_workflow_to_sdk_view(workflow)
except TsBridgeError as e:
raise HTTPException(status_code=500, detail=f"Failed to generate code: {e}")
return {
"id": workflow.id,
"name": workflow.name,
"name": view["name"],
"status": workflow.status,
"definition": current.workflow_json if current else None,
"version_number": current.version_number if current else None,
"version": view["version"],
"version_number": view["version_number"],
"code": view["code"],
}