diff --git a/packages/cli-v3/src/dev/mcpServer.ts b/packages/cli-v3/src/dev/mcpServer.ts index 1ddfa9ca3..c63926e1d 100644 --- a/packages/cli-v3/src/dev/mcpServer.ts +++ b/packages/cli-v3/src/dev/mcpServer.ts @@ -182,6 +182,26 @@ server.tool( } ); +server.tool( + "get-run-logs", + "Retrieve the logs output of a task run.", + { + runId: z.string().describe("The ID of the task run to get"), + }, + async ({ runId }) => { + const result = await sdkApiClient.listRunEvents(runId); + + return { + content: [ + { + text: JSON.stringify(result, null, 2), + type: "text", + }, + ], + }; + } +); + const app = polka(); app.get("/sse", (_req, res) => { mcpTransport = new SSEServerTransport("/messages", res); diff --git a/packages/core/src/v3/apiClient/index.ts b/packages/core/src/v3/apiClient/index.ts index 873a0b312..a10171d0e 100644 --- a/packages/core/src/v3/apiClient/index.ts +++ b/packages/core/src/v3/apiClient/index.ts @@ -404,6 +404,18 @@ export class ApiClient { ); } + listRunEvents(runId: string, requestOptions?: ZodFetchOptions) { + return zodfetch( + z.any(), // TODO: define a proper schema for this + `${this.baseUrl}/api/v1/runs/${runId}/events`, + { + method: "GET", + headers: this.#getHeaders(false), + }, + mergeRequestOptions(this.defaultRequestOptions, requestOptions) + ); + } + addTags(runId: string, body: AddTagsRequestBody, requestOptions?: ZodFetchOptions) { return zodfetch( z.object({ message: z.string() }),