How It Works
- Your backend passes
envandsecretswhen exchanging credentials for a widget JWT - Sigmic AI stores them server-side — secrets are encrypted at rest. Neither
envnorsecretsare included in the JWT itself or sent to the browser. - 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:my-api-server, the headers are resolved to:
Example: stdio server with environment variables
MCP server config:Example: SSE server with dynamic URL
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 inenv 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 aswarningsin the response. - On each widget app (Project → Settings → Widgets) the Console shows the key names your backend has sent with
env/secretson 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 ownenv/secretsand are not recorded here.
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:Token Refresh and Variables
Each widget token has its own set ofenv/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
envandsecretsare 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.