Skip to content

Commit 3107ad1

Browse files
committed
update mcp env variables
1 parent fc258ff commit 3107ad1

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

sdk/guides/agent-file-based.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,34 @@ Use the fetch tool to retrieve web content and save findings to files.
344344

345345
The `mcp_servers` field uses the same format as the [MCP configuration](/sdk/guides/mcp) — each key is a server name, and the value contains `command` and `args` for launching the server.
346346

347+
#### Environment Variable Resolution
348+
349+
All string values in MCP server configurations support `${VAR}` (and `$VAR`) environment variable references, which are resolved from `os.environ` at load time. This lets you forward secrets and dynamic paths without hard-coding them in Markdown:
350+
351+
```markdown icon="markdown"
352+
---
353+
name: api-agent
354+
description: Agent with MCP server using environment-based secrets.
355+
mcp_servers:
356+
my-server:
357+
command: ${PLUGIN_ROOT}/bin/server
358+
args:
359+
- --config
360+
- ${PLUGIN_ROOT}/config.json
361+
env:
362+
API_KEY: ${MY_API_KEY}
363+
remote:
364+
type: http
365+
url: ${API_BASE}/mcp
366+
headers:
367+
Authorization: Bearer ${AUTH_TOKEN}
368+
---
369+
370+
An agent that connects to MCP servers configured via environment variables.
371+
```
372+
373+
Environment variable resolution applies recursively to all string fields — `command`, `args`, `url`, `headers`, `env`, and any other string values in the server config. If a referenced variable is not set, the placeholder is left unchanged (e.g., `${NONEXISTENT_VAR}` stays as-is).
374+
347375
### Hooks
348376

349377
File-based agents can define [lifecycle hooks](/sdk/guides/hooks) that run at specific points during execution:

0 commit comments

Comments
 (0)