The Context Engine Studio is now open source.  View on GitHub →
Clinia

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.

PathWhat it does
src/env/server.tsValidates 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.tsCreates the token provider that the REST client and the MCP connection share.
src/lib/context-engine-client/server.tsCreates the ContextEngineClient with that token provider.
src/lib/context-engine-client/actions.tsWraps each REST call the studio makes as a Next.js server action.
src/lib/context-engine-client/mcp.tsOpens 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.tsRuns one chat turn, as described in How the chat assistant is wired.
src/lib/chat/session.tsTurns 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:

  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.

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 ChatStore 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

On this page