|
| 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 | +## Create an ignore file |
| 29 | + |
| 30 | +Create a file named `.thvignore` at the root of the directory you intend to |
| 31 | +mount. Use simple, gitignore-like patterns: |
| 32 | + |
| 33 | +```text |
| 34 | +# secrets |
| 35 | +.env |
| 36 | +.env.* |
| 37 | +*.key |
| 38 | +*.pem |
| 39 | +
|
| 40 | +# cloud credentials |
| 41 | +.aws/ |
| 42 | +.gcp/ |
| 43 | +
|
| 44 | +# SSH keys |
| 45 | +.ssh/ |
| 46 | +
|
| 47 | +# OS junk |
| 48 | +.DS_Store |
| 49 | +``` |
| 50 | + |
| 51 | +Guidelines: |
| 52 | + |
| 53 | +- `dir/` matches a directory directly under the mount source |
| 54 | +- `file.ext` matches a file directly under the mount source |
| 55 | +- `*.ext` matches any file with that extension directly under the mount source |
| 56 | +- Lines starting with `#` are comments; blank lines are ignored |
| 57 | + |
| 58 | +:::info[Pattern matching] |
| 59 | + |
| 60 | +ToolHive uses simple gitignore-like patterns. Advanced gitignore glob syntax |
| 61 | +like `**/*.env` (to match files in any subdirectory) is not currently supported. |
| 62 | +Patterns only match files and directories directly under the mount source. |
| 63 | + |
| 64 | +::: |
| 65 | + |
| 66 | +## Run a server with .thvignore |
| 67 | + |
| 68 | +Mount your project directory as usual. ToolHive automatically reads `.thvignore` |
| 69 | +if present: |
| 70 | + |
| 71 | +```bash |
| 72 | +thv run --volume ./my-project:/projects filesystem |
| 73 | +``` |
| 74 | + |
| 75 | +To print resolved overlay targets for debugging: |
| 76 | + |
| 77 | +```bash |
| 78 | +thv run --volume ./my-project:/projects \ |
| 79 | + --print-resolved-overlays \ |
| 80 | + filesystem |
| 81 | +``` |
| 82 | + |
| 83 | +The resolved overlays are logged to the workload's log file. For a complete list |
| 84 | +of options, see the [`thv run` command reference](../reference/cli/thv_run.md). |
| 85 | + |
| 86 | +## Global ignore patterns |
| 87 | + |
| 88 | +You can define global ignore patterns in a platform-specific location: |
| 89 | + |
| 90 | +- **Linux**: `~/.config/toolhive/thvignore` |
| 91 | +- **macOS**: `~/Library/Application Support/toolhive/thvignore` |
| 92 | +- **Windows**: `%LOCALAPPDATA%\toolhive\thvignore` |
| 93 | + |
| 94 | +Patterns contained in the global configuration are loaded in addition to a local |
| 95 | +`.thvignore` file. To disable global patterns for a specific workload, use the |
| 96 | +`--ignore-globally=false` option: |
| 97 | + |
| 98 | +```bash |
| 99 | +thv run --ignore-globally=false --volume ./my-project:/projects filesystem |
| 100 | +``` |
| 101 | + |
| 102 | +:::tip[Recommendation] |
| 103 | + |
| 104 | +Set machine-wide patterns (for example, `.aws/`, `.gcp/`, `.ssh/`, `*.pem`, |
| 105 | +`.docker/config.json`) in the global file, and keep app-specific patterns (for |
| 106 | +example, `.env*`, build artifacts) in your project's local `.thvignore`. |
| 107 | + |
| 108 | +::: |
| 109 | + |
| 110 | +## Troubleshooting |
| 111 | + |
| 112 | +<details> |
| 113 | +<summary>Overlays didn't apply</summary> |
| 114 | + |
| 115 | +- Ensure `.thvignore` exists in the mount source directory (not elsewhere) |
| 116 | +- Confirm patterns match actual names relative to the mount source |
| 117 | +- Run with `--print-resolved-overlays` and check the workload's log file path |
| 118 | + displayed by `thv run` |
| 119 | + |
| 120 | +</details> |
| 121 | + |
| 122 | +<details> |
| 123 | +<summary>Can't list a parent directory</summary> |
| 124 | + |
| 125 | +- On SELinux systems, listing a parent directory may fail even though specific |
| 126 | + files are accessible. Probe individual paths instead (for example, `stat` or |
| 127 | + `cat`). |
| 128 | + |
| 129 | +</details> |
| 130 | + |
| 131 | +## Related information |
| 132 | + |
| 133 | +- [File system access](./filesystem-access.md) |
| 134 | +- [Run MCP servers](./run-mcp-servers.mdx) |
| 135 | +- [Network isolation](./network-isolation.mdx) |
| 136 | +- [`thv run` command reference](../reference/cli/thv_run.md) |
0 commit comments