Skip to content

Commit c07d6bf

Browse files
committed
redesign config subsystem
1 parent 39284b0 commit c07d6bf

File tree

8 files changed

+683
-519
lines changed

8 files changed

+683
-519
lines changed

mcp_fuzzer/config/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
# Import loader functions
3535
from .loader import (
36+
ConfigLoader,
3637
find_config_file,
3738
load_config_file,
3839
apply_config_file,
@@ -67,10 +68,11 @@
6768
"DEFAULT_FORCE_KILL_TIMEOUT",
6869
# Manager
6970
"config",
70-
# Loader functions
71+
# Loader helpers
72+
"ConfigLoader",
7173
"find_config_file",
7274
"load_config_file",
7375
"apply_config_file",
7476
"get_config_schema",
7577
"load_custom_transports",
76-
]
78+
]

mcp_fuzzer/config/discovery.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python3
2+
"""Helpers for locating configuration files."""
3+
4+
from __future__ import annotations
5+
6+
import os
7+
from pathlib import Path
8+
9+
10+
def find_config_file(
11+
config_path: str | None = None,
12+
search_paths: list[str] | None = None,
13+
file_names: list[str] | None = None,
14+
) -> str | None:
15+
"""Find a configuration file in the given paths.
16+
17+
Args:
18+
config_path: Explicit path to config file, takes precedence if provided
19+
search_paths: List of directories to search for config files
20+
file_names: List of file names to search for
21+
22+
Returns:
23+
Path to the found config file or None if not found
24+
"""
25+
if config_path and os.path.isfile(config_path):
26+
return config_path
27+
28+
if search_paths is None:
29+
search_paths = [
30+
os.getcwd(),
31+
str(Path.home() / ".config" / "mcp-fuzzer"),
32+
]
33+
34+
if file_names is None:
35+
file_names = ["mcp-fuzzer.yml", "mcp-fuzzer.yaml"]
36+
37+
for path in search_paths:
38+
if not os.path.isdir(path):
39+
continue
40+
for name in file_names:
41+
file_path = os.path.join(path, name)
42+
if os.path.isfile(file_path):
43+
return file_path
44+
45+
return None

0 commit comments

Comments
 (0)