Use the Studio as a Starting Point for Your App
Which parts of the studio's code you can copy into your own app, and how its agent is wired.
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.
Where the reusable code lives
Each file below does one job and can be copied on its own. Paths are relative to the root of the clinia/context-engine-studio repository.
| Path | What it does |
|---|---|
src/env/server.ts | Validates the environment variables at startup, stops when the credentials are missing, and builds the MCP URL by adding /mcp to the workspace URL. |
src/lib/context-engine-client/auth.ts | Creates the token provider that the REST client and the MCP connection share. |
src/lib/context-engine-client/server.ts | Creates the ContextEngineClient with that token provider. |
src/lib/context-engine-client/actions.ts | Wraps each REST call the studio makes as a Next.js server action. |
src/lib/context-engine-client/mcp.ts | Opens an MCP connection, turns the engine's tools into AI SDK tools and loads the vfs_agent system prompt. |
src/app/api/patients/[patientId]/chat/route.ts | Runs one chat turn, as described in How the chat assistant is wired. |
src/lib/chat/session.ts | Turns the chat's messages into the messages a session import takes. |
src/lib/ingest/ | Sorts a dropped folder into FHIR and CDA files and splits a FHIR bundle that is too large for one request. |
The calls in actions.ts 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 methods table.
How the chat assistant is wired
One chat turn runs five steps:
- 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.
- It removes
patient_idandsession_idfrom each tool's input schema and adds them when the tool runs, so the model cannot set or invent them. - While the connection opens, it saves the user's question in the session.
- It streams a Claude answer through the AI SDK, with up to eight tool-calling steps.
- 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.
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 a local SQLite file through Drizzle, behind a
ChatStoreinterface insrc/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 ofsrc/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.svgand the icons derived from them.
Next steps
- SDK Overview for the JavaScript and Python clients that the studio's REST calls use.
- JavaScript Client to set up the client with client credentials.
- Connect an AI Agent for the MCP tools the chat assistant uses.