mcp-proxy-adapter 2.1.17__py3-none-any.whl → 3.0.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.
Files changed (84) hide show
  1. examples/__init__.py +19 -0
  2. examples/anti_patterns/README.md +51 -0
  3. examples/anti_patterns/__init__.py +9 -0
  4. examples/anti_patterns/bad_design/README.md +72 -0
  5. examples/anti_patterns/bad_design/global_state.py +170 -0
  6. examples/anti_patterns/bad_design/monolithic_command.py +272 -0
  7. examples/basic_example/README.md +131 -0
  8. examples/basic_example/__init__.py +8 -0
  9. examples/basic_example/commands/__init__.py +5 -0
  10. examples/basic_example/commands/echo_command.py +95 -0
  11. examples/basic_example/commands/math_command.py +151 -0
  12. examples/basic_example/commands/time_command.py +152 -0
  13. examples/basic_example/config.json +21 -0
  14. examples/basic_example/config.yaml +20 -0
  15. examples/basic_example/docs/EN/README.md +136 -0
  16. examples/basic_example/docs/RU/README.md +136 -0
  17. examples/basic_example/main.py +50 -0
  18. examples/basic_example/server.py +45 -0
  19. examples/basic_example/tests/conftest.py +243 -0
  20. examples/commands/echo_command.py +52 -0
  21. examples/commands/echo_result.py +65 -0
  22. examples/commands/get_date_command.py +98 -0
  23. examples/commands/new_uuid4_command.py +91 -0
  24. examples/complete_example/Dockerfile +24 -0
  25. examples/complete_example/README.md +92 -0
  26. examples/complete_example/__init__.py +8 -0
  27. examples/complete_example/commands/__init__.py +5 -0
  28. examples/complete_example/commands/system_command.py +327 -0
  29. examples/complete_example/config.json +41 -0
  30. examples/complete_example/configs/config.dev.yaml +40 -0
  31. examples/complete_example/configs/config.docker.yaml +40 -0
  32. examples/complete_example/docker-compose.yml +35 -0
  33. examples/complete_example/main.py +67 -0
  34. examples/complete_example/requirements.txt +20 -0
  35. examples/complete_example/server.py +85 -0
  36. examples/minimal_example/README.md +51 -0
  37. examples/minimal_example/__init__.py +8 -0
  38. examples/minimal_example/config.json +21 -0
  39. examples/minimal_example/config.yaml +26 -0
  40. examples/minimal_example/main.py +67 -0
  41. examples/minimal_example/simple_server.py +124 -0
  42. examples/minimal_example/tests/conftest.py +171 -0
  43. examples/minimal_example/tests/test_hello_command.py +111 -0
  44. examples/minimal_example/tests/test_integration.py +183 -0
  45. examples/server.py +69 -0
  46. examples/simple_server.py +137 -0
  47. examples/test_server.py +126 -0
  48. mcp_proxy_adapter/__init__.py +33 -1
  49. mcp_proxy_adapter/config.py +186 -0
  50. mcp_proxy_adapter/custom_openapi.py +125 -0
  51. mcp_proxy_adapter/framework.py +109 -0
  52. mcp_proxy_adapter/openapi.py +403 -0
  53. mcp_proxy_adapter/version.py +3 -0
  54. mcp_proxy_adapter-3.0.0.dist-info/METADATA +200 -0
  55. mcp_proxy_adapter-3.0.0.dist-info/RECORD +58 -0
  56. {mcp_proxy_adapter-2.1.17.dist-info → mcp_proxy_adapter-3.0.0.dist-info}/top_level.txt +1 -0
  57. mcp_proxy_adapter/adapter.py +0 -697
  58. mcp_proxy_adapter/analyzers/__init__.py +0 -1
  59. mcp_proxy_adapter/analyzers/docstring_analyzer.py +0 -199
  60. mcp_proxy_adapter/analyzers/type_analyzer.py +0 -151
  61. mcp_proxy_adapter/dispatchers/__init__.py +0 -1
  62. mcp_proxy_adapter/dispatchers/base_dispatcher.py +0 -85
  63. mcp_proxy_adapter/dispatchers/json_rpc_dispatcher.py +0 -262
  64. mcp_proxy_adapter/examples/analyze_config.py +0 -141
  65. mcp_proxy_adapter/examples/basic_integration.py +0 -155
  66. mcp_proxy_adapter/examples/docstring_and_schema_example.py +0 -69
  67. mcp_proxy_adapter/examples/extension_example.py +0 -72
  68. mcp_proxy_adapter/examples/help_best_practices.py +0 -67
  69. mcp_proxy_adapter/examples/help_usage.py +0 -64
  70. mcp_proxy_adapter/examples/mcp_proxy_client.py +0 -131
  71. mcp_proxy_adapter/examples/openapi_server.py +0 -383
  72. mcp_proxy_adapter/examples/project_structure_example.py +0 -47
  73. mcp_proxy_adapter/examples/testing_example.py +0 -64
  74. mcp_proxy_adapter/models.py +0 -47
  75. mcp_proxy_adapter/registry.py +0 -439
  76. mcp_proxy_adapter/schema.py +0 -257
  77. mcp_proxy_adapter/testing_utils.py +0 -112
  78. mcp_proxy_adapter/validators/__init__.py +0 -1
  79. mcp_proxy_adapter/validators/docstring_validator.py +0 -75
  80. mcp_proxy_adapter/validators/metadata_validator.py +0 -76
  81. mcp_proxy_adapter-2.1.17.dist-info/METADATA +0 -376
  82. mcp_proxy_adapter-2.1.17.dist-info/RECORD +0 -30
  83. {mcp_proxy_adapter-2.1.17.dist-info → mcp_proxy_adapter-3.0.0.dist-info}/WHEEL +0 -0
  84. {mcp_proxy_adapter-2.1.17.dist-info → mcp_proxy_adapter-3.0.0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,327 @@
1
+ """
2
+ System information command module.
3
+
4
+ This module contains a command that returns detailed information about the system.
5
+ """
6
+
7
+ import os
8
+ import sys
9
+ import platform
10
+ import datetime
11
+ from typing import Dict, Any, Optional, List
12
+
13
+ import psutil
14
+ import pytz
15
+
16
+ from mcp_proxy_adapter import Command, SuccessResult
17
+
18
+
19
+ class SystemInfoResult(SuccessResult):
20
+ """
21
+ Result of system_info command.
22
+
23
+ Attributes:
24
+ system (dict): System information
25
+ cpu (dict): CPU information
26
+ memory (dict): Memory information
27
+ disk (dict): Disk information
28
+ python (dict): Python information
29
+ network (dict): Network information
30
+ time (dict): Time information
31
+ """
32
+
33
+ def __init__(
34
+ self,
35
+ system: Dict[str, Any],
36
+ cpu: Dict[str, Any],
37
+ memory: Dict[str, Any],
38
+ disk: Dict[str, Any],
39
+ python: Dict[str, Any],
40
+ network: Dict[str, Any],
41
+ time: Dict[str, Any]
42
+ ):
43
+ """
44
+ Initialize result.
45
+
46
+ Args:
47
+ system: System information
48
+ cpu: CPU information
49
+ memory: Memory information
50
+ disk: Disk information
51
+ python: Python information
52
+ network: Network information
53
+ time: Time information
54
+ """
55
+ self.system = system
56
+ self.cpu = cpu
57
+ self.memory = memory
58
+ self.disk = disk
59
+ self.python = python
60
+ self.network = network
61
+ self.time = time
62
+
63
+ def to_dict(self) -> Dict[str, Any]:
64
+ """
65
+ Convert result to dictionary.
66
+
67
+ Returns:
68
+ Dictionary representation
69
+ """
70
+ return {
71
+ "system": self.system,
72
+ "cpu": self.cpu,
73
+ "memory": self.memory,
74
+ "disk": self.disk,
75
+ "python": self.python,
76
+ "network": self.network,
77
+ "time": self.time
78
+ }
79
+
80
+ @classmethod
81
+ def get_schema(cls) -> Dict[str, Any]:
82
+ """
83
+ Get JSON schema for result.
84
+
85
+ Returns:
86
+ JSON schema
87
+ """
88
+ return {
89
+ "type": "object",
90
+ "properties": {
91
+ "system": {
92
+ "type": "object",
93
+ "description": "System information",
94
+ "properties": {
95
+ "platform": {"type": "string"},
96
+ "system": {"type": "string"},
97
+ "node": {"type": "string"},
98
+ "release": {"type": "string"},
99
+ "version": {"type": "string"},
100
+ "machine": {"type": "string"},
101
+ "processor": {"type": "string"},
102
+ "uptime": {"type": "number"}
103
+ }
104
+ },
105
+ "cpu": {
106
+ "type": "object",
107
+ "description": "CPU information",
108
+ "properties": {
109
+ "count_physical": {"type": "integer"},
110
+ "count_logical": {"type": "integer"},
111
+ "usage_percent": {"type": "number"},
112
+ "frequency": {"type": "object"}
113
+ }
114
+ },
115
+ "memory": {
116
+ "type": "object",
117
+ "description": "Memory information",
118
+ "properties": {
119
+ "total": {"type": "integer"},
120
+ "available": {"type": "integer"},
121
+ "used": {"type": "integer"},
122
+ "percent": {"type": "number"}
123
+ }
124
+ },
125
+ "disk": {
126
+ "type": "object",
127
+ "description": "Disk information",
128
+ "properties": {
129
+ "partitions": {"type": "array"},
130
+ "usage": {"type": "object"}
131
+ }
132
+ },
133
+ "python": {
134
+ "type": "object",
135
+ "description": "Python information",
136
+ "properties": {
137
+ "version": {"type": "string"},
138
+ "implementation": {"type": "string"},
139
+ "executable": {"type": "string"},
140
+ "packages": {"type": "array"}
141
+ }
142
+ },
143
+ "network": {
144
+ "type": "object",
145
+ "description": "Network information",
146
+ "properties": {
147
+ "interfaces": {"type": "array"},
148
+ "connections": {"type": "integer"}
149
+ }
150
+ },
151
+ "time": {
152
+ "type": "object",
153
+ "description": "Time information",
154
+ "properties": {
155
+ "current": {"type": "string"},
156
+ "utc": {"type": "string"},
157
+ "timezone": {"type": "string"},
158
+ "timestamp": {"type": "number"}
159
+ }
160
+ }
161
+ }
162
+ }
163
+
164
+
165
+ class SystemInfoCommand(Command):
166
+ """
167
+ Command that returns detailed system information.
168
+
169
+ This command demonstrates gathering and formatting complex system data.
170
+ """
171
+
172
+ name = "system_info"
173
+ result_class = SystemInfoResult
174
+
175
+ async def execute(
176
+ self,
177
+ include_python_packages: bool = False,
178
+ include_network_interfaces: bool = True
179
+ ) -> SystemInfoResult:
180
+ """
181
+ Execute command.
182
+
183
+ Args:
184
+ include_python_packages: Whether to include installed Python packages
185
+ include_network_interfaces: Whether to include network interfaces
186
+
187
+ Returns:
188
+ System information result
189
+ """
190
+ # Gather system information
191
+ system_info = {
192
+ "platform": platform.platform(),
193
+ "system": platform.system(),
194
+ "node": platform.node(),
195
+ "release": platform.release(),
196
+ "version": platform.version(),
197
+ "machine": platform.machine(),
198
+ "processor": platform.processor(),
199
+ "uptime": psutil.boot_time()
200
+ }
201
+
202
+ # CPU information
203
+ cpu_info = {
204
+ "count_physical": psutil.cpu_count(logical=False),
205
+ "count_logical": psutil.cpu_count(logical=True),
206
+ "usage_percent": psutil.cpu_percent(interval=0.1),
207
+ "frequency": {
208
+ "current": psutil.cpu_freq().current if psutil.cpu_freq() else 0,
209
+ "min": psutil.cpu_freq().min if psutil.cpu_freq() and psutil.cpu_freq().min else 0,
210
+ "max": psutil.cpu_freq().max if psutil.cpu_freq() and psutil.cpu_freq().max else 0
211
+ }
212
+ }
213
+
214
+ # Memory information
215
+ memory = psutil.virtual_memory()
216
+ memory_info = {
217
+ "total": memory.total,
218
+ "available": memory.available,
219
+ "used": memory.used,
220
+ "percent": memory.percent
221
+ }
222
+
223
+ # Disk information
224
+ disk_info = {
225
+ "partitions": [],
226
+ "usage": {}
227
+ }
228
+
229
+ for partition in psutil.disk_partitions():
230
+ try:
231
+ usage = psutil.disk_usage(partition.mountpoint)
232
+ disk_info["partitions"].append({
233
+ "device": partition.device,
234
+ "mountpoint": partition.mountpoint,
235
+ "fstype": partition.fstype,
236
+ "opts": partition.opts
237
+ })
238
+ disk_info["usage"][partition.mountpoint] = {
239
+ "total": usage.total,
240
+ "used": usage.used,
241
+ "free": usage.free,
242
+ "percent": usage.percent
243
+ }
244
+ except (PermissionError, FileNotFoundError):
245
+ # Some mountpoints may not be accessible
246
+ pass
247
+
248
+ # Python information
249
+ python_info = {
250
+ "version": platform.python_version(),
251
+ "implementation": platform.python_implementation(),
252
+ "executable": sys.executable,
253
+ "packages": []
254
+ }
255
+
256
+ if include_python_packages:
257
+ try:
258
+ import pkg_resources
259
+ python_info["packages"] = [
260
+ {"name": pkg.key, "version": pkg.version}
261
+ for pkg in pkg_resources.working_set
262
+ ]
263
+ except ImportError:
264
+ pass
265
+
266
+ # Network information
267
+ network_info = {
268
+ "interfaces": [],
269
+ "connections": len(psutil.net_connections())
270
+ }
271
+
272
+ if include_network_interfaces:
273
+ for interface, addresses in psutil.net_if_addrs().items():
274
+ for address in addresses:
275
+ if address.family == socket.AF_INET: # IPv4
276
+ network_info["interfaces"].append({
277
+ "interface": interface,
278
+ "address": address.address,
279
+ "netmask": address.netmask,
280
+ "broadcast": address.broadcast
281
+ })
282
+
283
+ # Time information
284
+ now = datetime.datetime.now()
285
+ utc_now = datetime.datetime.now(pytz.UTC)
286
+
287
+ time_info = {
288
+ "current": now.isoformat(),
289
+ "utc": utc_now.isoformat(),
290
+ "timezone": str(datetime.datetime.now().astimezone().tzinfo),
291
+ "timestamp": now.timestamp()
292
+ }
293
+
294
+ return SystemInfoResult(
295
+ system=system_info,
296
+ cpu=cpu_info,
297
+ memory=memory_info,
298
+ disk=disk_info,
299
+ python=python_info,
300
+ network=network_info,
301
+ time=time_info
302
+ )
303
+
304
+ @classmethod
305
+ def get_schema(cls) -> Dict[str, Any]:
306
+ """
307
+ Get JSON schema for command parameters.
308
+
309
+ Returns:
310
+ JSON schema
311
+ """
312
+ return {
313
+ "type": "object",
314
+ "properties": {
315
+ "include_python_packages": {
316
+ "type": "boolean",
317
+ "description": "Whether to include installed Python packages",
318
+ "default": False
319
+ },
320
+ "include_network_interfaces": {
321
+ "type": "boolean",
322
+ "description": "Whether to include network interfaces",
323
+ "default": True
324
+ }
325
+ },
326
+ "additionalProperties": False
327
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "service": {
3
+ "name": "Complete Example",
4
+ "version": "1.0.0",
5
+ "description": "Полный пример MCP Proxy Adapter"
6
+ },
7
+ "server": {
8
+ "host": "0.0.0.0",
9
+ "port": 8000,
10
+ "debug": false,
11
+ "log_level": "info",
12
+ "workers": 4
13
+ },
14
+ "logging": {
15
+ "level": "INFO",
16
+ "file": "logs/complete_example.log",
17
+ "rotation": {
18
+ "type": "time",
19
+ "when": "D",
20
+ "interval": 1,
21
+ "backup_count": 30
22
+ }
23
+ },
24
+ "auth": {
25
+ "enabled": false,
26
+ "token_expiration": 3600,
27
+ "secret_key": "change_this_to_a_secure_key_in_production"
28
+ },
29
+ "database": {
30
+ "url": "sqlite:///./data/database.db",
31
+ "echo": false,
32
+ "pool_size": 5,
33
+ "max_overflow": 10
34
+ },
35
+ "cache": {
36
+ "enabled": true,
37
+ "ttl": 300,
38
+ "type": "memory",
39
+ "max_size": 1000
40
+ }
41
+ }
@@ -0,0 +1,40 @@
1
+ # Development configuration for complete MCP Microservice example
2
+
3
+ # Server settings
4
+ server:
5
+ host: "localhost" # Host to bind server
6
+ port: 8000 # Port to bind server
7
+ workers: 1 # Number of worker processes
8
+ debug: true # Enable debug mode
9
+
10
+ # Logging settings
11
+ logging:
12
+ level: "DEBUG" # Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
13
+ file: "logs/complete_example.log" # Log file path
14
+ rotation:
15
+ type: "size" # Log rotation type (size, time)
16
+ max_bytes: 10485760 # Maximum log file size (10 MB)
17
+ backup_count: 5 # Number of backup files
18
+
19
+ # Command discovery settings
20
+ discovery:
21
+ enabled: true
22
+ package: "commands" # Package to discover commands
23
+
24
+ # Cache settings
25
+ cache:
26
+ enabled: true
27
+ type: "file" # Cache type (file, memory, redis)
28
+ path: "cache" # Cache directory
29
+ ttl: 300 # Default TTL in seconds
30
+
31
+ # Database settings (for db_command)
32
+ database:
33
+ enabled: false # Database is disabled in development
34
+ type: "sqlite" # Database type
35
+ path: ":memory:" # Database path (in-memory SQLite)
36
+
37
+ # File operations settings (for file_command)
38
+ files:
39
+ base_path: "." # Base path for file operations
40
+ allowed_extensions: [".txt", ".log", ".json", ".yaml"] # Allowed file extensions
@@ -0,0 +1,40 @@
1
+ # Docker configuration for complete MCP Microservice example
2
+
3
+ # Server settings
4
+ server:
5
+ host: "0.0.0.0" # Bind to all interfaces in Docker
6
+ port: 8000 # Port to bind server
7
+ workers: 2 # Number of worker processes
8
+ debug: false # Disable debug mode in production
9
+
10
+ # Logging settings
11
+ logging:
12
+ level: "INFO" # Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
13
+ file: "/app/logs/complete_example.log" # Log file path in Docker container
14
+ rotation:
15
+ type: "size" # Log rotation type (size, time)
16
+ max_bytes: 10485760 # Maximum log file size (10 MB)
17
+ backup_count: 10 # Number of backup files
18
+
19
+ # Command discovery settings
20
+ discovery:
21
+ enabled: true
22
+ package: "commands" # Package to discover commands
23
+
24
+ # Cache settings
25
+ cache:
26
+ enabled: true
27
+ type: "file" # Cache type (file, memory, redis)
28
+ path: "/app/cache" # Cache directory in Docker container
29
+ ttl: 3600 # Default TTL in seconds (1 hour)
30
+
31
+ # Database settings (for db_command)
32
+ database:
33
+ enabled: true # Enable database in Docker environment
34
+ type: "sqlite" # Database type
35
+ path: "/app/data/db.sqlite" # Database path in Docker container
36
+
37
+ # File operations settings (for file_command)
38
+ files:
39
+ base_path: "/app/data" # Base path for file operations in Docker
40
+ allowed_extensions: [".txt", ".log", ".json", ".yaml"] # Allowed file extensions
@@ -0,0 +1,35 @@
1
+ version: '3.8'
2
+
3
+ services:
4
+ mcp-proxy-adapter:
5
+ build:
6
+ context: .
7
+ dockerfile: Dockerfile
8
+ image: mcp-proxy-adapter-example:latest
9
+ container_name: mcp-proxy-adapter-example
10
+ restart: unless-stopped
11
+ ports:
12
+ - "8000:8000"
13
+ volumes:
14
+ # Mount configuration, logs, and cache from host
15
+ - ./configs:/app/configs:ro
16
+ - ./logs:/app/logs
17
+ - ./cache:/app/cache
18
+ - ./data:/app/data
19
+ environment:
20
+ - PYTHONUNBUFFERED=1
21
+ - CONFIG_PATH=/app/configs/config.docker.yaml
22
+ networks:
23
+ - smart-assistant
24
+ user: "${UID:-1000}:${GID:-1000}" # Use host user ID to avoid permission issues
25
+ healthcheck:
26
+ test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
27
+ interval: 30s
28
+ timeout: 10s
29
+ retries: 3
30
+ start_period: 10s
31
+
32
+ networks:
33
+ smart-assistant:
34
+ # Use external network if it exists, otherwise create it
35
+ external: true
@@ -0,0 +1,67 @@
1
+ """
2
+ Main application module.
3
+ """
4
+
5
+ import os
6
+ import sys
7
+ import uvicorn
8
+ import logging
9
+
10
+ from mcp_proxy_adapter.api.app import app
11
+ from mcp_proxy_adapter.config import config
12
+ from mcp_proxy_adapter.core.logging import logger, setup_logging
13
+
14
+
15
+ def main():
16
+ """
17
+ Main function to run the application.
18
+ """
19
+ # Убедимся что логирование настроено
20
+ logger.info("Initializing logging configuration")
21
+
22
+ try:
23
+ # Получаем настройки логирования
24
+ log_level = config.get("logging.level", "INFO")
25
+ log_file = config.get("logging.file")
26
+ rotation_type = config.get("logging.rotation.type", "size")
27
+
28
+ # Выводим информацию о настройках логирования
29
+ logger.info(f"Log level: {log_level}")
30
+ if log_file:
31
+ logger.info(f"Log file: {log_file}")
32
+ logger.info(f"Log rotation type: {rotation_type}")
33
+
34
+ if rotation_type.lower() == "time":
35
+ when = config.get("logging.rotation.when", "D")
36
+ interval = config.get("logging.rotation.interval", 1)
37
+ logger.info(f"Log rotation: every {interval} {when}")
38
+ else:
39
+ max_bytes = config.get("logging.rotation.max_bytes", 10 * 1024 * 1024)
40
+ logger.info(f"Log rotation: when size reaches {max_bytes / (1024*1024):.1f} MB")
41
+
42
+ backup_count = config.get("logging.rotation.backup_count", 5)
43
+ logger.info(f"Log backups: {backup_count}")
44
+ else:
45
+ logger.info("File logging is disabled")
46
+
47
+ # Get server settings
48
+ host = config.get("server.host", "0.0.0.0")
49
+ port = config.get("server.port", 8000)
50
+
51
+ logger.info(f"Starting server on {host}:{port}")
52
+
53
+ # Run server
54
+ uvicorn.run(
55
+ app,
56
+ host=host,
57
+ port=port,
58
+ reload=True if os.environ.get("DEBUG") else False,
59
+ log_level=log_level.lower()
60
+ )
61
+ except Exception as e:
62
+ logger.exception(f"Error during application startup: {e}")
63
+ sys.exit(1)
64
+
65
+
66
+ if __name__ == "__main__":
67
+ main()
@@ -0,0 +1,20 @@
1
+ # Python dependencies for MCP Microservice complete example
2
+
3
+ # Core dependencies
4
+ fastapi>=0.95.0,<1.0.0
5
+ pydantic>=2.0.0,<3.0.0
6
+ uvicorn>=0.22.0,<1.0.0
7
+ docstring-parser>=0.15,<1.0.0
8
+ typing-extensions>=4.5.0,<5.0.0
9
+ jsonrpc>=1.2.0,<2.0.0
10
+
11
+ # For system_command
12
+ psutil>=5.9.0,<6.0.0
13
+ pytz>=2023.3
14
+
15
+ # For file_command
16
+ aiofiles>=23.1.0,<24.0.0
17
+
18
+ # For db_command
19
+ aiosqlite>=0.17.0,<1.0.0
20
+ SQLAlchemy>=2.0.0,<3.0.0
@@ -0,0 +1,85 @@
1
+ """
2
+ Complete MCP Microservice example.
3
+
4
+ This example demonstrates a complete microservice application with Docker support,
5
+ environment-specific configuration, and multiple commands.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ import argparse
11
+ from typing import Dict, Any
12
+
13
+ import mcp_proxy_adapter as mcp
14
+ from mcp_proxy_adapter import MicroService
15
+
16
+ # Add commands directory to path for local imports
17
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
18
+
19
+
20
+ def parse_args():
21
+ """
22
+ Parse command line arguments.
23
+
24
+ Returns:
25
+ Parsed arguments
26
+ """
27
+ parser = argparse.ArgumentParser(description="MCP Microservice Example")
28
+ parser.add_argument(
29
+ "--config",
30
+ default="configs/config.dev.yaml",
31
+ help="Path to configuration file"
32
+ )
33
+ return parser.parse_args()
34
+
35
+
36
+ def ensure_directories(config_path: str):
37
+ """
38
+ Create necessary directories based on configuration.
39
+
40
+ Args:
41
+ config_path: Path to configuration file
42
+ """
43
+ # Extract base directory
44
+ base_dir = os.path.dirname(os.path.abspath(__file__))
45
+
46
+ # Create logs directory
47
+ os.makedirs(os.path.join(base_dir, "logs"), exist_ok=True)
48
+
49
+ # Create cache directory
50
+ os.makedirs(os.path.join(base_dir, "cache"), exist_ok=True)
51
+
52
+ # Create data directory
53
+ os.makedirs(os.path.join(base_dir, "data"), exist_ok=True)
54
+
55
+
56
+ def main():
57
+ """Run microservice with command discovery."""
58
+ # Parse command line arguments
59
+ args = parse_args()
60
+
61
+ # Get absolute path to config file
62
+ current_dir = os.path.dirname(os.path.abspath(__file__))
63
+ config_path = os.path.join(current_dir, args.config)
64
+
65
+ # Create necessary directories
66
+ ensure_directories(config_path)
67
+
68
+ # Create microservice
69
+ service = MicroService(
70
+ title="Complete MCP Microservice Example",
71
+ description="Full-featured microservice with Docker support",
72
+ version="1.0.0",
73
+ config_path=config_path
74
+ )
75
+
76
+ # Discover and register commands
77
+ package_path = "commands"
78
+ service.discover_commands(package_path)
79
+
80
+ # Run server with parameters from configuration
81
+ service.run()
82
+
83
+
84
+ if __name__ == "__main__":
85
+ main()