mcp-proxy-adapter 6.4.43__py3-none-any.whl → 6.4.44__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.
@@ -1,393 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Author: Vasiliy Zdanovskiy
4
- email: vasilyvz@gmail.com
5
- Script for generating test configurations for MCP Proxy Adapter.
6
- Generates 6 different configuration types for testing various security scenarios.
7
- """
8
- import json
9
- import os
10
- import argparse
11
- import uuid
12
- from typing import Dict, Any
13
-
14
-
15
- def generate_http_simple_config(
16
- port: int = 20000, certs_dir: str = "certs", keys_dir: str = "keys"
17
- ) -> Dict[str, Any]:
18
- """Generate HTTP configuration without authorization."""
19
- return {
20
- "uuid": str(uuid.uuid4()),
21
- "server": {"host": "127.0.0.1", "port": port},
22
- "ssl": {"enabled": False},
23
- "security": {"enabled": False},
24
- "registration": {
25
- "enabled": False,
26
- "auth_method": "token",
27
- "server_url": "http://127.0.0.1:3004/proxy",
28
- "token": {"enabled": True, "token": "proxy_registration_token_123"},
29
- "proxy_info": {
30
- "name": "mcp_example_server",
31
- "capabilities": ["jsonrpc", "rest", "proxy_registration"],
32
- "endpoints": {
33
- "jsonrpc": "/api/jsonrpc",
34
- "rest": "/cmd",
35
- "health": "/health",
36
- },
37
- },
38
- "heartbeat": {"enabled": True, "interval": 30},
39
- },
40
- "protocols": {"enabled": True, "allowed_protocols": ["http"]},
41
- }
42
-
43
-
44
- def generate_http_token_config(
45
- port: int = 20001,
46
- certs_dir: str = "certs",
47
- keys_dir: str = "keys",
48
- roles_file: str = "configs/roles.json",
49
- ) -> Dict[str, Any]:
50
- """Generate HTTP configuration with token authorization."""
51
- return {
52
- "uuid": str(uuid.uuid4()),
53
- "server": {"host": "127.0.0.1", "port": port},
54
- "ssl": {"enabled": False},
55
- "security": {
56
- "enabled": True,
57
- "auth": {
58
- "enabled": True,
59
- "methods": ["api_key"],
60
- # Map API tokens to roles for testing
61
- "api_keys": {
62
- "test-token-123": "admin",
63
- "user-token-456": "user",
64
- "readonly-token-123": "readonly",
65
- "guest-token-123": "guest",
66
- "proxy-token-123": "proxy",
67
- },
68
- },
69
- "permissions": {"enabled": True, "roles_file": roles_file},
70
- },
71
- "registration": {
72
- "enabled": True,
73
- "url": "http://127.0.0.1:3004/proxy",
74
- "name": "http_token_adapter",
75
- "capabilities": ["http", "token_auth"],
76
- "retry_count": 3,
77
- "retry_delay": 5,
78
- "heartbeat": {"enabled": True, "interval": 30},
79
- },
80
- "protocols": {"enabled": True, "allowed_protocols": ["http"]},
81
- }
82
-
83
-
84
- def generate_https_simple_config(
85
- port: int = 20002, certs_dir: str = "certs", keys_dir: str = "keys"
86
- ) -> Dict[str, Any]:
87
- """Generate HTTPS configuration without client certificate verification and authorization."""
88
- return {
89
- "uuid": str(uuid.uuid4()),
90
- "server": {"host": "127.0.0.1", "port": port},
91
- "ssl": {
92
- "enabled": True,
93
- "cert_file": f"{certs_dir}/localhost_server.crt",
94
- "key_file": f"{keys_dir}/localhost_server.key",
95
- },
96
- "security": {"enabled": False},
97
- "registration": {
98
- "enabled": True,
99
- "url": "http://127.0.0.1:3004/proxy",
100
- "name": "https_simple_adapter",
101
- "capabilities": ["https"],
102
- "retry_count": 3,
103
- "retry_delay": 5,
104
- "heartbeat": {"enabled": True, "interval": 30},
105
- },
106
- "protocols": {"enabled": True, "allowed_protocols": ["http", "https"]},
107
- }
108
-
109
-
110
- def generate_https_token_config(
111
- port: int = 20003, certs_dir: str = "certs", keys_dir: str = "keys"
112
- ) -> Dict[str, Any]:
113
- """Generate HTTPS configuration without client certificate verification with token authorization."""
114
- return {
115
- "uuid": str(uuid.uuid4()),
116
- "server": {"host": "127.0.0.1", "port": port},
117
- "ssl": {
118
- "enabled": True,
119
- "cert_file": f"{certs_dir}/localhost_server.crt",
120
- "key_file": f"{keys_dir}/localhost_server.key",
121
- },
122
- "security": {
123
- "enabled": True,
124
- "auth": {
125
- "enabled": True,
126
- "methods": ["api_key"],
127
- "api_keys": {
128
- "test-token-123": "admin",
129
- "user-token-456": "user",
130
- "readonly-token-123": "readonly",
131
- "guest-token-123": "guest",
132
- "proxy-token-123": "proxy",
133
- },
134
- },
135
- "permissions": {"enabled": True, "roles_file": "./configs/roles.json"},
136
- },
137
- "registration": {
138
- "enabled": True,
139
- "url": "http://127.0.0.1:3004/proxy",
140
- "name": "https_token_adapter",
141
- "capabilities": ["https", "token_auth"],
142
- "retry_count": 3,
143
- "retry_delay": 5,
144
- "heartbeat": {"enabled": True, "interval": 30},
145
- },
146
- "protocols": {"enabled": True, "allowed_protocols": ["http", "https"]},
147
- }
148
-
149
-
150
- def generate_mtls_no_roles_config(
151
- port: int = 20004, certs_dir: str = "certs", keys_dir: str = "keys"
152
- ) -> Dict[str, Any]:
153
- """Generate mTLS configuration without roles."""
154
- return {
155
- "uuid": str(uuid.uuid4()),
156
- "server": {"host": "127.0.0.1", "port": port},
157
- "ssl": {
158
- "enabled": True,
159
- "cert_file": f"{certs_dir}/localhost_server.crt",
160
- "key_file": f"{keys_dir}/localhost_server.key",
161
- "ca_cert": f"{certs_dir}/mcp_proxy_adapter_ca_ca.crt",
162
- "client_cert_file": f"{certs_dir}/admin_cert.pem",
163
- "client_key_file": f"{certs_dir}/admin_key.pem",
164
- "verify_client": True,
165
- "client_cert_required": True,
166
- },
167
- "security": {
168
- "enabled": True,
169
- "auth": {"enabled": True, "methods": ["certificate"]},
170
- "permissions": {"enabled": False},
171
- },
172
- "registration": {"enabled": False},
173
- "protocols": {"enabled": True, "default_protocol": "mtls", "allowed_protocols": ["https", "mtls"]},
174
- }
175
-
176
-
177
- def generate_mtls_with_roles_config(
178
- port: int = 20005,
179
- certs_dir: str = "certs",
180
- keys_dir: str = "keys",
181
- roles_file: str = "configs/roles.json",
182
- ) -> Dict[str, Any]:
183
- """Generate mTLS configuration with roles."""
184
- return {
185
- "uuid": str(uuid.uuid4()),
186
- "server": {"host": "127.0.0.1", "port": port},
187
- "ssl": {
188
- "enabled": True,
189
- "cert_file": f"{certs_dir}/localhost_server.crt",
190
- "key_file": f"{keys_dir}/localhost_server.key",
191
- "ca_cert": f"{certs_dir}/mcp_proxy_adapter_ca_ca.crt",
192
- "client_cert_file": f"{certs_dir}/admin_cert.pem",
193
- "client_key_file": f"{certs_dir}/admin_key.pem",
194
- "verify_client": True,
195
- },
196
- "registration": {
197
- "enabled": True,
198
- "auth_method": "token",
199
- "server_url": "http://127.0.0.1:3004/proxy",
200
- "token": {"enabled": True, "token": "proxy_registration_token_123"},
201
- "proxy_info": {
202
- "name": "mcp_example_server",
203
- "capabilities": ["jsonrpc", "rest", "security", "proxy_registration"],
204
- "endpoints": {
205
- "jsonrpc": "/api/jsonrpc",
206
- "rest": "/cmd",
207
- "health": "/health",
208
- },
209
- },
210
- "heartbeat": {"enabled": True, "interval": 30},
211
- },
212
- "security": {
213
- "enabled": True,
214
- "auth": {"enabled": True, "methods": ["certificate"]},
215
- "permissions": {"enabled": True, "roles_file": roles_file},
216
- },
217
- "protocols": {"enabled": True, "default_protocol": "mtls", "allowed_protocols": ["https", "mtls"]},
218
- }
219
-
220
-
221
- def generate_roles_config() -> Dict[str, Any]:
222
- """Generate roles configuration for testing."""
223
- return {
224
- "admin": {
225
- "description": "Administrator role with full access",
226
- "permissions": [
227
- "read",
228
- "write",
229
- "execute",
230
- "delete",
231
- "admin",
232
- "register",
233
- "unregister",
234
- "heartbeat",
235
- "discover",
236
- ],
237
- "tokens": ["test-token-123"],
238
- },
239
- "user": {
240
- "description": "User role with limited access",
241
- "permissions": [
242
- "read",
243
- "execute",
244
- "register",
245
- "unregister",
246
- "heartbeat",
247
- "discover",
248
- ],
249
- "tokens": ["user-token-456"],
250
- },
251
- "readonly": {
252
- "description": "Read-only role",
253
- "permissions": ["read", "discover"],
254
- "tokens": ["readonly-token-123"],
255
- },
256
- "guest": {
257
- "description": "Guest role with read-only access",
258
- "permissions": ["read", "discover"],
259
- "tokens": ["guest-token-123"],
260
- },
261
- "proxy": {
262
- "description": "Proxy role for registration",
263
- "permissions": ["register", "unregister", "heartbeat", "discover"],
264
- "tokens": ["proxy-token-123"],
265
- },
266
- }
267
-
268
-
269
- def generate_all_configs(
270
- output_dir: str,
271
- certs_dir: str = "certs",
272
- keys_dir: str = "keys",
273
- roles_file: str = "configs/roles.json",
274
- ) -> None:
275
- """Generate all 6 configuration types and save them to files."""
276
- # Ensure output directory exists first
277
- os.makedirs(output_dir, exist_ok=True)
278
-
279
- configs = {
280
- "http_simple": generate_http_simple_config(20000, certs_dir, keys_dir),
281
- "http_token": generate_http_token_config(
282
- 20001, certs_dir, keys_dir, roles_file
283
- ),
284
- "https_simple": generate_https_simple_config(20002, certs_dir, keys_dir),
285
- "https_token": generate_https_token_config(20003, certs_dir, keys_dir),
286
- "mtls_no_roles": generate_mtls_no_roles_config(20004, certs_dir, keys_dir),
287
- "mtls_with_roles": generate_mtls_with_roles_config(
288
- 20005, certs_dir, keys_dir, roles_file
289
- ),
290
- }
291
-
292
- # Generate each configuration
293
- for name, config in configs.items():
294
- filename = os.path.join(output_dir, f"{name}.json")
295
- with open(filename, "w", encoding="utf-8") as f:
296
- json.dump(config, f, indent=2, ensure_ascii=False)
297
- print(f"Generated: {filename}")
298
-
299
- # Generate roles configuration
300
- roles_config = generate_roles_config()
301
-
302
- # Create roles.json in the root directory (test environment root) for compatibility
303
- # When running as module, we need to create roles.json in the current working directory
304
- # This is the directory where the user is running the command from
305
- try:
306
- # Get the current working directory where the user is running the command
307
- current_dir = os.getcwd()
308
- root_roles_filename = os.path.join(current_dir, "roles.json")
309
-
310
- # Create roles.json in the current working directory
311
- with open(root_roles_filename, "w", encoding="utf-8") as f:
312
- json.dump(roles_config, f, indent=2, ensure_ascii=False)
313
- print(f"Generated: {root_roles_filename}")
314
-
315
- # Also create a copy in the output directory for reference
316
- backup_roles_filename = os.path.join(output_dir, "roles_backup.json")
317
- with open(backup_roles_filename, "w", encoding="utf-8") as f:
318
- json.dump(roles_config, f, indent=2, ensure_ascii=False)
319
- print(f"Generated backup: {backup_roles_filename}")
320
-
321
- except Exception as e:
322
- print(f"Warning: Could not create roles.json in current directory: {e}")
323
- print(f"Current working directory: {os.getcwd()}")
324
- print(f"Script directory: {os.path.dirname(os.path.abspath(__file__))}")
325
-
326
- # Also create roles.json in configs directory for reference
327
- roles_filename = os.path.join(output_dir, "roles.json")
328
- with open(roles_filename, "w", encoding="utf-8") as f:
329
- json.dump(roles_config, f, indent=2, ensure_ascii=False)
330
- print(f"Generated: {roles_filename}")
331
- print(
332
- f"\nGenerated {len(configs)} configuration files and roles.json in {output_dir}"
333
- )
334
-
335
- print("\n" + "=" * 60)
336
- print("✅ CONFIGURATION GENERATION COMPLETED SUCCESSFULLY")
337
- print("=" * 60)
338
- print("\n📋 NEXT STEPS:")
339
- print("1. Run security tests:")
340
- print(" python -m mcp_proxy_adapter.examples.run_security_tests")
341
- print("\n2. Start basic framework example:")
342
- print(
343
- " python -m mcp_proxy_adapter.examples.basic_framework.main --config configs/https_simple.json"
344
- )
345
- print("\n3. Start full application example:")
346
- print(
347
- " python -m mcp_proxy_adapter.examples.full_application.main --config configs/mtls_with_roles.json"
348
- )
349
- print("=" * 60)
350
-
351
-
352
- def main() -> int:
353
- """Main function for command line execution."""
354
- parser = argparse.ArgumentParser(
355
- description="Generate test configurations for MCP Proxy Adapter"
356
- )
357
- parser.add_argument(
358
- "--output-dir",
359
- default="configs",
360
- help="Output directory for configuration files (default: configs)",
361
- )
362
- parser.add_argument(
363
- "--certs-dir", default="certs", help="Certificates directory (default: certs)"
364
- )
365
- parser.add_argument(
366
- "--keys-dir", default="keys", help="Keys directory (default: keys)"
367
- )
368
- parser.add_argument(
369
- "--roles-file",
370
- default="configs/roles.json",
371
- help="Roles file path (default: configs/roles.json)",
372
- )
373
- args = parser.parse_args()
374
-
375
- try:
376
- generate_all_configs(
377
- args.output_dir, args.certs_dir, args.keys_dir, args.roles_file
378
- )
379
- print("Configuration generation completed successfully!")
380
- except Exception as e:
381
- print(f"\n❌ CONFIGURATION GENERATION FAILED: {e}")
382
- print("=" * 60)
383
- print("\n🔧 TROUBLESHOOTING:")
384
- print("1. Check if output directory is writable")
385
- print("2. Verify JSON encoding support")
386
- print("3. Check available disk space")
387
- print("=" * 60)
388
- return 1
389
- return 0
390
-
391
-
392
- if __name__ == "__main__":
393
- exit(main())