mcp-proxy-adapter 6.6.8__py3-none-any.whl → 6.7.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/api/app.py +136 -90
- mcp_proxy_adapter/commands/__init__.py +4 -0
- mcp_proxy_adapter/commands/registration_status_command.py +119 -0
- mcp_proxy_adapter/core/app_runner.py +29 -2
- mcp_proxy_adapter/core/async_proxy_registration.py +285 -0
- mcp_proxy_adapter/core/signal_handler.py +170 -0
- mcp_proxy_adapter/examples/config_builder.py +465 -55
- mcp_proxy_adapter/examples/generate_config.py +22 -15
- mcp_proxy_adapter/main.py +37 -1
- mcp_proxy_adapter/version.py +1 -1
- {mcp_proxy_adapter-6.6.8.dist-info → mcp_proxy_adapter-6.7.0.dist-info}/METADATA +1 -1
- {mcp_proxy_adapter-6.6.8.dist-info → mcp_proxy_adapter-6.7.0.dist-info}/RECORD +15 -12
- {mcp_proxy_adapter-6.6.8.dist-info → mcp_proxy_adapter-6.7.0.dist-info}/WHEEL +0 -0
- {mcp_proxy_adapter-6.6.8.dist-info → mcp_proxy_adapter-6.7.0.dist-info}/entry_points.txt +0 -0
- {mcp_proxy_adapter-6.6.8.dist-info → mcp_proxy_adapter-6.7.0.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env python3
|
2
2
|
"""
|
3
|
-
|
3
|
+
Enhanced Configuration Builder for MCP Proxy Adapter
|
4
|
+
Supports all configuration options and versions.
|
4
5
|
|
5
6
|
Author: Vasiliy Zdanovskiy
|
6
7
|
email: vasilyvz@gmail.com
|
@@ -24,17 +25,21 @@ class AuthMethod(Enum):
|
|
24
25
|
NONE = "none"
|
25
26
|
TOKEN = "token"
|
26
27
|
TOKEN_ROLES = "token_roles"
|
28
|
+
CERTIFICATE = "certificate"
|
29
|
+
BASIC = "basic"
|
30
|
+
OAUTH2 = "oauth2"
|
31
|
+
JWT = "jwt"
|
27
32
|
|
28
33
|
|
29
34
|
class ConfigBuilder:
|
30
|
-
"""
|
35
|
+
"""Enhanced configuration builder with full feature support."""
|
31
36
|
|
32
37
|
def __init__(self):
|
33
38
|
"""Initialize the configuration builder."""
|
34
39
|
self._reset_to_defaults()
|
35
40
|
|
36
41
|
def _reset_to_defaults(self):
|
37
|
-
"""Reset configuration to default values."""
|
42
|
+
"""Reset configuration to default values with all sections."""
|
38
43
|
self.config = {
|
39
44
|
"uuid": str(uuid.uuid4()),
|
40
45
|
"server": {
|
@@ -49,53 +54,258 @@ class ConfigBuilder:
|
|
49
54
|
"file": None,
|
50
55
|
"log_dir": "./logs",
|
51
56
|
"log_file": "mcp_proxy_adapter.log",
|
52
|
-
"
|
57
|
+
"error_log_file": "mcp_proxy_adapter_error.log",
|
58
|
+
"access_log_file": "mcp_proxy_adapter_access.log",
|
59
|
+
"max_file_size": "10MB",
|
53
60
|
"backup_count": 5,
|
61
|
+
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
62
|
+
"date_format": "%Y-%m-%d %H:%M:%S",
|
54
63
|
"console_output": True,
|
64
|
+
"file_output": True,
|
55
65
|
"json_format": False
|
56
66
|
},
|
57
|
-
"
|
58
|
-
"
|
59
|
-
"
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
"
|
65
|
-
|
66
|
-
"user": ["read", "write"],
|
67
|
-
"readonly": ["read"]
|
68
|
-
},
|
69
|
-
"roles_file": None
|
67
|
+
"commands": {
|
68
|
+
"auto_discovery": True,
|
69
|
+
"commands_directory": "./commands",
|
70
|
+
"catalog_directory": "./catalog",
|
71
|
+
"plugin_servers": [],
|
72
|
+
"auto_install_dependencies": True,
|
73
|
+
"enabled_commands": ["health", "echo", "list", "help"],
|
74
|
+
"disabled_commands": [],
|
75
|
+
"custom_commands_path": "./commands"
|
70
76
|
},
|
71
|
-
"
|
77
|
+
"ssl": {
|
72
78
|
"enabled": False,
|
73
|
-
"
|
74
|
-
"
|
75
|
-
"
|
79
|
+
"mode": "https_only",
|
80
|
+
"cert_file": None,
|
81
|
+
"key_file": None,
|
82
|
+
"ca_cert": None,
|
83
|
+
"verify_client": False,
|
84
|
+
"client_cert_required": False,
|
85
|
+
"chk_hostname": False,
|
86
|
+
"cipher_suites": [
|
87
|
+
"TLS_AES_256_GCM_SHA384",
|
88
|
+
"TLS_CHACHA20_POLY1305_SHA256"
|
89
|
+
],
|
90
|
+
"min_tls_version": "TLSv1.2",
|
91
|
+
"max_tls_version": None,
|
92
|
+
"token_auth": {
|
93
|
+
"enabled": False,
|
94
|
+
"header_name": "Authorization",
|
95
|
+
"token_prefix": "Bearer",
|
96
|
+
"tokens_file": "tokens.json",
|
97
|
+
"token_expiry": 3600,
|
98
|
+
"jwt_secret": "",
|
99
|
+
"jwt_algorithm": "HS256"
|
100
|
+
}
|
76
101
|
},
|
77
102
|
"transport": {
|
78
103
|
"type": "http",
|
79
104
|
"port": None,
|
80
|
-
"
|
81
|
-
|
105
|
+
"ssl": {
|
106
|
+
"enabled": False,
|
107
|
+
"cert_file": None,
|
108
|
+
"key_file": None,
|
109
|
+
"ca_cert": None,
|
110
|
+
"verify_client": False,
|
111
|
+
"client_cert_required": False
|
112
|
+
}
|
82
113
|
},
|
83
|
-
"
|
114
|
+
"proxy_registration": {
|
84
115
|
"enabled": False,
|
85
116
|
"proxy_url": "http://localhost:3004",
|
86
|
-
"public_host": None,
|
87
|
-
"public_port": None,
|
88
|
-
"protocol": None, # Will be set based on server protocol
|
89
117
|
"server_id": "mcp_proxy_adapter",
|
90
118
|
"server_name": "MCP Proxy Adapter",
|
91
119
|
"description": "JSON-RPC API for interacting with MCP Proxy",
|
92
|
-
"version": "6.6.
|
120
|
+
"version": "6.6.9",
|
121
|
+
"registration_timeout": 30,
|
122
|
+
"retry_attempts": 3,
|
123
|
+
"retry_delay": 5,
|
124
|
+
"auto_register_on_startup": True,
|
125
|
+
"auto_unregister_on_shutdown": True,
|
126
|
+
"auth_method": "none",
|
127
|
+
"server_url": None,
|
128
|
+
"fallback_proxy_url": None,
|
129
|
+
"public_host": None,
|
130
|
+
"public_port": None,
|
131
|
+
"protocol": None,
|
132
|
+
"certificate": {
|
133
|
+
"cert_file": None,
|
134
|
+
"key_file": None
|
135
|
+
},
|
136
|
+
"token": {
|
137
|
+
"token": None
|
138
|
+
},
|
139
|
+
"api_key": {
|
140
|
+
"key": None
|
141
|
+
},
|
142
|
+
"ssl": {
|
143
|
+
"ca_cert": None,
|
144
|
+
"verify_mode": "CERT_REQUIRED"
|
145
|
+
},
|
93
146
|
"heartbeat": {
|
94
147
|
"enabled": True,
|
95
148
|
"interval": 30,
|
96
149
|
"timeout": 10,
|
97
150
|
"retry_attempts": 3,
|
98
151
|
"retry_delay": 5
|
152
|
+
},
|
153
|
+
"proxy_info": {
|
154
|
+
"name": "mcp_proxy_adapter",
|
155
|
+
"description": "MCP Proxy Adapter",
|
156
|
+
"version": "6.6.9",
|
157
|
+
"capabilities": ["jsonrpc", "rest", "security"],
|
158
|
+
"endpoints": {
|
159
|
+
"jsonrpc": "/api/jsonrpc",
|
160
|
+
"rest": "/cmd",
|
161
|
+
"health": "/health"
|
162
|
+
}
|
163
|
+
}
|
164
|
+
},
|
165
|
+
"debug": {
|
166
|
+
"enabled": False,
|
167
|
+
"level": "WARNING",
|
168
|
+
"log_level": "DEBUG",
|
169
|
+
"trace_requests": False,
|
170
|
+
"trace_responses": False
|
171
|
+
},
|
172
|
+
"security": {
|
173
|
+
"framework": "mcp_security_framework",
|
174
|
+
"enabled": False,
|
175
|
+
"debug": False,
|
176
|
+
"environment": "dev",
|
177
|
+
"version": "1.0.0",
|
178
|
+
"tokens": {
|
179
|
+
"admin": "admin-secret-key",
|
180
|
+
"user": "user-secret-key",
|
181
|
+
"readonly": "readonly-secret-key"
|
182
|
+
},
|
183
|
+
"roles": {
|
184
|
+
"admin": ["read", "write", "delete", "admin"],
|
185
|
+
"user": ["read", "write"],
|
186
|
+
"readonly": ["read"]
|
187
|
+
},
|
188
|
+
"roles_file": None,
|
189
|
+
"auth": {
|
190
|
+
"enabled": False,
|
191
|
+
"methods": ["api_key"],
|
192
|
+
"api_keys": {},
|
193
|
+
"user_roles": {},
|
194
|
+
"jwt_secret": "",
|
195
|
+
"jwt_algorithm": "HS256",
|
196
|
+
"jwt_expiry_hours": 24,
|
197
|
+
"certificate_auth": False,
|
198
|
+
"certificate_roles_oid": "1.3.6.1.4.1.99999.1.1",
|
199
|
+
"certificate_permissions_oid": "1.3.6.1.4.1.99999.1.2",
|
200
|
+
"basic_auth": False,
|
201
|
+
"oauth2_config": None,
|
202
|
+
"public_paths": ["/health", "/docs", "/openapi.json"],
|
203
|
+
"security_headers": None
|
204
|
+
},
|
205
|
+
"ssl": {
|
206
|
+
"enabled": False,
|
207
|
+
"cert_file": None,
|
208
|
+
"key_file": None,
|
209
|
+
"ca_cert_file": None,
|
210
|
+
"client_cert_file": None,
|
211
|
+
"client_key_file": None,
|
212
|
+
"verify_mode": "CERT_NONE",
|
213
|
+
"min_tls_version": "TLSv1.2",
|
214
|
+
"max_tls_version": None,
|
215
|
+
"cipher_suite": None,
|
216
|
+
"check_hostname": True,
|
217
|
+
"check_expiry": True,
|
218
|
+
"expiry_warning_days": 30
|
219
|
+
},
|
220
|
+
"certificates": {
|
221
|
+
"enabled": False,
|
222
|
+
"ca_cert_path": None,
|
223
|
+
"ca_key_path": None,
|
224
|
+
"cert_storage_path": "./certs",
|
225
|
+
"key_storage_path": "./keys",
|
226
|
+
"default_validity_days": 365,
|
227
|
+
"key_size": 2048,
|
228
|
+
"hash_algorithm": "sha256",
|
229
|
+
"crl_enabled": False,
|
230
|
+
"crl_path": None,
|
231
|
+
"crl_url": None,
|
232
|
+
"crl_validity_days": 30,
|
233
|
+
"auto_renewal": False,
|
234
|
+
"renewal_threshold_days": 30
|
235
|
+
},
|
236
|
+
"permissions": {
|
237
|
+
"enabled": False,
|
238
|
+
"roles_file": None,
|
239
|
+
"default_role": "guest",
|
240
|
+
"admin_role": "admin",
|
241
|
+
"role_hierarchy": {},
|
242
|
+
"permission_cache_enabled": False,
|
243
|
+
"permission_cache_ttl": 300,
|
244
|
+
"wildcard_permissions": False,
|
245
|
+
"strict_mode": False,
|
246
|
+
"roles": None
|
247
|
+
},
|
248
|
+
"rate_limit": {
|
249
|
+
"enabled": False,
|
250
|
+
"default_requests_per_minute": 60,
|
251
|
+
"default_requests_per_hour": 1000,
|
252
|
+
"burst_limit": 2,
|
253
|
+
"window_size_seconds": 60,
|
254
|
+
"storage_backend": "memory",
|
255
|
+
"redis_config": None,
|
256
|
+
"cleanup_interval": 300,
|
257
|
+
"exempt_paths": ["/health", "/docs", "/openapi.json"],
|
258
|
+
"exempt_roles": ["admin"]
|
259
|
+
},
|
260
|
+
"logging": {
|
261
|
+
"enabled": True,
|
262
|
+
"level": "INFO",
|
263
|
+
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
264
|
+
"date_format": "%Y-%m-%d %H:%M:%S",
|
265
|
+
"file_path": None,
|
266
|
+
"max_file_size": 10,
|
267
|
+
"backup_count": 5,
|
268
|
+
"console_output": True,
|
269
|
+
"json_format": False,
|
270
|
+
"include_timestamp": True,
|
271
|
+
"include_level": True,
|
272
|
+
"include_module": True
|
273
|
+
}
|
274
|
+
},
|
275
|
+
"roles": {
|
276
|
+
"enabled": False,
|
277
|
+
"config_file": None,
|
278
|
+
"default_policy": {
|
279
|
+
"deny_by_default": False,
|
280
|
+
"require_role_match": False,
|
281
|
+
"case_sensitive": False,
|
282
|
+
"allow_wildcard": False
|
283
|
+
},
|
284
|
+
"auto_load": False,
|
285
|
+
"validation_enabled": False
|
286
|
+
},
|
287
|
+
"protocols": {
|
288
|
+
"enabled": True,
|
289
|
+
"allowed_protocols": ["http", "jsonrpc"],
|
290
|
+
"default_protocol": "http",
|
291
|
+
"auto_discovery": True,
|
292
|
+
"protocol_handlers": {
|
293
|
+
"http": {
|
294
|
+
"enabled": True,
|
295
|
+
"port": None,
|
296
|
+
"ssl": False
|
297
|
+
},
|
298
|
+
"https": {
|
299
|
+
"enabled": False,
|
300
|
+
"port": None,
|
301
|
+
"ssl": True
|
302
|
+
},
|
303
|
+
"mtls": {
|
304
|
+
"enabled": False,
|
305
|
+
"port": None,
|
306
|
+
"ssl": True,
|
307
|
+
"client_cert_required": True
|
308
|
+
}
|
99
309
|
}
|
100
310
|
}
|
101
311
|
}
|
@@ -105,22 +315,47 @@ class ConfigBuilder:
|
|
105
315
|
self.config["server"]["protocol"] = protocol.value
|
106
316
|
|
107
317
|
# Set registration protocol to match server protocol
|
108
|
-
self.config["
|
318
|
+
self.config["proxy_registration"]["protocol"] = protocol.value
|
319
|
+
|
320
|
+
# Update protocol handlers
|
321
|
+
for handler_name in self.config["protocols"]["protocol_handlers"]:
|
322
|
+
self.config["protocols"]["protocol_handlers"][handler_name]["enabled"] = False
|
109
323
|
|
110
324
|
if protocol == Protocol.HTTP:
|
111
325
|
# HTTP - no SSL, no client verification
|
112
|
-
self.config["transport"]["verify_client"] = False
|
113
|
-
self.config["transport"]["
|
326
|
+
self.config["transport"]["ssl"]["verify_client"] = False
|
327
|
+
self.config["transport"]["ssl"]["enabled"] = False
|
328
|
+
self.config["ssl"]["enabled"] = False
|
329
|
+
self.config["ssl"]["verify_client"] = False
|
330
|
+
self.config["ssl"]["chk_hostname"] = False
|
331
|
+
self.config["protocols"]["protocol_handlers"]["http"]["enabled"] = True
|
332
|
+
self.config["protocols"]["allowed_protocols"] = ["http"]
|
333
|
+
self.config["protocols"]["default_protocol"] = "http"
|
114
334
|
|
115
335
|
elif protocol == Protocol.HTTPS:
|
116
336
|
# HTTPS - SSL enabled, no client verification
|
117
|
-
self.config["transport"]["verify_client"] = False
|
118
|
-
self.config["transport"]["
|
337
|
+
self.config["transport"]["ssl"]["verify_client"] = False
|
338
|
+
self.config["transport"]["ssl"]["enabled"] = True
|
339
|
+
self.config["ssl"]["enabled"] = True
|
340
|
+
self.config["ssl"]["verify_client"] = False
|
341
|
+
self.config["ssl"]["chk_hostname"] = True
|
342
|
+
self.config["ssl"]["mode"] = "https_only"
|
343
|
+
self.config["protocols"]["protocol_handlers"]["https"]["enabled"] = True
|
344
|
+
self.config["protocols"]["allowed_protocols"] = ["https"]
|
345
|
+
self.config["protocols"]["default_protocol"] = "https"
|
119
346
|
|
120
347
|
elif protocol == Protocol.MTLS:
|
121
348
|
# mTLS - SSL enabled, client verification required
|
122
|
-
self.config["transport"]["verify_client"] = True
|
123
|
-
self.config["transport"]["
|
349
|
+
self.config["transport"]["ssl"]["verify_client"] = True
|
350
|
+
self.config["transport"]["ssl"]["enabled"] = True
|
351
|
+
self.config["ssl"]["enabled"] = True
|
352
|
+
self.config["ssl"]["verify_client"] = True
|
353
|
+
self.config["ssl"]["chk_hostname"] = True
|
354
|
+
self.config["ssl"]["mode"] = "mtls"
|
355
|
+
self.config["ssl"]["client_cert_required"] = True
|
356
|
+
self.config["protocols"]["protocol_handlers"]["mtls"]["enabled"] = True
|
357
|
+
self.config["protocols"]["allowed_protocols"] = ["mtls"]
|
358
|
+
self.config["protocols"]["default_protocol"] = "mtls"
|
124
359
|
|
125
360
|
return self
|
126
361
|
|
@@ -128,12 +363,16 @@ class ConfigBuilder:
|
|
128
363
|
"""Set authentication configuration."""
|
129
364
|
if auth_method == AuthMethod.NONE:
|
130
365
|
self.config["security"]["enabled"] = False
|
366
|
+
self.config["security"]["auth"]["enabled"] = False
|
367
|
+
self.config["security"]["auth"]["methods"] = []
|
131
368
|
self.config["security"]["tokens"] = {}
|
132
369
|
self.config["security"]["roles"] = {}
|
133
370
|
self.config["security"]["roles_file"] = None
|
134
371
|
|
135
372
|
elif auth_method == AuthMethod.TOKEN:
|
136
373
|
self.config["security"]["enabled"] = True
|
374
|
+
self.config["security"]["auth"]["enabled"] = True
|
375
|
+
self.config["security"]["auth"]["methods"] = ["api_key"]
|
137
376
|
self.config["security"]["tokens"] = api_keys or {
|
138
377
|
"admin": "admin-secret-key",
|
139
378
|
"user": "user-secret-key"
|
@@ -146,6 +385,8 @@ class ConfigBuilder:
|
|
146
385
|
|
147
386
|
elif auth_method == AuthMethod.TOKEN_ROLES:
|
148
387
|
self.config["security"]["enabled"] = True
|
388
|
+
self.config["security"]["auth"]["enabled"] = True
|
389
|
+
self.config["security"]["auth"]["methods"] = ["api_key"]
|
149
390
|
self.config["security"]["tokens"] = api_keys or {
|
150
391
|
"admin": "admin-secret-key",
|
151
392
|
"user": "user-secret-key",
|
@@ -157,39 +398,141 @@ class ConfigBuilder:
|
|
157
398
|
"readonly": ["read"]
|
158
399
|
}
|
159
400
|
self.config["security"]["roles_file"] = "configs/roles.json"
|
401
|
+
self.config["roles"]["enabled"] = True
|
402
|
+
self.config["roles"]["config_file"] = "configs/roles.json"
|
403
|
+
|
404
|
+
elif auth_method == AuthMethod.CERTIFICATE:
|
405
|
+
self.config["security"]["enabled"] = True
|
406
|
+
self.config["security"]["auth"]["enabled"] = True
|
407
|
+
self.config["security"]["auth"]["methods"] = ["certificate"]
|
408
|
+
self.config["security"]["auth"]["certificate_auth"] = True
|
409
|
+
self.config["security"]["ssl"]["enabled"] = True
|
410
|
+
self.config["security"]["ssl"]["verify_mode"] = "CERT_REQUIRED"
|
411
|
+
|
412
|
+
elif auth_method == AuthMethod.BASIC:
|
413
|
+
self.config["security"]["enabled"] = True
|
414
|
+
self.config["security"]["auth"]["enabled"] = True
|
415
|
+
self.config["security"]["auth"]["methods"] = ["basic"]
|
416
|
+
self.config["security"]["auth"]["basic_auth"] = True
|
417
|
+
|
418
|
+
elif auth_method == AuthMethod.OAUTH2:
|
419
|
+
self.config["security"]["enabled"] = True
|
420
|
+
self.config["security"]["auth"]["enabled"] = True
|
421
|
+
self.config["security"]["auth"]["methods"] = ["oauth2"]
|
422
|
+
self.config["security"]["auth"]["oauth2_config"] = {}
|
423
|
+
|
424
|
+
elif auth_method == AuthMethod.JWT:
|
425
|
+
self.config["security"]["enabled"] = True
|
426
|
+
self.config["security"]["auth"]["enabled"] = True
|
427
|
+
self.config["security"]["auth"]["methods"] = ["jwt"]
|
428
|
+
self.config["security"]["auth"]["jwt_secret"] = "your-jwt-secret"
|
429
|
+
self.config["security"]["auth"]["jwt_algorithm"] = "HS256"
|
160
430
|
|
161
431
|
return self
|
162
432
|
|
163
|
-
def set_server(self, host: str = "0.0.0.0", port: int = 8000):
|
433
|
+
def set_server(self, host: str = "0.0.0.0", port: int = 8000, debug: bool = False, log_level: str = "INFO"):
|
164
434
|
"""Set server configuration."""
|
165
435
|
self.config["server"]["host"] = host
|
166
436
|
self.config["server"]["port"] = port
|
437
|
+
self.config["server"]["debug"] = debug
|
438
|
+
self.config["server"]["log_level"] = log_level
|
439
|
+
return self
|
440
|
+
|
441
|
+
def set_logging(self, log_dir: str = "./logs", level: str = "INFO", console_output: bool = True, file_output: bool = True):
|
442
|
+
"""Set logging configuration."""
|
443
|
+
self.config["logging"]["log_dir"] = log_dir
|
444
|
+
self.config["logging"]["level"] = level
|
445
|
+
self.config["logging"]["console_output"] = console_output
|
446
|
+
self.config["logging"]["file_output"] = file_output
|
447
|
+
return self
|
448
|
+
|
449
|
+
def set_commands(self, enabled_commands: Optional[List[str]] = None, disabled_commands: Optional[List[str]] = None):
|
450
|
+
"""Set commands configuration."""
|
451
|
+
if enabled_commands:
|
452
|
+
self.config["commands"]["enabled_commands"] = enabled_commands
|
453
|
+
if disabled_commands:
|
454
|
+
self.config["commands"]["disabled_commands"] = disabled_commands
|
167
455
|
return self
|
168
456
|
|
169
457
|
def set_roles_file(self, roles_file: str):
|
170
458
|
"""Set roles file path."""
|
171
459
|
self.config["security"]["roles_file"] = roles_file
|
460
|
+
self.config["roles"]["config_file"] = roles_file
|
461
|
+
self.config["roles"]["enabled"] = True
|
172
462
|
return self
|
173
463
|
|
174
464
|
def set_proxy_registration(self, enabled: bool = True, proxy_url: str = "http://localhost:3004",
|
175
|
-
|
176
|
-
|
177
|
-
|
465
|
+
public_host: Optional[str] = None, public_port: Optional[int] = None,
|
466
|
+
server_id: str = "mcp_proxy_adapter", server_name: str = "MCP Proxy Adapter",
|
467
|
+
description: str = "JSON-RPC API for interacting with MCP Proxy",
|
468
|
+
auth_method: str = "none", cert_file: Optional[str] = None, key_file: Optional[str] = None):
|
178
469
|
"""Set proxy registration configuration."""
|
179
|
-
self.config["
|
180
|
-
self.config["
|
181
|
-
self.config["
|
182
|
-
self.config["
|
183
|
-
self.config["
|
184
|
-
self.config["
|
185
|
-
self.config["
|
470
|
+
self.config["proxy_registration"]["enabled"] = enabled
|
471
|
+
self.config["proxy_registration"]["proxy_url"] = proxy_url
|
472
|
+
self.config["proxy_registration"]["public_host"] = public_host
|
473
|
+
self.config["proxy_registration"]["public_port"] = public_port
|
474
|
+
self.config["proxy_registration"]["server_id"] = server_id
|
475
|
+
self.config["proxy_registration"]["server_name"] = server_name
|
476
|
+
self.config["proxy_registration"]["description"] = description
|
477
|
+
self.config["proxy_registration"]["auth_method"] = auth_method
|
478
|
+
|
479
|
+
if cert_file:
|
480
|
+
self.config["proxy_registration"]["certificate"]["cert_file"] = cert_file
|
481
|
+
if key_file:
|
482
|
+
self.config["proxy_registration"]["certificate"]["key_file"] = key_file
|
186
483
|
|
187
484
|
# Set protocol to match server protocol if not explicitly set
|
188
|
-
if self.config["
|
189
|
-
self.config["
|
485
|
+
if self.config["proxy_registration"]["protocol"] is None:
|
486
|
+
self.config["proxy_registration"]["protocol"] = self.config["server"]["protocol"]
|
487
|
+
|
488
|
+
return self
|
489
|
+
|
490
|
+
def enable_auto_registration(self, proxy_url: str = "http://localhost:3004",
|
491
|
+
server_id: str = "mcp_proxy_adapter",
|
492
|
+
server_name: str = "MCP Proxy Adapter",
|
493
|
+
description: str = "JSON-RPC API for interacting with MCP Proxy",
|
494
|
+
auth_method: str = "none"):
|
495
|
+
"""
|
496
|
+
Enable automatic proxy registration with auto-determined parameters.
|
497
|
+
|
498
|
+
This method enables registration with automatic determination of:
|
499
|
+
- public_host: from hostname (if server.host is 0.0.0.0/127.0.0.1) or server.host
|
500
|
+
- public_port: from server.port
|
501
|
+
- protocol: from server.protocol
|
502
|
+
|
503
|
+
Args:
|
504
|
+
proxy_url: URL of the proxy server
|
505
|
+
server_id: Unique identifier for this server
|
506
|
+
server_name: Human-readable name for this server
|
507
|
+
description: Description of this server
|
508
|
+
auth_method: Authentication method for proxy registration
|
509
|
+
"""
|
510
|
+
self.config["proxy_registration"]["enabled"] = True
|
511
|
+
self.config["proxy_registration"]["proxy_url"] = proxy_url
|
512
|
+
self.config["proxy_registration"]["public_host"] = None # Auto-determined
|
513
|
+
self.config["proxy_registration"]["public_port"] = None # Auto-determined
|
514
|
+
self.config["proxy_registration"]["protocol"] = None # Auto-determined
|
515
|
+
self.config["proxy_registration"]["server_id"] = server_id
|
516
|
+
self.config["proxy_registration"]["server_name"] = server_name
|
517
|
+
self.config["proxy_registration"]["description"] = description
|
518
|
+
self.config["proxy_registration"]["auth_method"] = auth_method
|
190
519
|
|
191
520
|
return self
|
192
521
|
|
522
|
+
def set_ssl_certificates(self, cert_file: str, key_file: str, ca_cert: Optional[str] = None):
|
523
|
+
"""Set SSL certificate paths."""
|
524
|
+
self.config["ssl"]["cert_file"] = cert_file
|
525
|
+
self.config["ssl"]["key_file"] = key_file
|
526
|
+
if ca_cert:
|
527
|
+
self.config["ssl"]["ca_cert"] = ca_cert
|
528
|
+
return self
|
529
|
+
|
530
|
+
def set_debug(self, enabled: bool = True, log_level: str = "DEBUG"):
|
531
|
+
"""Set debug configuration."""
|
532
|
+
self.config["debug"]["enabled"] = enabled
|
533
|
+
self.config["debug"]["log_level"] = log_level
|
534
|
+
return self
|
535
|
+
|
193
536
|
def build(self) -> Dict[str, Any]:
|
194
537
|
"""Build and return the configuration."""
|
195
538
|
return self.config.copy()
|
@@ -282,7 +625,16 @@ class ConfigFactory:
|
|
282
625
|
.build())
|
283
626
|
|
284
627
|
@staticmethod
|
285
|
-
def
|
628
|
+
def create_mtls_certificate_config(port: int = 8009) -> Dict[str, Any]:
|
629
|
+
"""Create mTLS with certificate authentication configuration."""
|
630
|
+
return (ConfigBuilder()
|
631
|
+
.set_protocol(Protocol.MTLS)
|
632
|
+
.set_auth(AuthMethod.CERTIFICATE)
|
633
|
+
.set_server(port=port)
|
634
|
+
.build())
|
635
|
+
|
636
|
+
@staticmethod
|
637
|
+
def create_http_with_proxy_config(port: int = 8010, proxy_url: str = "http://localhost:3004") -> Dict[str, Any]:
|
286
638
|
"""Create HTTP configuration with proxy registration."""
|
287
639
|
return (ConfigBuilder()
|
288
640
|
.set_protocol(Protocol.HTTP)
|
@@ -291,7 +643,7 @@ class ConfigFactory:
|
|
291
643
|
.build())
|
292
644
|
|
293
645
|
@staticmethod
|
294
|
-
def create_https_with_proxy_config(port: int =
|
646
|
+
def create_https_with_proxy_config(port: int = 8011, proxy_url: str = "https://localhost:3004") -> Dict[str, Any]:
|
295
647
|
"""Create HTTPS configuration with proxy registration."""
|
296
648
|
return (ConfigBuilder()
|
297
649
|
.set_protocol(Protocol.HTTPS)
|
@@ -300,17 +652,69 @@ class ConfigFactory:
|
|
300
652
|
.build())
|
301
653
|
|
302
654
|
@staticmethod
|
303
|
-
def create_mtls_with_proxy_config(port: int =
|
655
|
+
def create_mtls_with_proxy_config(port: int = 8012, proxy_url: str = "https://localhost:3004") -> Dict[str, Any]:
|
304
656
|
"""Create mTLS configuration with proxy registration."""
|
305
657
|
return (ConfigBuilder()
|
306
658
|
.set_protocol(Protocol.MTLS)
|
307
659
|
.set_server(port=port)
|
308
660
|
.set_proxy_registration(proxy_url=proxy_url)
|
309
661
|
.build())
|
662
|
+
|
663
|
+
@staticmethod
|
664
|
+
def create_http_with_auto_registration(port: int = 8013, proxy_url: str = "http://localhost:3004",
|
665
|
+
server_id: str = "mcp_proxy_adapter") -> Dict[str, Any]:
|
666
|
+
"""Create HTTP configuration with automatic proxy registration."""
|
667
|
+
return (ConfigBuilder()
|
668
|
+
.set_protocol(Protocol.HTTP)
|
669
|
+
.set_server(port=port)
|
670
|
+
.enable_auto_registration(proxy_url=proxy_url, server_id=server_id)
|
671
|
+
.build())
|
672
|
+
|
673
|
+
@staticmethod
|
674
|
+
def create_https_with_auto_registration(port: int = 8014, proxy_url: str = "https://localhost:3004",
|
675
|
+
server_id: str = "mcp_proxy_adapter") -> Dict[str, Any]:
|
676
|
+
"""Create HTTPS configuration with automatic proxy registration."""
|
677
|
+
return (ConfigBuilder()
|
678
|
+
.set_protocol(Protocol.HTTPS)
|
679
|
+
.set_server(port=port)
|
680
|
+
.enable_auto_registration(proxy_url=proxy_url, server_id=server_id)
|
681
|
+
.build())
|
682
|
+
|
683
|
+
@staticmethod
|
684
|
+
def create_mtls_with_auto_registration(port: int = 8015, proxy_url: str = "https://localhost:3004",
|
685
|
+
server_id: str = "mcp_proxy_adapter") -> Dict[str, Any]:
|
686
|
+
"""Create mTLS configuration with automatic proxy registration."""
|
687
|
+
return (ConfigBuilder()
|
688
|
+
.set_protocol(Protocol.MTLS)
|
689
|
+
.set_server(port=port)
|
690
|
+
.enable_auto_registration(proxy_url=proxy_url, server_id=server_id)
|
691
|
+
.build())
|
692
|
+
|
693
|
+
@staticmethod
|
694
|
+
def create_full_featured_config(port: int = 8020) -> Dict[str, Any]:
|
695
|
+
"""Create full-featured configuration with all options enabled."""
|
696
|
+
return (ConfigBuilder()
|
697
|
+
.set_protocol(Protocol.MTLS)
|
698
|
+
.set_auth(AuthMethod.TOKEN_ROLES)
|
699
|
+
.set_server(port=port)
|
700
|
+
.enable_auto_registration(
|
701
|
+
proxy_url="https://mcp-proxy:3004",
|
702
|
+
server_id="full-featured-server",
|
703
|
+
server_name="Full Featured Server",
|
704
|
+
description="Server with all features enabled"
|
705
|
+
)
|
706
|
+
.set_ssl_certificates(
|
707
|
+
cert_file="./certs/server.crt",
|
708
|
+
key_file="./keys/server.key",
|
709
|
+
ca_cert="./certs/ca.crt"
|
710
|
+
)
|
711
|
+
.set_debug(enabled=True)
|
712
|
+
.build())
|
310
713
|
|
311
714
|
|
312
715
|
def create_config_from_flags(protocol: str, token: bool = False, roles: bool = False, port: int = 8000,
|
313
|
-
proxy_registration: bool = False, proxy_url: str = "http://localhost:3004"
|
716
|
+
proxy_registration: bool = False, proxy_url: str = "http://localhost:3004",
|
717
|
+
auto_registration: bool = False, server_id: str = "mcp_proxy_adapter") -> Dict[str, Any]:
|
314
718
|
"""
|
315
719
|
Create configuration from command line flags.
|
316
720
|
|
@@ -319,8 +723,10 @@ def create_config_from_flags(protocol: str, token: bool = False, roles: bool = F
|
|
319
723
|
token: Enable token authentication
|
320
724
|
roles: Enable role-based access control
|
321
725
|
port: Server port
|
322
|
-
proxy_registration: Enable proxy registration
|
726
|
+
proxy_registration: Enable proxy registration with manual settings
|
323
727
|
proxy_url: Proxy URL for registration
|
728
|
+
auto_registration: Enable automatic proxy registration (auto-determined parameters)
|
729
|
+
server_id: Server ID for registration
|
324
730
|
|
325
731
|
Returns:
|
326
732
|
Configuration dictionary
|
@@ -344,7 +750,11 @@ def create_config_from_flags(protocol: str, token: bool = False, roles: bool = F
|
|
344
750
|
builder.set_auth(AuthMethod.NONE)
|
345
751
|
|
346
752
|
# Enable proxy registration if requested
|
347
|
-
if
|
753
|
+
if auto_registration:
|
754
|
+
# Use automatic registration with auto-determined parameters
|
755
|
+
builder.enable_auto_registration(proxy_url=proxy_url, server_id=server_id)
|
756
|
+
elif proxy_registration:
|
757
|
+
# Use manual registration settings
|
348
758
|
builder.set_proxy_registration(proxy_url=proxy_url)
|
349
759
|
|
350
760
|
return builder.build()
|
@@ -353,4 +763,4 @@ def create_config_from_flags(protocol: str, token: bool = False, roles: bool = F
|
|
353
763
|
if __name__ == "__main__":
|
354
764
|
# Example usage
|
355
765
|
config = create_config_from_flags("http", token=True, port=8001)
|
356
|
-
print(json.dumps(config, indent=2))
|
766
|
+
print(json.dumps(config, indent=2))
|