Skip to content

Commit 191c3a9

Browse files
authored
docs: add .thvignore documentation for hiding sensitive files (#161)
* docs: add .thvignore documentation for hiding sensitive files - Add new documentation page explaining .thvignore functionality - Document how to prevent secrets from leaking into MCP containers - Include examples for creating and using .thvignore files - Add reference to .thvignore in run-mcp-servers guide - Update sidebar to include new .thvignore page under Security section * Address PR feedback for .thvignore documentation - Fix global config path to be cross-platform compatible (Linux/macOS/Windows) - Remove redundant Requirements section - Change section heading to 'Create an ignore file' - Update file creation description to be more specific - Replace 'fetch' with 'filesystem' in command examples (better example) - Update troubleshooting section to use collapsible details format - Convert recommendation text to use tip admonition format - Improve global patterns description text - Add clarification about pattern matching limitations (no full glob syntax)
1 parent 2c40923 commit 191c3a9

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ To enable file system access for an MCP server, you can either use the
118118
`--volume` flag to mount specific paths or create a custom permission profile
119119
that defines read and write permissions.
120120

121-
See [File system access](./filesystem-access.md) for detailed examples.
121+
See [File system access](./filesystem-access.md) for detailed examples. To
122+
prevent sensitive files from being exposed when mounting a project, use
123+
[.thvignore](./thvignore.md).
122124

123125
### Restrict network access
124126

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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)

sidebars.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const sidebars: SidebarsConfig = {
8484
},
8585
items: [
8686
'toolhive/guides-cli/filesystem-access',
87+
'toolhive/guides-cli/thvignore',
8788
'toolhive/guides-cli/network-isolation',
8889
],
8990
},

0 commit comments

Comments
 (0)