Give an MCP server a secret
This page is for an MCP server that agents start in the sandbox, as a local
process listed in a harness profile's mcpServers. For a remote server
reached over HTTP, name it on an integration instead, so its calls get
approvals, hooks and the run's journal: see
Call a remote MCP server.
The example uses a placeholder server, acme-mcp, that reads its key from
ACME_API_KEY and calls api.acme.example; put your own server, variable and
host in their place. You need:
- Terraform set up with the Spotlight provider, using a token that has the
configureandsecretsscopes. See Manage Spotlight with Terraform. - A host to take the runs, or a push pool that names an egress. Runs that use secrets go only to hosts and to push pools that name an egress. See Install a host and Send push pool runs through an egress.
- The API's host, the header or query parameter it reads the key from, and
any prefix, such as
Bearer.
Keep the key as a secret bound to the API's host
variable "acme_api_key" {
type = string
sensitive = true
}
data "spotlight_workspace" "acme" {
slug = "acme"
}
resource "spotlight_secret" "acme_api_key" {
workspace_id = data.spotlight_workspace.acme.id
name = "ACME_API_KEY"
bindings = [
{ host = "api.acme.example", location = "header", name = "authorization", prefix = "Bearer " },
]
value_wo = var.acme_api_key
value_wo_version = 1
}If the API reads the key from a query parameter, as the Google Maps APIs read
key, bind it there instead:
bindings = [
{ host = "maps.googleapis.com", location = "query", name = "key" },
]If the key is in AWS Secrets Manager or another store, read it in Terraform
and pass it as value_wo. See
A value from another secret store.
Set the value outside Terraform
If the key must not pass through Terraform, leave out value_wo and
value_wo_version:
resource "spotlight_secret" "acme_api_key" {
workspace_id = data.spotlight_workspace.acme.id
name = "ACME_API_KEY"
bindings = [
{ host = "api.acme.example", location = "header", name = "authorization", prefix = "Bearer " },
]
}After terraform apply, the secret awaits a value. A run at a station whose
profile names it fails with
secret_awaiting_value: Secret ACME_API_KEY has no value. Station: <station>
until the value is set. To set it, you need the secrets permission, which
owners and admins have.
- In the web app, open Settings, then Secrets. On the
ACME_API_KEYrow, click Set value, type the key in Value, and click Save value. - On the command line, after
spotlight login, runspotlight secret set ACME_API_KEYand type the key at the prompt. To read it from another command, pipe it in:op read op://acme/api/key | spotlight secret set ACME_API_KEY.
To rotate the key, set it again: the button reads Replace value. A run that failed before the value was set does not start again by itself. Reply to its inbox item to start a new run.
If you later add value_wo_version and value_wo, Terraform sets the value
again, and the app and the command line refuse to change it.
Name the secret in the server's environment
In a harness profile, set the environment variable the server reads to
secret.<NAME>:
data "spotlight_team" "core" {
workspace_id = data.spotlight_workspace.acme.id
key = "core"
}
resource "spotlight_harness_profile" "acme" {
team_id = data.spotlight_team.core.id
key = "acme"
mcp_servers = [
{
name = "acme"
command = "npx"
args = ["-y", "acme-mcp"]
env = { ACME_API_KEY = "secret.${spotlight_secret.acme_api_key.name}" }
},
]
}The secret must exist before the profile names it, and it cannot be deleted while the profile names it.
Run a station with the profile
Set the station's profile to the profile's key:
station {
key = "implementation"
name = "Implementation"
harness = "claude-code"
profile = spotlight_harness_profile.acme.key
passes_to = ["code-review"]
}Run terraform apply. On the next run at that station, the server's calls to
api.acme.example succeed. Inside the sandbox, ACME_API_KEY contains only the
stand-in spotlight-egress:ACME_API_KEY. The server must send it in the
authorization header as the whole value, or right after the binding's exact
prefix (Bearer spotlight-egress:ACME_API_KEY), and egress injects the real key
in its place in the outgoing request. For a secret bound to a query parameter,
the server must send the stand-in as that parameter's whole value, or right
after the prefix, as in ?key=spotlight-egress:MAPS_KEY for a secret named
MAPS_KEY. A server that encodes the key, as HTTP Basic does, or sends it
somewhere else, gets nothing. Other requests to api.acme.example from the
sandbox go out without the key.
If the host, or the shared egress of a push pool, sets
SPOTLIGHT_EGRESS_ALLOW, the list must allow the API's host, or egress
blocks the server's requests to it. A server that pins certificates
cannot reach a host egress injects a secret for.
Related
spotlight_harness_profile: every MCP server field.- Run secrets, on how egress injects a secret into a request.
spotlight_secret- The sandbox is the security boundary