What we are trying to do. We serve Mastra agents over AG-UI from our own Mastra server, to more
than one kind of client: CopilotKit's React front end, and clients that speak plain AG-UI with no
CopilotKit code, such as @ag-ui/client's HttpAgent or a mobile app.
What happens. registerCopilotKit() in @ag-ui/mastra 1.1.4 always passes
mode: "single-route" to createCopilotRuntimeHandler (src/copilotkit.ts), with no option to
change it. Single-route mode accepts only CopilotKit's { method, params, body } envelope, so a plain
AG-UI run is refused:
HttpAgent from @ag-ui/client 1.0.0, or a bare RunAgentInput over raw HTTP, pointed at the
registered path: HTTP 400, "Missing method field".
- The same CopilotKit runtime (
@copilotkit/runtime 1.74.0) mounted by hand in multi-route mode:
POST <base>/agent/:agentId/run takes the bare RunAgentInput and streams AG-UI events, and
HttpAgent works unchanged.
Run against @mastra/core 1.66.0.
What we would like.
- A
mode option on registerCopilotKit(), "single-route" by default so nothing changes for
existing users, passed through to createCopilotRuntimeHandler.
- In multi-route mode, a way to choose which of the runtime's endpoints are registered, for
example only agent/:agentId/run and info. We register each endpoint as its own Mastra API route
today, so that CopilotKit's connect, threads/… and memories/… endpoints are not reachable until
we have a runner that checks who owns a thread. With a single catch-all route, every endpoint the
runtime serves would be reachable.
We are happy to open a pull request for either if you would take one.
Also worth knowing. The existing comment in registerCopilotKit() explains why it drops the
authorization header before the runtime sees it. The runtime also forwards every x- header a client
sends, and @ag-ui/mastra passes the agent's headers to the model call as modelSettings.headers, so
a browser's x- headers reach the model provider unless forwardHeaders is set. It may be worth a
line in the helper's documentation.
What we are trying to do. We serve Mastra agents over AG-UI from our own Mastra server, to more
than one kind of client: CopilotKit's React front end, and clients that speak plain AG-UI with no
CopilotKit code, such as
@ag-ui/client'sHttpAgentor a mobile app.What happens.
registerCopilotKit()in@ag-ui/mastra1.1.4 always passesmode: "single-route"tocreateCopilotRuntimeHandler(src/copilotkit.ts), with no option tochange it. Single-route mode accepts only CopilotKit's
{ method, params, body }envelope, so a plainAG-UI run is refused:
HttpAgentfrom@ag-ui/client1.0.0, or a bareRunAgentInputover raw HTTP, pointed at theregistered path: HTTP 400,
"Missing method field".@copilotkit/runtime1.74.0) mounted by hand in multi-route mode:POST <base>/agent/:agentId/runtakes the bareRunAgentInputand streams AG-UI events, andHttpAgentworks unchanged.Run against
@mastra/core1.66.0.What we would like.
modeoption onregisterCopilotKit(),"single-route"by default so nothing changes forexisting users, passed through to
createCopilotRuntimeHandler.example only
agent/:agentId/runandinfo. We register each endpoint as its own Mastra API routetoday, so that CopilotKit's
connect,threads/…andmemories/…endpoints are not reachable untilwe have a runner that checks who owns a thread. With a single catch-all route, every endpoint the
runtime serves would be reachable.
We are happy to open a pull request for either if you would take one.
Also worth knowing. The existing comment in
registerCopilotKit()explains why it drops theauthorizationheader before the runtime sees it. The runtime also forwards everyx-header a clientsends, and
@ag-ui/mastrapasses the agent's headers to the model call asmodelSettings.headers, soa browser's
x-headers reach the model provider unlessforwardHeadersis set. It may be worth aline in the helper's documentation.