# Use the Studio as a Starting Point for Your App

URL: https://docs.clinia.com/studio/use-studio-as-a-starting-point

> How the studio calls the Context Engine and wires its agent, and which parts stay specific to the studio.

The studio's server code covers the three things most apps built on the Context Engine need: authenticating to a workspace, calling its REST API and giving an agent the engine's MCP tools. The code is under the Apache-2.0 license, so you can copy, change and ship it as long as your copy keeps the `LICENSE` and `NOTICE` files.

## Calling the REST API [#calling-the-rest-api]

The studio's REST calls go through the client's low-level `client.http` layer, with each route path written out. Your own code can make the same calls with the client's resource methods, such as `client.patients.upsertPatient` or `client.vfs.readVfs`, which are listed in the [JavaScript Client](https://docs.clinia.com/sdks/javascript#methods) methods table.

## How the chat assistant is wired [#how-the-chat-assistant-is-wired]

One chat turn runs five steps:

1. The route opens a new MCP connection to the workspace on every turn, because the engine's MCP server is stateless and keeps nothing from one request to the next that the studio could reuse.
2. It removes `patient_id` and `session_id` from each tool's input schema and adds them when the tool runs, so the model cannot set or invent them.
3. While the connection opens, it saves the user's question in the session.
4. It streams a Claude answer through the AI SDK, with up to eight tool-calling steps.
5. When the answer finishes streaming, it closes the MCP connection and saves the assistant's answer in the session.

When the MCP connection fails, the route answers without tools instead of failing the request. The tools that the engine's MCP server exposes are described in [Connect an AI Agent](https://docs.clinia.com/docs/context-assembly/connect-an-ai-agent).

## What stays specific to the studio [#what-stays-specific-to-the-studio]

Three parts were built for the studio, so an app usually replaces them instead of copying them:

- Chat history is stored in Postgres through Drizzle, either an embedded PGlite database or a server chosen by `STUDIO_DATABASE_URL`, behind a `ChatRepository` interface in `src/persistence/` that is meant to be swapped for another database.
- The components in `src/components/ui/` come from shadcn/ui under the MIT license. The rest of `src/components/` is built around the studio's screens.
- The Clinia name and logos are trademarks that the license does not cover, so a fork replaces `public/Logomark.svg`, `public/Logotype.svg` and the icons derived from them.

## Next steps [#next-steps]

- [SDK Overview](https://docs.clinia.com/sdks/overview) for the JavaScript and Python clients that the studio's REST calls use.
- [JavaScript Client](https://docs.clinia.com/sdks/javascript#install-and-authenticate) to set up the client with client credentials.
- [Connect an AI Agent](https://docs.clinia.com/docs/context-assembly/connect-an-ai-agent) for the MCP tools the chat assistant uses.
