Skip to main content

Routes and Events

This page documents the route inventory exposed by AI Mastra Bridge and how it implements the io.Intelligence Agent Protocol on top of Mastra.

Use Agent Protocol as the canonical contract reference. This page focuses on the Mastra-specific implementation view.


Route Inventory

The bridge currently registers ten routes.

MethodPathPurpose
POST/runStarts a protocol streaming run
POST/runs/:runId/tool-calls/:toolCallId/resultSubmits one frontend tool result back to an active run
GET/agentsLists available agents
GET/agents/:agentIdReturns one agent
POST/threadsCreates a thread
GET/threadsLists threads
GET/threads/:threadIdReturns one thread
PATCH/threads/:threadIdUpdates a thread
DELETE/threads/:threadIdDeletes a thread
GET/threads/:threadId/messagesReturns thread messages

When a custom prefix is configured, that prefix is prepended to each path.

Example with the default prefix:

  • POST /io-bridge/run
  • POST /io-bridge/runs/:runId/tool-calls/:toolCallId/result
  • GET /io-bridge/agents
  • GET /io-bridge/threads/:threadId/messages

Streaming Route

POST /run

This is the most important bridge endpoint. It accepts a run request, calls the Mastra agent runtime, and streams protocol events over Server-Sent Events.

The bridge translates Mastra stream chunks into the AG-UI-based event subset used by the protocol so frontend clients can work with a consistent event model.


Protocol Event Translation

The bridge emits event categories such as:

  • run lifecycle events
  • text streaming events
  • tool call lifecycle events
  • step lifecycle events

Common Event Types

Event TypeMeaning
RUN_STARTEDRun lifecycle start
RUN_FINISHEDRun finished successfully
RUN_ERRORRun failed
TEXT_MESSAGE_STARTAssistant text message started
TEXT_MESSAGE_CONTENTText delta chunk
TEXT_MESSAGE_ENDAssistant text message ended
TOOL_CALL_STARTTool call began
TOOL_CALL_ARGSTool call argument delta
TOOL_CALL_ENDTool call argument stream ended
TOOL_CALL_RESULTTool result became available
STEP_STARTEDExecution step started
STEP_FINISHEDExecution step finished

Mastra-to-Protocol Mapping

Mastra Chunk TypeProtocol Event(s)
text-startTEXT_MESSAGE_START
text-deltaTEXT_MESSAGE_CONTENT
text-endTEXT_MESSAGE_END
tool-call-input-streaming-startTOOL_CALL_START
tool-call-deltaTOOL_CALL_ARGS
tool-call-input-streaming-endTOOL_CALL_END
tool-callTOOL_CALL_START, TOOL_CALL_ARGS, TOOL_CALL_END
tool-resultTOOL_CALL_RESULT
step-startSTEP_STARTED
step-finishSTEP_FINISHED
finishRUN_FINISHED
errorRUN_ERROR

Frontend Tool Result Reporting

The bridge supports frontend-executed tools without requiring a second /run request:

  1. the agent emits a tool call
  2. the frontend executes the tool after TOOL_CALL_END
  3. the frontend posts the result to /runs/:runId/tool-calls/:toolCallId/result
  4. the bridge resolves the pending proxy tool
  5. Mastra emits TOOL_CALL_RESULT and continues the same run

This matters for assistant clients that integrate tools outside the Mastra backend itself while still relying on Mastra memory and the normal tool loop.


Server Tool Result Capture

The bridge also accounts for server-side tools registered directly with Mastra agents.

Because Mastra does not always emit tool-result chunks consistently, the bridge captures server tool results and emits TOOL_CALL_RESULT events when needed. This helps frontend clients observe a cleaner and more predictable tool lifecycle.


Thread and Message Routes

The thread routes expose a frontend-friendly thread API:

  • create a thread before a conversation begins
  • list threads for a resource
  • fetch one thread
  • rename or update thread metadata
  • delete a thread
  • retrieve thread messages with pagination-style parameters such as limit and offset

These routes let the frontend use a stable thread contract without depending on Mastra-specific REST details.


Practical Notes

  • memory-backed thread behavior depends on at least one Mastra agent having memory configured
  • without memory, stateless streaming can still work, but thread CRUD cannot behave as a persistent thread system
  • custom auth and request policy are typically added through host-app middleware around the registered routes