mcp-proxy-adapter 6.8.1__py3-none-any.whl → 6.9.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcp_proxy_adapter/commands/proxy_registration_command.py +15 -9
- mcp_proxy_adapter/config.py +208 -110
- mcp_proxy_adapter/core/config_validator.py +1012 -189
- mcp_proxy_adapter/core/errors.py +42 -0
- mcp_proxy_adapter/core/logging.py +16 -16
- mcp_proxy_adapter/examples/config_builder.py +192 -741
- mcp_proxy_adapter/examples/full_application/main.py +10 -2
- mcp_proxy_adapter/examples/full_application/run_mtls.py +252 -0
- mcp_proxy_adapter/examples/full_application/run_simple.py +152 -0
- mcp_proxy_adapter/examples/full_application/test_server.py +221 -0
- mcp_proxy_adapter/examples/generate_config.py +61 -8
- mcp_proxy_adapter/examples/test_config.py +47 -2
- mcp_proxy_adapter/version.py +1 -1
- {mcp_proxy_adapter-6.8.1.dist-info → mcp_proxy_adapter-6.9.0.dist-info}/METADATA +1 -1
- {mcp_proxy_adapter-6.8.1.dist-info → mcp_proxy_adapter-6.9.0.dist-info}/RECORD +18 -15
- {mcp_proxy_adapter-6.8.1.dist-info → mcp_proxy_adapter-6.9.0.dist-info}/WHEEL +0 -0
- {mcp_proxy_adapter-6.8.1.dist-info → mcp_proxy_adapter-6.9.0.dist-info}/entry_points.txt +0 -0
- {mcp_proxy_adapter-6.8.1.dist-info → mcp_proxy_adapter-6.9.0.dist-info}/top_level.txt +0 -0
mcp_proxy_adapter/core/errors.py
CHANGED
@@ -3,6 +3,7 @@ Module for defining errors and exceptions for the microservice.
|
|
3
3
|
"""
|
4
4
|
|
5
5
|
from typing import Any, Dict, List, Optional, Union
|
6
|
+
from dataclasses import dataclass
|
6
7
|
|
7
8
|
|
8
9
|
class MicroserviceError(Exception):
|
@@ -215,3 +216,44 @@ def format_validation_errors(errors: List[Dict[str, Any]]) -> Dict[str, Any]:
|
|
215
216
|
msg = error.get("msg", "Validation error")
|
216
217
|
formatted_errors[field] = msg
|
217
218
|
return formatted_errors
|
219
|
+
|
220
|
+
|
221
|
+
@dataclass
|
222
|
+
class ValidationResult:
|
223
|
+
"""Result of configuration validation."""
|
224
|
+
level: str # "error", "warning", "info"
|
225
|
+
message: str
|
226
|
+
section: Optional[str] = None
|
227
|
+
key: Optional[str] = None
|
228
|
+
suggestion: Optional[str] = None
|
229
|
+
|
230
|
+
|
231
|
+
class ConfigError(MicroserviceError):
|
232
|
+
"""Configuration validation error."""
|
233
|
+
|
234
|
+
def __init__(self, message: str, validation_results: Optional[List[ValidationResult]] = None):
|
235
|
+
"""
|
236
|
+
Initialize configuration error.
|
237
|
+
|
238
|
+
Args:
|
239
|
+
message: Error message
|
240
|
+
validation_results: List of validation results that caused the error
|
241
|
+
"""
|
242
|
+
super().__init__(message, code=-32001, data={"type": "configuration_error"})
|
243
|
+
self.validation_results = validation_results or []
|
244
|
+
|
245
|
+
def get_error_summary(self) -> str:
|
246
|
+
"""Get summary of all validation errors."""
|
247
|
+
if not self.validation_results:
|
248
|
+
return self.message
|
249
|
+
|
250
|
+
error_messages = []
|
251
|
+
for result in self.validation_results:
|
252
|
+
if result.level == "error":
|
253
|
+
location = f"{result.section}.{result.key}" if result.key else result.section
|
254
|
+
error_msg = f"[{location}] {result.message}"
|
255
|
+
if result.suggestion:
|
256
|
+
error_msg += f" (Suggestion: {result.suggestion})"
|
257
|
+
error_messages.append(error_msg)
|
258
|
+
|
259
|
+
return "\n".join(error_messages)
|
@@ -9,7 +9,7 @@ import uuid
|
|
9
9
|
from logging.handlers import RotatingFileHandler, TimedRotatingFileHandler
|
10
10
|
from typing import Dict, Optional, Any
|
11
11
|
|
12
|
-
from mcp_proxy_adapter.config import
|
12
|
+
from mcp_proxy_adapter.config import get_config
|
13
13
|
|
14
14
|
|
15
15
|
class CustomFormatter(logging.Formatter):
|
@@ -121,11 +121,11 @@ def setup_logging(
|
|
121
121
|
Configured logger.
|
122
122
|
"""
|
123
123
|
# Get parameters from configuration if not explicitly specified
|
124
|
-
level = level or
|
124
|
+
level = level or get_config().get("logging.level", "INFO")
|
125
125
|
|
126
126
|
# Check debug level from config if debug is enabled
|
127
|
-
if
|
128
|
-
debug_level =
|
127
|
+
if get_config().get("debug.enabled", False):
|
128
|
+
debug_level = get_config().get("debug.level", "INFO")
|
129
129
|
# Use debug level if it's more verbose than the logging level
|
130
130
|
debug_level_num = getattr(logging, debug_level.upper(), logging.INFO)
|
131
131
|
level_num = getattr(logging, level.upper(), logging.INFO)
|
@@ -133,33 +133,33 @@ def setup_logging(
|
|
133
133
|
level = debug_level
|
134
134
|
logger.debug(f"Using debug level from config: {debug_level}")
|
135
135
|
|
136
|
-
log_file = log_file or
|
136
|
+
log_file = log_file or get_config().get("logging.file")
|
137
137
|
rotation_type = rotation_type or "size" # Default to size-based rotation
|
138
138
|
|
139
139
|
# Get log directory and file settings from config
|
140
|
-
log_dir =
|
141
|
-
log_file_name =
|
142
|
-
error_log_file =
|
143
|
-
access_log_file =
|
140
|
+
log_dir = get_config().get("logging.log_dir", "./logs")
|
141
|
+
log_file_name = get_config().get("logging.log_file", "mcp_proxy_adapter.log")
|
142
|
+
error_log_file = get_config().get("logging.error_log_file", "mcp_proxy_adapter_error.log")
|
143
|
+
access_log_file = get_config().get(
|
144
144
|
"logging.access_log_file", "mcp_proxy_adapter_access.log"
|
145
145
|
)
|
146
146
|
|
147
147
|
# Get rotation settings from config
|
148
|
-
max_file_size_str =
|
149
|
-
backup_count = backup_count or
|
148
|
+
max_file_size_str = get_config().get("logging.max_file_size", "10MB")
|
149
|
+
backup_count = backup_count or get_config().get("logging.backup_count", 5)
|
150
150
|
|
151
151
|
# Parse max file size (e.g., "10MB" -> 10 * 1024 * 1024)
|
152
152
|
max_bytes = max_bytes or _parse_file_size(max_file_size_str)
|
153
153
|
|
154
154
|
# Get format settings
|
155
|
-
log_format =
|
155
|
+
log_format = get_config().get(
|
156
156
|
"logging.format", "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
157
157
|
)
|
158
|
-
date_format =
|
158
|
+
date_format = get_config().get("logging.date_format", "%Y-%m-%d %H:%M:%S")
|
159
159
|
|
160
160
|
# Get output settings
|
161
|
-
console_output =
|
162
|
-
file_output =
|
161
|
+
console_output = get_config().get("logging.console_output", True)
|
162
|
+
file_output = get_config().get("logging.file_output", True)
|
163
163
|
|
164
164
|
# Convert string logging level to constant
|
165
165
|
numeric_level = getattr(logging, level.upper(), None)
|
@@ -227,7 +227,7 @@ def setup_logging(
|
|
227
227
|
logger.addHandler(access_handler)
|
228
228
|
|
229
229
|
# Configure loggers for external libraries
|
230
|
-
log_levels =
|
230
|
+
log_levels = get_config().get("logging.levels", {})
|
231
231
|
for logger_name, logger_level in log_levels.items():
|
232
232
|
lib_logger = logging.getLogger(logger_name)
|
233
233
|
lib_logger.setLevel(getattr(logging, logger_level.upper(), logging.INFO))
|