Skip to content

@ag-ui/mastra: let registerCopilotKit() mount CopilotKit's runtime in multi-route mode #2863

Description

@fa-lesley

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.

  1. A mode option on registerCopilotKit(), "single-route" by default so nothing changes for
    existing users, passed through to createCopilotRuntimeHandler.
  2. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions