Skip to content

Commit 41a54c8

Browse files
authored
Document header injection for remote MCP servers (#473)
* Document header injection for remote MCP servers Add "Inject custom headers" section to the remote server configuration guide covering the new --remote-forward-headers and --remote-forward-headers-secret flags. * Remove tip about thv proxy command The thv proxy command lacks narrative documentation explaining when to use it vs thv run, so referencing it here would confuse readers.
1 parent 49d01f9 commit 41a54c8

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

docs/toolhive/guides-cli/run-mcp-servers.mdx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,56 @@ thv run https://api.example.com/mcp \
769769
--remote-auth-skip-browser
770770
```
771771

772+
#### Inject custom headers
773+
774+
Some remote MCP servers require custom headers for tenant identification, API
775+
keys, or other purposes. ToolHive can inject headers into every request
776+
forwarded to the remote server.
777+
778+
To add plaintext headers, use the `--remote-forward-headers` flag:
779+
780+
```bash
781+
thv run https://api.example.com/mcp \
782+
--name my-server \
783+
--remote-forward-headers "X-Tenant-ID=tenant123" \
784+
--remote-forward-headers "X-Custom-Header=value"
785+
```
786+
787+
For sensitive values like API keys, use the `--remote-forward-headers-secret`
788+
flag to reference values stored in ToolHive's secrets manager:
789+
790+
```bash
791+
# First, store the secret (enter the value when prompted)
792+
thv secret set my-api-key
793+
794+
# Then reference it by name
795+
thv run https://api.example.com/mcp \
796+
--name my-server \
797+
--remote-forward-headers-secret "X-Api-Key=my-api-key"
798+
```
799+
800+
You can combine plaintext and secret-backed headers in a single command:
801+
802+
```bash
803+
thv run https://api.example.com/mcp \
804+
--name my-server \
805+
--remote-forward-headers "X-Tenant-ID=tenant123" \
806+
--remote-forward-headers-secret "X-Api-Key=my-api-key"
807+
```
808+
809+
:::warning[Security considerations]
810+
811+
- Plaintext header values are stored in the server's configuration file. For
812+
sensitive values (API keys, tokens), always use
813+
`--remote-forward-headers-secret`.
814+
- Secret-backed header values are resolved at runtime and never stored in
815+
configuration files.
816+
- Certain headers cannot be configured for security reasons, including `Host`,
817+
`Connection`, `Transfer-Encoding`, and proxy-related headers like
818+
`X-Forwarded-For`.
819+
820+
:::
821+
772822
### Remote server management
773823

774824
Remote MCP servers are managed like any other ToolHive workload:

0 commit comments

Comments
 (0)