Skip to main content
When you embed the widget, each end user likely needs the agent to connect to their data — their database, their API, their tenant. Environment variables and secrets let you pass per-user credentials at token exchange time so the agent’s MCP servers connect to the right services for each end user.

How It Works

  1. Your backend passes env and secrets when exchanging credentials for a widget JWT
  2. Sigmic AI stores them server-side — secrets are encrypted at rest. Neither env nor secrets are included in the JWT itself or sent to the browser.
  3. When the user chats, the platform retrieves the stored values and injects them into every MCP server in the project. Template placeholders like {{mcp.API_KEY}} in your server config are resolved to the actual values before the connection is established.

env vs secrets

Both env and secrets are key-value string maps passed in the token exchange request. The difference is how they are stored: If the same key appears in both env and secrets, the secrets value takes precedence.
The env/secrets distinction exists for forward compatibility. Today both are stored securely. Use secrets for anything sensitive (tokens, passwords, connection strings) and env for non-sensitive configuration (tenant IDs, regions, feature flags).

Using Variables in MCP Server Config

MCP servers are configured in your project settings (via the Console or the project config API). Use {{mcp.KEY}} placeholders in the server’s headers, env, or url fields. These placeholders are resolved at runtime using the env/secrets from the active widget token.

Example: HTTP server with API key in headers

Step 1 — Configure the MCP server in your project:
Step 2 — Pass the values when issuing a widget token:
Result: When the agent connects to my-api-server, the headers are resolved to:

Example: stdio server with environment variables

MCP server config:
Widget token request:
Result: The MCP server process launches with these environment variables:

Example: SSE server with dynamic URL

With env: { REGION: 'us-east-1' } and secrets: { ANALYTICS_KEY: 'ak-12345' }, the agent connects to https://us-east-1.analytics.example.com/mcp/sse with header X-API-Key: ak-12345.

Template Reference

Key naming rules

Keys must be valid environment variable names:
  • Start with a letter or underscore
  • Contain only letters, digits, and underscores
  • All values must be strings

Troubleshooting placeholders

A placeholder only resolves when the key name in your MCP server config matches, character for character, a key your backend sent in env or secrets when it minted the widget token. When a placeholder cannot be resolved:
  • In the agent session the MCP server fails to connect instead of sending the literal placeholder. The error names the server, the field, the placeholder and the keys that were available, for example: MCP server 'billing-api' (headers.Authorization): unresolved template variable {{mcp.API_TOKEN}} (did you mean 'api_TOKEN'?). Available keys: api_TOKEN. Keys are case-sensitive. The agent tells the end user the integration is misconfigured; it does not ask them for credentials.
  • In the Console (Project → Settings → MCP Servers) the health check for a server that uses placeholders cannot test the connection — the values only exist inside a widget session — so it reports the placeholders it found and, once your backend has minted at least one token with env/secrets, whether each placeholder matches a key that was actually sent. Saving a server config returns the same check as warnings in the response.
  • On each widget app (Project → Settings → Widgets) the Console shows the key names your backend has sent with env/secrets on token mints so far (accumulated, so end users with different key sets do not hide each other). Values are never stored for display. Sessions started through the Task API carry their own env/secrets and are not recorded here.
Fix it by renaming either side so they match exactly. Prefer upper-case names such as API_TOKEN on both sides.

Multi-Tenant Example

A common pattern is passing per-tenant credentials so each end user’s widget session connects the agent to that user’s data:
With the corresponding project MCP server config:
Each end user’s widget session connects the agent to that user’s database and API — with credentials that never leave the server.

Token Refresh and Variables

Each widget token has its own set of env/secrets. When you refresh a token, you must pass env and secrets again — the new token does not inherit values from the previous one. This also means you can update credentials on refresh without interrupting the session. For example, if an end user’s API key is rotated, the next token refresh can include the new key.

Security

  • env and secrets are never included in the JWT — they are stored server-side only
  • They are never sent to the browser — the widget iframe only receives the JWT
  • Values are stored encrypted and automatically cleaned up when the token expires
  • Secrets are only decrypted when the agent session needs them
This is the same mechanism used by the Task API for passing environment variables. If you are already using env/secrets with the Task API, they work identically in the widget.