Skip to content

Commit bcb4bdf

Browse files
Improve maintainability (#109)
* Improve modularity * update4 docs * Add unittest * resolve comments * more improvements * resolve comments * resolve comments * Fix review comments * Fix: Improve transport handling in CLI
1 parent a21b09c commit bcb4bdf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2183
-1565
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ testing_servers/
6161
nosetests.xml
6262
coverage.xml
6363
*.cover
64-
*.py
6564
.hypothesis/
6665
.pytest_cache/
6766
cover/

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ If your server conforms to the [MCP schema](https://github.com/modelcontextproto
3939
- Production Ready: Environment detection and production-safe defaults
4040
- Intelligent Testing: Hypothesis-based data generation with custom strategies
4141

42+
### Extensibility for Contributors
43+
MCP Server Fuzzer is designed for easy extension while keeping CLI usage simple:
44+
45+
- **Custom Transports**: Add support for new protocols via config or self-registration (see [docs/transport/custom-transports.md](docs/transport/custom-transports.md)).
46+
- **Pluggable Safety**: Swap safety providers for custom filtering rules.
47+
- **Injectable Components**: Advanced users can inject custom clients/reporters for testing or plugins.
48+
49+
The modularity improvements (dependency injection, registries) make it maintainer-friendly without complicating the core CLI experience.
50+
4251
## Quick Start
4352

4453
### Installation

docs/architecture/client-architecture.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ import asyncio
8181
asyncio.run(fuzz_server())
8282
```
8383

84-
For backward compatibility, the old `UnifiedMCPFuzzerClient` name is still available as an alias for `MCPFuzzerClient`.
85-
8684
## Future Improvements
8785

8886
1. **Plugin Architecture**: Add support for custom fuzzing strategies via plugins

docs/components/safety.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,6 @@ mcp-fuzzer --mode tools --protocol stdio --endpoint "python test_server.py" --no
311311
### Advanced Safety Configuration
312312

313313
```bash
314-
# Custom safety plugin
315-
mcp-fuzzer --mode tools --protocol stdio --endpoint "python test_server.py" \
316-
--safety-plugin my_safety_module.SafetyProvider
317-
318314
# Retry with safety on interrupt
319315
mcp-fuzzer --mode tools --protocol stdio --endpoint "python test_server.py" \
320316
--retry-with-safety-on-interrupt
@@ -388,12 +384,10 @@ class CustomSafetySystem(SafetySystem):
388384
```bash
389385
# Use custom safety provider
390386
mcp-fuzzer --mode tools --protocol stdio --endpoint "python test_server.py" \
391-
--safety-plugin my_safety_module.CustomSafetyProvider
392387

393388
# With configuration
394389
export MCP_FUZZER_SAFETY_CONFIG=/path/to/safety_config.json
395390
mcp-fuzzer --mode tools --protocol stdio --endpoint "python test_server.py" \
396-
--safety-plugin my_safety_module.CustomSafetyProvider
397391
```
398392

399393
## Safety Alerts and Logging

docs/development/contributing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,9 @@ The project uses semantic versioning:
485485

486486
- **MAJOR**: Incompatible API changes
487487

488-
- **MINOR**: New functionality (backward compatible)
488+
- **MINOR**: New functionality that preserves the public API
489489

490-
- **PATCH**: Bug fixes (backward compatible)
490+
- **PATCH**: Bug fixes that do not change the API
491491

492492
### Release Steps
493493

docs/development/reference.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ Notes:
5757
| Option | Type | Default | Description |
5858
|--------|------|---------|-------------|
5959
| `--enable-safety-system` | Flag | False | Enable system-level safety features |
60+
| `--no-safety` | Flag | False | Disable argument-level safety filtering |
6061
| `--fs-root` | Path | ~/.mcp_fuzzer | Restrict filesystem operations to specified directory |
61-
| `--safety-plugin` | String | - | Dotted path to custom safety provider |
62-
| `--no-safety` | Flag | False | Disable argument-level safety filtering (not recommended) |
6362
| `--retry-with-safety-on-interrupt` | Flag | False | Retry once with safety system enabled on Ctrl-C |
6463

6564
### Reporting Options
@@ -1103,7 +1102,7 @@ The safety system focuses on containment and preventing external references duri
11031102

11041103
- Argument-level filtering (`mcp_fuzzer.safety_system.safety.SafetyFilter`):
11051104
- Blocks URLs and risky commands in tool arguments; recursively sanitizes dicts/lists.
1106-
- Pluggable provider via `--safety-plugin`; `--no-safety` disables filtering.
1105+
- CLI provides `--fs-root` to redirect sandbox.
11071106
- `set_fs_root(path)` records a sandbox root (for future path checks).
11081107

11091108
- System-level blocking (`mcp_fuzzer.safety_system.system_blocker.SystemCommandBlocker`):

docs/getting-started/examples.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,12 @@ mcp-fuzzer --mode tools --protocol stdio --endpoint "python test_server.py" --fs
151151

152152
# Disable argument-level safety (not recommended)
153153
mcp-fuzzer --mode tools --protocol stdio --endpoint "python test_server.py" --no-safety
154+
154155
```
155156

156157
### Advanced Safety Configuration
157158

158159
```bash
159-
# Custom safety plugin
160-
mcp-fuzzer --mode tools --protocol stdio --endpoint "python test_server.py" --safety-plugin my_safety_module.SafetyProvider
161-
162160
# Retry with safety on interrupt
163161
mcp-fuzzer --mode tools --protocol stdio --endpoint "python test_server.py" --retry-with-safety-on-interrupt
164162

@@ -925,4 +923,3 @@ mcp-fuzzer --mode tools --phase aggressive --protocol http --endpoint http://loc
925923
# Monitor performance
926924
mcp-fuzzer --mode tools --protocol http --endpoint http://localhost:8000 --runs 100 --log-level INFO
927925
These examples cover the most common use cases and should help you get started with MCP Server Fuzzer. For more advanced configurations and customizations, refer to the [Reference](reference.md), [Architecture](architecture.md), and [Runtime Management](runtime-management.md) documentation.
928-

docs/getting-started/getting-started.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,15 @@ mcp-fuzzer --mode tools --auth-env --endpoint http://localhost:8000
225225
### Basic Safety Features
226226

227227
```bash
228-
# Enable safety system
228+
# Enable safety system (default)
229229
mcp-fuzzer --mode tools --protocol stdio --endpoint "python test_server.py" --enable-safety-system
230230

231231
# Set filesystem root
232232
mcp-fuzzer --mode tools --protocol stdio --endpoint "python test_server.py" --fs-root /tmp/safe_dir
233233

234234
# Disable argument-level safety (not recommended)
235235
mcp-fuzzer --mode tools --protocol stdio --endpoint "python test_server.py" --no-safety
236+
236237
```
237238

238239
### Safety System Features

docs/transport/custom-transports.md

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ class MyCustomTransport(TransportProtocol):
6161
# Implement notification sending logic
6262
pass
6363

64+
async def close(self) -> None:
65+
"""Close the transport connection."""
66+
# Cleanup logic
67+
pass
68+
6469
async def _stream_request(
6570
self, payload: Dict[str, Any]
6671
) -> AsyncIterator[Dict[str, Any]]:
@@ -71,72 +76,46 @@ class MyCustomTransport(TransportProtocol):
7176
yield {}
7277
```
7378

74-
### 2. Register the Transport
75-
76-
#### Option A: Programmatic Registration
77-
78-
```python
79-
from mcp_fuzzer.transport import register_custom_transport
80-
81-
# Register your custom transport
82-
register_custom_transport(
83-
name="mytransport",
84-
transport_class=MyCustomTransport,
85-
description="My custom MCP transport implementation",
86-
config_schema={
87-
"type": "object",
88-
"properties": {
89-
"timeout": {"type": "number"},
90-
"retries": {"type": "integer"}
91-
}
92-
}
93-
)
94-
```
95-
96-
#### Option B: Configuration File Registration
79+
### 2. Register Your Transport
9780

98-
Add to your `mcp-fuzzer.yaml` configuration file:
81+
Add your custom transport to the configuration file:
9982

10083
```yaml
84+
# config.yaml
10185
custom_transports:
102-
mytransport:
86+
my-custom:
10387
module: "my_package.transports"
10488
class: "MyCustomTransport"
105-
description: "My custom MCP transport implementation"
106-
config:
107-
timeout: 30
108-
retries: 3
89+
# Optional: additional init kwargs
90+
extra_arg: "value"
10991
```
11092
111-
### 3. Use the Custom Transport
93+
### 3. Use in CLI
11294
113-
Once registered, your custom transport can be used in several ways:
95+
Now you can use your custom transport via the CLI:
11496
115-
#### Via URL Scheme
116-
117-
```python
118-
from mcp_fuzzer.transport import create_transport
119-
120-
# Use custom transport with URL scheme
121-
transport = create_transport("mytransport://my-endpoint")
97+
```bash
98+
mcp-fuzzer --protocol my-custom --config config.yaml --endpoint my-endpoint
12299
```
123100

124-
#### Via Factory Function
101+
## Advanced: Self-Registration with Registry
102+
103+
The transport factory now uses a `TransportRegistry` for built-in transports. For custom transports, you can optionally self-register in your module for even easier extension:
125104

126105
```python
127-
from mcp_fuzzer.transport import create_custom_transport
106+
# In my_package/transports.py
107+
from mcp_fuzzer.transport.factory import registry
108+
109+
class MyCustomTransport(TransportProtocol):
110+
# ... implementation ...
128111

129-
# Create custom transport instance directly
130-
transport = create_custom_transport("mytransport", "my-endpoint")
112+
# Self-register (runs when module is imported)
113+
registry.register("my-custom", MyCustomTransport)
131114
```
132115

133-
#### Via Configuration
116+
This makes extension simpler – no factory changes needed, and CLI usage remains unchanged.
134117

135-
```yaml
136-
# In mcp-fuzzer.yaml
137-
protocol: mytransport
138-
endpoint: "my-endpoint"
139-
```
118+
Note: Self-registration is optional; config-based registration (step 2) still works and is recommended for most cases.
140119

141120
## Example: WebSocket Transport
142121

docs/transport/transport-improvements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ async def send_raw(self, payload: Dict[str, Any]) -> Dict[str, Any]:
231231

232232
### For Existing Code
233233

234-
The improvements are backward compatible. Existing code will continue to work without changes:
234+
Existing code continues to work without changes:
235235

236236
```python
237237
# This still works exactly the same

0 commit comments

Comments
 (0)