|
| 1 | +--- |
| 2 | +title: Hide sensitive files with .thvignore |
| 3 | +description: |
| 4 | + Use .thvignore to prevent secrets from leaking into MCP containers while |
| 5 | + keeping fast bind mounts for development. |
| 6 | +--- |
| 7 | + |
| 8 | +Some MCP servers need access to your project files, but you don't want to expose |
| 9 | +secrets like `.env`, SSH keys, or cloud credentials. ToolHive supports a |
| 10 | +`.thvignore` mechanism that masks selected paths from the container while |
| 11 | +keeping all other files available through a live bind mount for a smooth |
| 12 | +developer experience. |
| 13 | + |
| 14 | +## How it works |
| 15 | + |
| 16 | +When you mount a directory and a `.thvignore` file is present at the mount |
| 17 | +source, ToolHive resolves the ignore patterns and overlays those paths inside |
| 18 | +the container: |
| 19 | + |
| 20 | +- Directories (for example, `.ssh/`, `node_modules/`): overlaid using a tmpfs |
| 21 | + mount at the container path |
| 22 | +- Files (for example, `.env`, `secrets.json`): overlaid using a bind mount of a |
| 23 | + shared, empty host file at the container path |
| 24 | + |
| 25 | +The rest of the files remain bind-mounted from your host, so edits are visible |
| 26 | +in the container immediately. |
| 27 | + |
| 28 | +## Requirements |
| 29 | + |
| 30 | +- ToolHive CLI |
| 31 | +- A mount source directory that contains a `.thvignore` file with patterns to |
| 32 | + exclude |
| 33 | + |
| 34 | +## Create a .thvignore |
| 35 | + |
| 36 | +Create a `.thvignore` file at the root of the directory you intend to mount. Use |
| 37 | +simple, gitignore-like patterns: |
| 38 | + |
| 39 | +```text |
| 40 | +# secrets |
| 41 | +.env |
| 42 | +.env.* |
| 43 | +*.key |
| 44 | +*.pem |
| 45 | +
|
| 46 | +# cloud credentials |
| 47 | +.aws/ |
| 48 | +.gcp/ |
| 49 | +
|
| 50 | +# SSH keys |
| 51 | +.ssh/ |
| 52 | +
|
| 53 | +# OS junk |
| 54 | +.DS_Store |
| 55 | +``` |
| 56 | + |
| 57 | +Guidelines: |
| 58 | + |
| 59 | +- `dir/` matches a directory directly under the mount source |
| 60 | +- `file.ext` matches a file directly under the mount source |
| 61 | +- `*.ext` matches any file with that extension directly under the mount source |
| 62 | +- Lines starting with `#` are comments; blank lines are ignored |
| 63 | + |
| 64 | +## Run a server with .thvignore |
| 65 | + |
| 66 | +Mount your project directory as usual. ToolHive automatically reads `.thvignore` |
| 67 | +if present: |
| 68 | + |
| 69 | +```bash |
| 70 | +thv run --volume ./my-project:/app fetch |
| 71 | +``` |
| 72 | + |
| 73 | +To print resolved overlay targets for debugging: |
| 74 | + |
| 75 | +```bash |
| 76 | +thv run --volume ./my-project:/app \ |
| 77 | + --print-resolved-overlays \ |
| 78 | + fetch |
| 79 | +``` |
| 80 | + |
| 81 | +The resolved overlays are logged to the workload's log file. For a complete list |
| 82 | +of options, see the [`thv run` command reference](../reference/cli/thv_run.md). |
| 83 | + |
| 84 | +## Global ignore patterns |
| 85 | + |
| 86 | +You can define global ignore patterns at: |
| 87 | + |
| 88 | +```text |
| 89 | +~/.config/toolhive/thvignore |
| 90 | +``` |
| 91 | + |
| 92 | +These patterns are loaded in addition to your project's local `.thvignore`. |
| 93 | + |
| 94 | +- Enabled by default |
| 95 | +- Disable for a single run: |
| 96 | + |
| 97 | +```bash |
| 98 | +thv run --ignore-globally=false --volume ./my-project:/app fetch |
| 99 | +``` |
| 100 | + |
| 101 | +Recommendation: Store machine-wide patterns (for example, `.aws/`, `.gcp/`, |
| 102 | +`.ssh/`, `*.pem`, `.docker/config.json`) in the global file, and keep |
| 103 | +app-specific patterns (for example, `.env*`, build artifacts) in your project's |
| 104 | +local `.thvignore`. |
| 105 | + |
| 106 | +## Troubleshooting |
| 107 | + |
| 108 | +- Overlays didn't apply |
| 109 | + - Ensure `.thvignore` exists in the mount source directory (not elsewhere) |
| 110 | + - Confirm patterns match actual names relative to the mount source |
| 111 | + - Run with `--print-resolved-overlays` and check the workload's log file path |
| 112 | + displayed by `thv run` |
| 113 | + |
| 114 | +- Can’t list a parent directory |
| 115 | + - On SELinux systems, listing a parent directory may fail even though specific |
| 116 | + files are accessible. Probe individual paths instead (for example, `stat` or |
| 117 | + `cat`). |
| 118 | + |
| 119 | +## Related information |
| 120 | + |
| 121 | +- [File system access](./filesystem-access.md) |
| 122 | +- [Run MCP servers](./run-mcp-servers.mdx) |
| 123 | +- [Network isolation](./network-isolation.mdx) |
| 124 | +- [`thv run` command reference](../reference/cli/thv_run.md) |
0 commit comments