Skip to content

Commit f4d077c

Browse files
docs: add documentation for mcp excludeTools and includeTools (google-gemini#3409)
Co-authored-by: Jack Wotherspoon <jackwoth@google.com>
1 parent 5f8fff4 commit f4d077c

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

docs/cli/configuration.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,23 @@ In addition to a project settings file, a project's `.gemini` directory can cont
132132
- `cwd` (string, optional): The working directory in which to start the server.
133133
- `timeout` (number, optional): Timeout in milliseconds for requests to this MCP server.
134134
- `trust` (boolean, optional): Trust this server and bypass all tool call confirmations.
135+
- `includeTools` (array of strings, optional): List of tool names to include from this MCP server. When specified, only the tools listed here will be available from this server (whitelist behavior). If not specified, all tools from the server are enabled by default.
136+
- `excludeTools` (array of strings, optional): List of tool names to exclude from this MCP server. Tools listed here will not be available to the model, even if they are exposed by the server. **Note:** `excludeTools` takes precedence over `includeTools` - if a tool is in both lists, it will be excluded.
135137
- **Example:**
136138
```json
137139
"mcpServers": {
138140
"myPythonServer": {
139141
"command": "python",
140142
"args": ["mcp_server.py", "--port", "8080"],
141143
"cwd": "./mcp_tools/python",
142-
"timeout": 5000
144+
"timeout": 5000,
145+
"includeTools": ["safe_tool", "file_reader"],
143146
},
144147
"myNodeServer": {
145148
"command": "node",
146149
"args": ["mcp_server.js"],
147-
"cwd": "./mcp_tools/node"
150+
"cwd": "./mcp_tools/node",
151+
"excludeTools": ["dangerous_tool", "file_deleter"]
148152
},
149153
"myDockerServer": {
150154
"command": "docker",

docs/tools/mcp-server.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ Each server configuration supports the following properties:
9292
- **`cwd`** (string): Working directory for Stdio transport
9393
- **`timeout`** (number): Request timeout in milliseconds (default: 600,000ms = 10 minutes)
9494
- **`trust`** (boolean): When `true`, bypasses all tool call confirmations for this server (default: `false`)
95+
- **`includeTools`** (string[]): List of tool names to include from this MCP server. When specified, only the tools listed here will be available from this server (whitelist behavior). If not specified, all tools from the server are enabled by default.
96+
- **`excludeTools`** (string[]): List of tool names to exclude from this MCP server. Tools listed here will not be available to the model, even if they are exposed by the server. **Note:** `excludeTools` takes precedence over `includeTools` - if a tool is in both lists, it will be excluded.
9597

9698
### Example Configurations
9799

@@ -185,6 +187,22 @@ Each server configuration supports the following properties:
185187
}
186188
```
187189

190+
#### MCP Server with Tool Filtering
191+
192+
```json
193+
{
194+
"mcpServers": {
195+
"filteredServer": {
196+
"command": "python",
197+
"args": ["-m", "my_mcp_server"],
198+
"includeTools": ["safe_tool", "file_reader", "data_processor"],
199+
// "excludeTools": ["dangerous_tool", "file_deleter"],
200+
"timeout": 30000
201+
}
202+
}
203+
}
204+
```
205+
188206
## Discovery Process Deep Dive
189207

190208
When the Gemini CLI starts, it performs MCP server discovery through the following detailed process:
@@ -207,7 +225,8 @@ Upon successful connection:
207225

208226
1. **Tool listing:** The client calls the MCP server's tool listing endpoint
209227
2. **Schema validation:** Each tool's function declaration is validated
210-
3. **Name sanitization:** Tool names are cleaned to meet Gemini API requirements:
228+
3. **Tool filtering:** Tools are filtered based on `includeTools` and `excludeTools` configuration
229+
4. **Name sanitization:** Tool names are cleaned to meet Gemini API requirements:
211230
- Invalid characters (non-alphanumeric, underscore, dot, hyphen) are replaced with underscores
212231
- Names longer than 63 characters are truncated with middle replacement (`___`)
213232

0 commit comments

Comments
 (0)