Skip to content

Comments

feat(mcp): stream workflow task status (ENG-161)#309

Merged
betterclever merged 5 commits intomainfrom
eng-161-stream-status
Feb 21, 2026
Merged

feat(mcp): stream workflow task status (ENG-161)#309
betterclever merged 5 commits intomainfrom
eng-161-stream-status

Conversation

@betterclever
Copy link
Contributor

@betterclever betterclever commented Feb 21, 2026

Overview

Migrates `run_workflow` from simple fire-and-poll to a native MCP Task — meaning AI agents now receive real-time streaming status updates as the workflow progresses, instead of blocking on a final result.

What Changed

`StudioMcpService` — task-augmented execution

  • `run_workflow` is now registered via `registerToolTask` with `taskSupport: 'required'`, using the experimental MCP Task API
  • A background `monitorWorkflowRun` loop polls Temporal run status and pushes updates via `taskStore.updateTaskStatus` and `taskStore.storeTaskResult`
  • `McpServer` is initialised with `InMemoryTaskStore` + `InMemoryTaskMessageQueue` so task state persists across HTTP requests within the same process

Key bug fixed in this PR

The initial implementation had a double terminal-state bug: `updateTaskStatus` was called first (setting the task status to `completed`), then `storeTaskResult` threw an internal error because the SDK refuses to overwrite a task already in a terminal state. Fixed by skipping `updateTaskStatus` for terminal run states and letting `storeTaskResult` perform the transition itself.

Stream Message Sequence

```
taskCreated → { taskId, status: "working" }
taskStatus → { status: "working", statusMessage: "RUNNING" }
...
taskStatus → { status: "completed", statusMessage: "COMPLETED" }
result → { content: [{ type: "text", text: "{ outputs: ... }" }] }
```

Testing

Test Status
`studio-mcp.service.spec.ts` — 21 unit tests ✅ pass
`studio-mcp-agent.test.ts` — AI SDK agent E2E ✅ pass
`studio-mcp-tasks.test.ts` — new Task API E2E ✅ pass (added in this PR)

The new E2E test (`studio-mcp-tasks.test.ts`) connects directly via `StreamableHTTPClientTransport`, calls `run_workflow` using `client.experimental.tasks.callToolStream()`, and asserts the full `taskCreated → taskStatus → result` sequence is received correctly.

Linear

Closes ENG-161

chatgpt-codex-connector[bot]

This comment was marked as outdated.

…atus to chat

Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
storeTaskResult refuses to update a task already in a terminal state.
Previously, updateTaskStatus was called first (setting the task to
'completed'/'failed'), then storeTaskResult would throw with an
internal error, causing the client to receive a -32603 McpError.

Fix: skip updateTaskStatus for terminal workflow states and let
storeTaskResult perform the terminal status transition itself.
Only call updateTaskStatus for non-terminal (working) states.

Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
…ty response

The AI agent test was producing an empty text response because the
prompt didn't explicitly request a textual summary. Updated the prompt
to ask for a summary of the final output message so the agent always
returns a non-empty response.

Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Adds a new E2E test that validates the full MCP task lifecycle via
StreamableHTTPClientTransport:
- Connects to /studio-mcp with API key auth
- Calls run_workflow using the experimental callToolStream API
- Asserts taskCreated, taskStatus, and result messages are received
- Verifies the result contains workflow output and no errors

Also removes the scratch test-mcp-server.ts file used for local
debugging during development.

Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
updateTaskStatus is no longer called for terminal states (COMPLETED/
FAILED/CANCELLED) — storeTaskResult handles the terminal transition.
Update unit test expectations to reflect this behaviour.

Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
@betterclever betterclever merged commit f9fe541 into main Feb 21, 2026
3 checks passed
@betterclever betterclever deleted the eng-161-stream-status branch February 21, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant