Skip to content

Commit a30d73d

Browse files
Skip tools regex (#117)
* Upgrade regex dependency to 1.11.3 * Upgrade Rust to 1.90 * Remove unused Docker manifest structs * Use RegexSet for skip_tools list in runtime config The change converts skip_tools from Vec<String> to RegexSet to support pattern matching. This includes regex serialization, deserialization with anchoring, and comprehensive test coverage for various matching scenarios. * Add skip_tools test fixtures * Add skip tools pattern guide and enhance docs The commit adds comprehensive documentation for the new regex-based skip_tools feature. It includes a full pattern guide, updates configuration examples, and enhances the runtime config documentation with pattern matching details. Key changes include: - New SKIP_TOOLS_GUIDE.md with detailed pattern examples - Enhanced skip_tools docs in RUNTIME_CONFIG.md - Updated config examples with pattern matching - Added skip tools guide link to README.md
1 parent 1d6785e commit a30d73d

13 files changed

+1183
-59
lines changed

Cargo.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ rmcp = { version = "0.6.4", features = [
3737
"transport-sse-server",
3838
"transport-streamable-http-server",
3939
] }
40-
regex = { version = "1.11.1", features = ["unicode", "perf"] }
40+
regex = { version = "1.11.3", features = ["unicode", "perf"] }
4141
reqwest = { version = "0.12.21", features = ["json"] }
4242
serde = { version = "1.0.219", features = ["derive"] }
4343
serde_json = "1.0.140"

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=$BUILDPLATFORM rust:1.86 AS builder
1+
FROM --platform=$BUILDPLATFORM rust:1.90 AS builder
22
WORKDIR /app
33
RUN cargo install cargo-auditable
44

@@ -10,10 +10,10 @@ RUN cargo auditable build --release --locked
1010
FROM gcr.io/distroless/cc-debian12
1111

1212
LABEL org.opencontainers.image.authors="[email protected]" \
13-
org.opencontainers.image.url="https://github.com/tuananh/hyper-mcp" \
14-
org.opencontainers.image.source="https://github.com/tuananh/hyper-mcp" \
15-
org.opencontainers.image.vendor="github.com/tuananh/hyper-mcp" \
16-
io.modelcontextprotocol.server.name="io.github.tuananh/hyper-mcp"
13+
org.opencontainers.image.url="https://github.com/tuananh/hyper-mcp" \
14+
org.opencontainers.image.source="https://github.com/tuananh/hyper-mcp" \
15+
org.opencontainers.image.vendor="github.com/tuananh/hyper-mcp" \
16+
io.modelcontextprotocol.server.name="io.github.tuananh/hyper-mcp"
1717

1818
WORKDIR /app
1919
COPY --from=builder /app/target/release/hyper-mcp /usr/local/bin/hyper-mcp

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ We maintain several example plugins to get you started:
162162
- Security considerations and best practices
163163
- Platform-specific keyring setup for macOS, Linux, and Windows
164164
- Troubleshooting authentication issues
165+
- **[Skip Tools Pattern Guide](./SKIP_TOOLS_GUIDE.md)** - Comprehensive guide to filtering tools using regex patterns:
166+
- Pattern syntax and examples
167+
- Common use cases and best practices
168+
- Environment-specific filtering strategies
169+
- Advanced regex techniques
170+
- Migration and troubleshooting
165171

166172
## Creating Plugins
167173

RUNTIME_CONFIG.md

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The configuration is structured as follows:
88
- **plugins**: A map of plugin names to plugin configuration objects.
99
- **path** (`string`): OCI path or HTTP URL or local path for the plugin.
1010
- **runtime_config** (`object`, optional): Plugin-specific runtime configuration. The available fields are:
11-
- **skip_tools** (`array[string]`, optional): List of tool names to skip loading at runtime.
11+
- **skip_tools** (`array[string]`, optional): List of regex patterns for tool names to skip loading at runtime. Each pattern is automatically anchored to match the entire tool name (equivalent to wrapping with `^` and `$`). Supports full regex syntax for powerful pattern matching.
1212
- **allowed_hosts** (`array[string]`, optional): List of allowed hosts for the plugin (e.g., `["1.1.1.1"]` or `["*"]`).
1313
- **allowed_paths** (`array[string]`, optional): List of allowed file system paths.
1414
- **env_vars** (`object`, optional): Key-value pairs of environment variables for the plugin.
@@ -322,7 +322,10 @@ plugins:
322322
allowed_hosts:
323323
- "1.1.1.1"
324324
skip_tools:
325-
- "debug"
325+
- "debug_tool" # Skip exact tool name
326+
- "temp_.*" # Skip tools starting with "temp_"
327+
- ".*_backup" # Skip tools ending with "_backup"
328+
- "test_[0-9]+" # Skip tools like "test_1", "test_42"
326329
env_vars:
327330
FOO: "bar"
328331
memory_limit: "512Mi"
@@ -361,7 +364,12 @@ plugins:
361364
"url": "oci://ghcr.io/tuananh/myip-plugin:latest",
362365
"runtime_config": {
363366
"allowed_hosts": ["1.1.1.1"],
364-
"skip_tools": ["debug"],
367+
"skip_tools": [
368+
"debug_tool",
369+
"temp_.*",
370+
".*_backup",
371+
"test_[0-9]+"
372+
],
365373
"env_vars": {"FOO": "bar"},
366374
"memory_limit": "512Mi"
367375
}
@@ -470,10 +478,86 @@ This error occurs when the stored password isn't valid JSON or doesn't match the
470478
chmod 600 config.yaml
471479
```
472480

481+
## Skip Tools Pattern Matching
482+
483+
The `skip_tools` field supports powerful regex pattern matching for filtering out unwanted tools at runtime.
484+
485+
> 📖 **For comprehensive examples, advanced patterns, and detailed use cases, see [SKIP_TOOLS_GUIDE.md](./SKIP_TOOLS_GUIDE.md)**
486+
487+
### Pattern Behavior
488+
- **Automatic Anchoring**: Patterns are automatically anchored to match the entire tool name (wrapped with `^` and `$`)
489+
- **Regex Support**: Full regex syntax is supported, including wildcards, character classes, and quantifiers
490+
- **Case Sensitive**: Pattern matching is case-sensitive
491+
- **Compilation**: All patterns are compiled into a single optimized regex set for efficient matching
492+
493+
### Pattern Examples
494+
495+
#### Exact Matches
496+
```yaml
497+
skip_tools:
498+
- "debug_tool" # Matches only "debug_tool"
499+
- "test_runner" # Matches only "test_runner"
500+
```
501+
502+
#### Wildcard Patterns
503+
```yaml
504+
skip_tools:
505+
- "temp_.*" # Matches "temp_file", "temp_data", etc.
506+
- ".*_backup" # Matches "data_backup", "file_backup", etc.
507+
- "debug.*" # Matches "debug", "debugger", "debug_info", etc.
508+
```
509+
510+
#### Advanced Regex Patterns
511+
```yaml
512+
skip_tools:
513+
- "tool_[0-9]+" # Matches "tool_1", "tool_42", etc.
514+
- "test_(unit|integration)" # Matches "test_unit" and "test_integration"
515+
- "[a-z]+_helper" # Matches lowercase word + "_helper"
516+
- "system_(admin|user)_.*" # Matches tools starting with "system_admin_" or "system_user_"
517+
```
518+
519+
#### Explicit Anchoring
520+
```yaml
521+
skip_tools:
522+
- "^prefix_.*" # Explicit start anchor (same as "prefix_.*" due to auto-anchoring)
523+
- ".*_suffix$" # Explicit end anchor (same as ".*_suffix" due to auto-anchoring)
524+
- "^exact_only$" # Fully explicit anchoring (same as "exact_only")
525+
```
526+
527+
#### Special Characters
528+
```yaml
529+
skip_tools:
530+
- "file\\.exe" # Matches "file.exe" literally (escaped dot)
531+
- "script\\?" # Matches "script?" literally (escaped question mark)
532+
- "temp\\*data" # Matches "temp*data" literally (escaped asterisk)
533+
```
534+
535+
#### Common Use Cases
536+
```yaml
537+
skip_tools:
538+
- ".*_test" # Skip all test tools
539+
- "dev_.*" # Skip all development tools
540+
- "mock_.*" # Skip all mock tools
541+
- ".*_deprecated" # Skip all deprecated tools
542+
- "admin_.*" # Skip all admin tools
543+
- "debug.*" # Skip all debug-related tools
544+
```
545+
546+
### Error Handling
547+
- Invalid regex patterns will cause configuration loading to fail with a descriptive error
548+
- Empty pattern arrays are allowed and will skip no tools
549+
- The `skip_tools` field can be omitted entirely to skip no tools
550+
551+
### Performance Notes
552+
- All patterns are compiled into a single optimized `RegexSet` for O(1) tool name checking
553+
- Pattern compilation happens once at startup, not per tool evaluation
554+
- Large numbers of patterns have minimal runtime performance impact
555+
473556
## Notes
474557

475558
- Fields marked as `optional` can be omitted.
476559
- Plugin authors may extend `runtime_config` with additional fields, but only the above are officially recognized.
477560
- Authentication applies to all HTTPS requests made by plugins, including plugin downloads and runtime API calls.
478561
- URL matching is case-sensitive and based on string prefix matching.
479562
- Keyring authentication requires platform-specific keyring services to be available and accessible.
563+
- Skip tools patterns use full regex syntax with automatic anchoring for precise tool filtering.

0 commit comments

Comments
 (0)