Quick start
Use the exportedregisterApiRoute helper to declare an endpoint. Add it to the server.apiRoutes array and ServerKit will mount it under the root of your server.
/ characters.
Accessing ServerKit internals
Within a handler you can reach theServerKit instance via c.get("serverKit"), or the underlying Mastra-compatible object via c.get("mastra"). This lets you reuse the same agents or workflows that power the default API.
Adding middleware
Custom routes can declare middleware at registration time. Use it to enforce authentication, emit logs, or mutate the context before the handler executes.server.middleware option to run code before every route—including your customs ones. Route-level middleware executes after global middleware but before the handler.
Testing custom routes
The integration tests inpackages/server/src/__tests__/server.test.ts demonstrate how to spin up a ServerKit instance, hit a custom route, and assert on the JSON payload. Reuse the same approach in your own test suite to cover bespoke endpoints and authentication flows.