Contexts
Contexts let you group related MolnOS resources under a shared name. A context represents a logical boundary around a piece of software—an app, a system, a project—giving you a way to organize and manage resources together without imposing rigid hierarchy.
What Is a Context?
Section titled “What Is a Context?”A context is a named container with an optional intent (what it’s for) and freeform attributes (metadata). Resources like functions, databases, storage buckets, and sites can all belong to a context.
Unlike organizational models in major clouds (AWS accounts, GCP projects), contexts are a soft boundary. They don’t enforce strong isolation—they’re a way to keep things organized and provide meaning to your landscape. Additionally, these allow you to add a boundary to generate code and configuration to, using the AI generation capabilities in MolnOS.
A default context is always available.
Why Use Contexts?
Section titled “Why Use Contexts?”- Organization: Group the functions, databases, and storage that make up a single application
- AI generation: The AI uses a context’s intent and attributes to understand what you’re building and generate appropriate code
- Lifecycle management: Delete all resources in a context at once when decommissioning
- Visibility: See at a glance what resources belong together
How It Works
Section titled “How It Works”Contexts are managed through the HTTP API at /contexts/* endpoints.
Create a Context
Section titled “Create a Context”POST /contexts{ "name": "url-shortener", "intent": "A URL shortener API with analytics and custom short codes", "attributes": { "storage": "kv", "auth": "apiKey" }}name(required) - Unique name, 1-64 charactersintent(optional) - Human-readable description of purpose, up to 1000 charactersattributes(optional) - Any JSON object with custom metadata
List Contexts
Section titled “List Contexts”GET /contextsReturns all contexts with a summary of associated resources.
Get Context Details
Section titled “Get Context Details”GET /contexts/{contextName}Returns the context along with its associated resources.
Update a Context
Section titled “Update a Context”PATCH /contexts/{contextName}Update the intent or attributes:
{ "intent": "Updated description of this context", "attributes": { "auth": "jwt", "features": ["rate-limiting"] }}Delete a Context
Section titled “Delete a Context”DELETE /contexts/{contextName}Deletes the context. The default context cannot be deleted.
Delete All Resources in a Context
Section titled “Delete All Resources in a Context”DELETE /contexts/{contextName}/resourcesRemoves all resources (functions, databases, storage, sites, etc.) associated with the context.
Resource Association
Section titled “Resource Association”Resources are associated with contexts in three ways:
- Via IaC: Resources defined in an IaC configuration are automatically registered to the context specified in that config
- At creation: When deploying a function or creating a database table, pass a
contextparameter to associate it - Automatically: Resources created without an explicit context are placed in the
defaultcontext
Supported Resource Types
Section titled “Supported Resource Types”Contexts can contain any other resource types.
Permissions
Section titled “Permissions”Context operations require appropriate permissions:
contexts.context.create- Create new contextscontexts.context.get- List and view contextscontexts.context.update- Update context intent and attributescontexts.context.delete- Delete contextscontexts.context.delete-resources- Delete all resources in a context