MCPcopy
hub / github.com/strukto-ai/mirage / execute

Function execute

python/mirage/server/routers/execute.py:91–133  ·  view source on GitHub ↗
(
        workspace_id: str,
        request: Request,
        background: bool = Query(False),
)

Source from the content-addressed store, hash-verified

89
90@router.post("")
91async def execute(
92 workspace_id: str,
93 request: Request,
94 background: bool = Query(False),
95) -> Response:
96 entry = _require_entry(request, workspace_id)
97 job_table = request.app.state.jobs
98 content_type = request.headers.get("content-type", "")
99 req_obj, stdin_bytes = await _parse_execute_body(request, content_type)
100 schedule = functools.partial(_schedule_on_runner, entry.runner)
101 job = job_table.submit(
102 workspace_id=workspace_id,
103 command=req_obj.command,
104 schedule=schedule,
105 coro_factory=_make_coro_factory(
106 entry.runner,
107 _build_execute_kwargs(req_obj, stdin_bytes),
108 ),
109 )
110 if background:
111 return Response(
112 content=BackgroundResponse(
113 job_id=job.id,
114 workspace_id=workspace_id,
115 submitted_at=job.submitted_at,
116 ).model_dump_json(),
117 media_type="application/json",
118 status_code=202,
119 headers={"X-Mirage-Job-Id": job.id},
120 )
121 await job_table.wait(job.id)
122 if job.status == JobStatus.CANCELED:
123 raise HTTPException(status_code=499, detail="job canceled")
124 if job.status == JobStatus.FAILED:
125 raise HTTPException(status_code=500,
126 detail=job.error or "execute failed")
127 result_dict = await io_result_to_dict(job.result)
128 return Response(
129 content=json.dumps(result_dict),
130 media_type="application/json",
131 status_code=200,
132 headers={"X-Mirage-Job-Id": job.id},
133 )
134
135
136async def _parse_execute_body(

Callers

nothing calls this directly

Calls 9

io_result_to_dictFunction · 0.90
_parse_execute_bodyFunction · 0.85
_make_coro_factoryFunction · 0.85
_build_execute_kwargsFunction · 0.85
BackgroundResponseClass · 0.85
_require_entryFunction · 0.70
getMethod · 0.65
submitMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected