Environment Variables and Secrets in MCP Servers
MCP tools often sit next to valuable credentials. Treat configuration as a first-class security concern.
Use a secret manager in production
Environment variables are convenient injection points, but the underlying secret should ideally come from your deployment platform's secret store rather than a committed file.
Keep tokens out of URLs
Use authorization headers or supported auth mechanisms. URLs are commonly logged by gateways, browsers, and observability systems.
Do not return secrets to the model
A tool should use credentials internally, not include them in result payloads. Redact sensitive headers from logs and traces.
Separate environments
Use different credentials for development, staging, and production. A local test server should not automatically inherit production access.
Assume prompts and tool arguments may be stored in traces. Never ask the model to carry credentials as normal text when an infrastructure credential channel exists.