mcp-proxy-adapter 3.0.3__tar.gz → 3.1.0__tar.gz
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-3.0.3/mcp_proxy_adapter.egg-info → mcp_proxy_adapter-3.1.0}/PKG-INFO +1 -1
- mcp_proxy_adapter-3.1.0/docs/EN/development/DEPENDENCY_INJECTION.md +176 -0
- mcp_proxy_adapter-3.1.0/docs/RU/development/DEPENDENCY_INJECTION.md +176 -0
- mcp_proxy_adapter-3.1.0/examples/commands/echo_command_di.py +152 -0
- mcp_proxy_adapter-3.1.0/examples/di_example/.pytest_cache/README.md +8 -0
- mcp_proxy_adapter-3.1.0/examples/di_example/server.py +249 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/api/handlers.py +6 -3
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/commands/__init__.py +7 -4
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/commands/base.py +81 -38
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/commands/command_registry.py +67 -4
- mcp_proxy_adapter-3.1.0/mcp_proxy_adapter/commands/dependency_container.py +110 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/api/test_middleware.py +31 -27
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/test_base_command.py +7 -7
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/version.py +1 -1
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0/mcp_proxy_adapter.egg-info}/PKG-INFO +1 -1
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter.egg-info/SOURCES.txt +17 -1
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/pyproject.toml +1 -1
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/setup.py +1 -1
- mcp_proxy_adapter-3.1.0/tests/__init__.py +3 -0
- mcp_proxy_adapter-3.1.0/tests/api/__init__.py +3 -0
- mcp_proxy_adapter-3.1.0/tests/api/test_handler_dependency_injection.py +131 -0
- mcp_proxy_adapter-3.1.0/tests/commands/__init__.py +3 -0
- mcp_proxy_adapter-3.1.0/tests/commands/test_command_di.py +157 -0
- mcp_proxy_adapter-3.1.0/tests/commands/test_dependency_container.py +101 -0
- mcp_proxy_adapter-3.1.0/tests/commands/test_echo_command_di.py +118 -0
- mcp_proxy_adapter-3.1.0/tests/conftest.py +50 -0
- mcp_proxy_adapter-3.1.0/tests/integration/__init__.py +3 -0
- mcp_proxy_adapter-3.1.0/tests/integration/test_di_integration.py +226 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/LICENSE +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/MANIFEST.in +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/API_SCHEMA.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/AUTOMATED_PUBLISHING.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/BASIC_ARCHITECTURE.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/COMMAND_CHECKLIST.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/COMMAND_RESULTS.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/COMMAND_TEMPLATE.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/CONFIGURATION_PRINCIPLES.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/DOCUMENTATION_MAP.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/DOCUMENTATION_STANDARDS.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/ERROR_HANDLING.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/EXAMPLES_COMMAND_CLASSES.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/GLOSSARY.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/LOGGING_SYSTEM.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/NAMING_STANDARDS.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/OPENAPI_SCHEMA.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/PROJECT_EXTENSION_GUIDE.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/PROJECT_IDEOLOGY.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/PROJECT_RULES.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/PROJECT_STRUCTURE.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/PUBLISHING_TO_PYPI.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/api/cmd_endpoint.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/api/errors.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/api/intro.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/api/requests.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/api/responses.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/commands/get_date_command.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/commands/help_command.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/commands/index.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/commands/new_uuid4_command.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/development/COMMAND_METADATA_ENHANCEMENT.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/development/METADATA_COMMANDS.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/development/OPENAPI_CUSTOMIZATION.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/development/REMOVE_COMMAND_GUIDE.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/development/TOOL_INTEGRATION.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/development/architecture.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/examples/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/examples/anti_patterns.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/examples/basic_example.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/examples/complete_example.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/examples/minimal_example.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/testing/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/user/basic_usage.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/user/configuration.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/user/deployment.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/user/examples.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/EN/user/installation.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/API_SCHEMA.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/AUTOMATED_PUBLISHING.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/BASIC_ARCHITECTURE.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/COMMAND_CHECKLIST.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/COMMAND_RESULTS.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/COMMAND_TEMPLATE.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/CONFIGURATION_PRINCIPLES.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/DOCUMENTATION_MAP.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/DOCUMENTATION_STANDARDS.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/ERROR_HANDLING.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/EXAMPLES_COMMAND_CLASSES.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/GLOSSARY.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/LOGGING_SYSTEM.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/NAMING_STANDARDS.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/OPENAPI_SCHEMA.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/PROJECT_EXTENSION_GUIDE.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/PROJECT_IDEOLOGY.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/PROJECT_RULES.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/PROJECT_STRUCTURE.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/PUBLISHING_TO_PYPI.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/api/cmd_endpoint.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/api/errors.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/api/intro.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/api/requests.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/api/responses.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/commands/get_date_command.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/commands/help_command.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/commands/index.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/commands/new_uuid4_command.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/development/COMMAND_METADATA_ENHANCEMENT.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/development/METADATA_COMMANDS.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/development/OPENAPI_CUSTOMIZATION.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/development/PLAN_REALIZACII_METADATA.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/development/REMOVE_COMMAND_GUIDE.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/development/TOOL_INTEGRATION.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/development/architecture.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/examples/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/examples/anti_patterns.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/examples/basic_example.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/examples/complete_example.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/examples/minimal_example.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/testing/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/user/basic_usage.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/user/configuration.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/user/deployment.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/user/examples.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/docs/RU/user/installation.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/anti_patterns/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/anti_patterns/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/anti_patterns/bad_design/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/anti_patterns/bad_design/global_state.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/anti_patterns/bad_design/monolithic_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/basic_example/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/basic_example/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/basic_example/commands/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/basic_example/commands/echo_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/basic_example/commands/math_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/basic_example/commands/time_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/basic_example/config.json +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/basic_example/docs/EN/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/basic_example/docs/RU/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/basic_example/server.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/basic_example/tests/conftest.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/commands/echo_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/commands/echo_result.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/commands/get_date_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/commands/new_uuid4_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/complete_example/Dockerfile +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/complete_example/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/complete_example/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/complete_example/commands/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/complete_example/commands/system_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/complete_example/config.json +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/complete_example/configs/config.dev.yaml +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/complete_example/configs/config.docker.yaml +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/complete_example/docker-compose.yml +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/complete_example/requirements.txt +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/complete_example/server.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/minimal_example/README.md +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/minimal_example/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/minimal_example/config.json +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/minimal_example/main.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/minimal_example/simple_server.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/minimal_example/tests/conftest.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/minimal_example/tests/test_hello_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/minimal_example/tests/test_integration.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/server.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/simple_server.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/test_server.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/examples/tool_description_example.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/api/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/api/app.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/api/middleware/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/api/middleware/auth.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/api/middleware/base.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/api/middleware/error_handling.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/api/middleware/logging.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/api/middleware/performance.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/api/middleware/rate_limit.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/api/schemas.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/api/tool_integration.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/api/tools.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/commands/config_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/commands/health_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/commands/help_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/commands/result.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/config.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/core/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/core/errors.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/core/logging.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/core/utils.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/custom_openapi.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/openapi.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/py.typed +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/schemas/base_schema.json +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/schemas/openapi_schema.json +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/api/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/api/test_cmd_endpoint.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/commands/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/commands/test_config_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/commands/test_echo_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/commands/test_help_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/conftest.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/functional/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/functional/test_api.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/integration/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/integration/test_cmd_integration.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/integration/test_integration.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/performance/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/performance/test_performance.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/stubs/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/stubs/echo_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/test_api_endpoints.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/test_api_handlers.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/test_batch_requests.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/test_command_registry.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/test_config.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/test_utils.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/unit/__init__.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/unit/test_base_command.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter/tests/unit/test_config.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter.egg-info/dependency_links.txt +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter.egg-info/requires.txt +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/mcp_proxy_adapter.egg-info/top_level.txt +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/requirements.txt +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/setup.cfg +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/tests/api/test_tool_description.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/tests/commands/test_command_metadata.py +0 -0
- {mcp_proxy_adapter-3.0.3 → mcp_proxy_adapter-3.1.0}/tests/commands/test_help_command.py +0 -0
@@ -0,0 +1,176 @@
|
|
1
|
+
# Dependency Injection
|
2
|
+
|
3
|
+
MCP Proxy Adapter version 3.1.0 introduces support for Dependency Injection (DI).
|
4
|
+
This feature allows creating more flexible and testable commands that can
|
5
|
+
use shared services and resources.
|
6
|
+
|
7
|
+
## Core Concepts
|
8
|
+
|
9
|
+
**Dependency Injection (DI)** is a design pattern where an object receives its
|
10
|
+
dependencies from external sources rather than creating them itself. In the context of microservice-command-protocol:
|
11
|
+
|
12
|
+
1. **Commands** - classes that receive dependencies through their constructor
|
13
|
+
2. **Dependencies** - services, repositories, or other objects needed by commands
|
14
|
+
3. **Container** - an object for storing and managing dependencies
|
15
|
+
4. **Registration** - the process of adding a command instance to the registry
|
16
|
+
|
17
|
+
## Using DI in Commands
|
18
|
+
|
19
|
+
### 1. Creating a Command with Dependencies
|
20
|
+
|
21
|
+
```python
|
22
|
+
from mcp_proxy_adapter.commands import Command, SuccessResult
|
23
|
+
|
24
|
+
class DatabaseService:
|
25
|
+
"""Service for data operations."""
|
26
|
+
|
27
|
+
def get_data(self, key):
|
28
|
+
# ... data retrieval logic
|
29
|
+
return {"result": f"Data for {key}"}
|
30
|
+
|
31
|
+
|
32
|
+
class DataCommand(Command):
|
33
|
+
"""Command using an injected dependency."""
|
34
|
+
|
35
|
+
name = "get_data"
|
36
|
+
result_class = SuccessResult
|
37
|
+
|
38
|
+
def __init__(self, db_service: DatabaseService):
|
39
|
+
"""
|
40
|
+
Initialize command with dependencies.
|
41
|
+
|
42
|
+
Args:
|
43
|
+
db_service: Service for data operations
|
44
|
+
"""
|
45
|
+
self.db_service = db_service
|
46
|
+
|
47
|
+
async def execute(self, key: str) -> SuccessResult:
|
48
|
+
"""Execute command."""
|
49
|
+
data = self.db_service.get_data(key)
|
50
|
+
return self.result_class(**data)
|
51
|
+
```
|
52
|
+
|
53
|
+
### 2. Registering a Command with Dependencies
|
54
|
+
|
55
|
+
```python
|
56
|
+
from mcp_proxy_adapter.commands import registry, container
|
57
|
+
|
58
|
+
# Create services
|
59
|
+
db_service = DatabaseService()
|
60
|
+
|
61
|
+
# Register in container (optional)
|
62
|
+
container.register("db_service", db_service)
|
63
|
+
|
64
|
+
# Create command instance with dependencies
|
65
|
+
data_command = DataCommand(db_service)
|
66
|
+
|
67
|
+
# Register the instance
|
68
|
+
registry.register(data_command)
|
69
|
+
```
|
70
|
+
|
71
|
+
### 3. Executing the Command via API
|
72
|
+
|
73
|
+
After registering a command with dependencies, it can be called via API just like regular commands. The system will automatically find the registered command instance:
|
74
|
+
|
75
|
+
```json
|
76
|
+
{
|
77
|
+
"jsonrpc": "2.0",
|
78
|
+
"method": "get_data",
|
79
|
+
"params": {
|
80
|
+
"key": "user_123"
|
81
|
+
},
|
82
|
+
"id": 1
|
83
|
+
}
|
84
|
+
```
|
85
|
+
|
86
|
+
## Registration Types and Lifecycle Management
|
87
|
+
|
88
|
+
### 1. Command Instance Registration
|
89
|
+
|
90
|
+
```python
|
91
|
+
# Create instance
|
92
|
+
command = MyCommand(dependency)
|
93
|
+
|
94
|
+
# Register instance
|
95
|
+
registry.register(command)
|
96
|
+
```
|
97
|
+
|
98
|
+
### 2. Command Class Registration (for commands without dependencies)
|
99
|
+
|
100
|
+
```python
|
101
|
+
# Register class
|
102
|
+
registry.register(MySimpleCommand)
|
103
|
+
```
|
104
|
+
|
105
|
+
## Dependency Container
|
106
|
+
|
107
|
+
MCP Proxy Adapter includes a simple dependency container (`DependencyContainer`) that can be used for centralized dependency management:
|
108
|
+
|
109
|
+
```python
|
110
|
+
from mcp_proxy_adapter.commands import container
|
111
|
+
|
112
|
+
# Register a simple dependency
|
113
|
+
container.register("config", config_service)
|
114
|
+
|
115
|
+
# Register a factory (creates a new instance on each request)
|
116
|
+
container.register_factory("logger", lambda: create_logger())
|
117
|
+
|
118
|
+
# Register a singleton (creates instance only on first request)
|
119
|
+
container.register_singleton("db", lambda: create_db_connection())
|
120
|
+
|
121
|
+
# Get a dependency
|
122
|
+
db = container.get("db")
|
123
|
+
```
|
124
|
+
|
125
|
+
## Full Integration Example
|
126
|
+
|
127
|
+
```python
|
128
|
+
import asyncio
|
129
|
+
from mcp_proxy_adapter import create_app
|
130
|
+
from mcp_proxy_adapter.commands import registry, container
|
131
|
+
|
132
|
+
# Create services
|
133
|
+
db_service = DatabaseService("sqlite://:memory:")
|
134
|
+
config_service = ConfigService("config.json")
|
135
|
+
time_service = TimeService()
|
136
|
+
|
137
|
+
# Register in container
|
138
|
+
container.register("db", db_service)
|
139
|
+
container.register("config", config_service)
|
140
|
+
container.register("time", time_service)
|
141
|
+
|
142
|
+
# Register commands
|
143
|
+
registry.register(DataCommand(db_service, time_service))
|
144
|
+
registry.register(ConfigCommand(config_service))
|
145
|
+
registry.register(StatusCommand(db_service, config_service, time_service))
|
146
|
+
|
147
|
+
# Create FastAPI application
|
148
|
+
app = create_app()
|
149
|
+
|
150
|
+
# Run the server
|
151
|
+
if __name__ == "__main__":
|
152
|
+
import uvicorn
|
153
|
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
154
|
+
```
|
155
|
+
|
156
|
+
## DI Benefits
|
157
|
+
|
158
|
+
1. **Testability** - ability to replace real dependencies with mocks during testing
|
159
|
+
2. **Flexibility** - ability to change dependencies without modifying command code
|
160
|
+
3. **Lifecycle Management** - centralized resource management
|
161
|
+
4. **Reusability** - ability to use the same services across different commands
|
162
|
+
|
163
|
+
## Best Practices
|
164
|
+
|
165
|
+
1. **Interfaces** - define clear interfaces for services
|
166
|
+
2. **Initialization** - initialize dependencies at application startup
|
167
|
+
3. **Resource Cleanup** - add handlers for proper resource cleanup
|
168
|
+
4. **Grouping** - group logically related dependencies in a single service
|
169
|
+
|
170
|
+
## Complete Examples
|
171
|
+
|
172
|
+
Complete examples of DI usage can be found in the `examples/di_example/` directory and `examples/commands/echo_command_di.py`.
|
173
|
+
|
174
|
+
## Backward Compatibility
|
175
|
+
|
176
|
+
The DI implementation is fully backward compatible with previous library versions. Commands without dependencies will continue to work without changes.
|
@@ -0,0 +1,176 @@
|
|
1
|
+
# Внедрение зависимостей (Dependency Injection)
|
2
|
+
|
3
|
+
В версии 3.1.0 библиотеки MCP Proxy Adapter добавлена поддержка внедрения зависимостей (DI).
|
4
|
+
Эта функциональность позволяет создавать более гибкие и тестируемые команды, которые
|
5
|
+
могут использовать общие сервисы и ресурсы.
|
6
|
+
|
7
|
+
## Основные понятия
|
8
|
+
|
9
|
+
**Dependency Injection (DI)** - это паттерн проектирования, при котором объект получает свои
|
10
|
+
зависимости извне, а не создает их самостоятельно. В контексте microservice-command-protocol:
|
11
|
+
|
12
|
+
1. **Команды** - классы, которые принимают зависимости через конструктор
|
13
|
+
2. **Зависимости** - сервисы, репозитории, другие объекты, необходимые для работы команд
|
14
|
+
3. **Контейнер** - объект для хранения и управления зависимостями
|
15
|
+
4. **Регистрация** - процесс добавления экземпляра команды в реестр
|
16
|
+
|
17
|
+
## Использование DI в командах
|
18
|
+
|
19
|
+
### 1. Создание команды с зависимостями
|
20
|
+
|
21
|
+
```python
|
22
|
+
from mcp_proxy_adapter.commands import Command, SuccessResult
|
23
|
+
|
24
|
+
class DatabaseService:
|
25
|
+
"""Сервис для работы с данными."""
|
26
|
+
|
27
|
+
def get_data(self, key):
|
28
|
+
# ... логика получения данных
|
29
|
+
return {"result": f"Data for {key}"}
|
30
|
+
|
31
|
+
|
32
|
+
class DataCommand(Command):
|
33
|
+
"""Команда, использующая внедренную зависимость."""
|
34
|
+
|
35
|
+
name = "get_data"
|
36
|
+
result_class = SuccessResult
|
37
|
+
|
38
|
+
def __init__(self, db_service: DatabaseService):
|
39
|
+
"""
|
40
|
+
Инициализация команды с зависимостями.
|
41
|
+
|
42
|
+
Args:
|
43
|
+
db_service: Сервис для работы с данными
|
44
|
+
"""
|
45
|
+
self.db_service = db_service
|
46
|
+
|
47
|
+
async def execute(self, key: str) -> SuccessResult:
|
48
|
+
"""Выполнение команды."""
|
49
|
+
data = self.db_service.get_data(key)
|
50
|
+
return self.result_class(**data)
|
51
|
+
```
|
52
|
+
|
53
|
+
### 2. Регистрация команды с зависимостями
|
54
|
+
|
55
|
+
```python
|
56
|
+
from mcp_proxy_adapter.commands import registry, container
|
57
|
+
|
58
|
+
# Создание сервисов
|
59
|
+
db_service = DatabaseService()
|
60
|
+
|
61
|
+
# Регистрация в контейнере (опционально)
|
62
|
+
container.register("db_service", db_service)
|
63
|
+
|
64
|
+
# Создание экземпляра команды с зависимостями
|
65
|
+
data_command = DataCommand(db_service)
|
66
|
+
|
67
|
+
# Регистрация экземпляра
|
68
|
+
registry.register(data_command)
|
69
|
+
```
|
70
|
+
|
71
|
+
### 3. Выполнение команды через API
|
72
|
+
|
73
|
+
После регистрации команды с зависимостями, её можно вызывать через API точно так же, как и обычные команды. Система автоматически найдет зарегистрированный экземпляр команды:
|
74
|
+
|
75
|
+
```json
|
76
|
+
{
|
77
|
+
"jsonrpc": "2.0",
|
78
|
+
"method": "get_data",
|
79
|
+
"params": {
|
80
|
+
"key": "user_123"
|
81
|
+
},
|
82
|
+
"id": 1
|
83
|
+
}
|
84
|
+
```
|
85
|
+
|
86
|
+
## Типы регистрации и управление жизненным циклом
|
87
|
+
|
88
|
+
### 1. Регистрация экземпляра команды
|
89
|
+
|
90
|
+
```python
|
91
|
+
# Создание экземпляра
|
92
|
+
command = MyCommand(dependency)
|
93
|
+
|
94
|
+
# Регистрация экземпляра
|
95
|
+
registry.register(command)
|
96
|
+
```
|
97
|
+
|
98
|
+
### 2. Регистрация класса команды (для команд без зависимостей)
|
99
|
+
|
100
|
+
```python
|
101
|
+
# Регистрация класса
|
102
|
+
registry.register(MySimpleCommand)
|
103
|
+
```
|
104
|
+
|
105
|
+
## Контейнер зависимостей
|
106
|
+
|
107
|
+
MCP Proxy Adapter включает простой контейнер зависимостей (`DependencyContainer`), который можно использовать для централизованного управления зависимостями:
|
108
|
+
|
109
|
+
```python
|
110
|
+
from mcp_proxy_adapter.commands import container
|
111
|
+
|
112
|
+
# Регистрация простой зависимости
|
113
|
+
container.register("config", config_service)
|
114
|
+
|
115
|
+
# Регистрация фабрики (создает новый экземпляр при каждом запросе)
|
116
|
+
container.register_factory("logger", lambda: create_logger())
|
117
|
+
|
118
|
+
# Регистрация синглтона (создает экземпляр только при первом запросе)
|
119
|
+
container.register_singleton("db", lambda: create_db_connection())
|
120
|
+
|
121
|
+
# Получение зависимости
|
122
|
+
db = container.get("db")
|
123
|
+
```
|
124
|
+
|
125
|
+
## Пример полной интеграции
|
126
|
+
|
127
|
+
```python
|
128
|
+
import asyncio
|
129
|
+
from mcp_proxy_adapter import create_app
|
130
|
+
from mcp_proxy_adapter.commands import registry, container
|
131
|
+
|
132
|
+
# Создание сервисов
|
133
|
+
db_service = DatabaseService("sqlite://:memory:")
|
134
|
+
config_service = ConfigService("config.json")
|
135
|
+
time_service = TimeService()
|
136
|
+
|
137
|
+
# Регистрация в контейнере
|
138
|
+
container.register("db", db_service)
|
139
|
+
container.register("config", config_service)
|
140
|
+
container.register("time", time_service)
|
141
|
+
|
142
|
+
# Регистрация команд
|
143
|
+
registry.register(DataCommand(db_service, time_service))
|
144
|
+
registry.register(ConfigCommand(config_service))
|
145
|
+
registry.register(StatusCommand(db_service, config_service, time_service))
|
146
|
+
|
147
|
+
# Создание FastAPI приложения
|
148
|
+
app = create_app()
|
149
|
+
|
150
|
+
# Запуск сервера
|
151
|
+
if __name__ == "__main__":
|
152
|
+
import uvicorn
|
153
|
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
154
|
+
```
|
155
|
+
|
156
|
+
## Преимущества DI
|
157
|
+
|
158
|
+
1. **Тестируемость** - возможность подменять реальные зависимости на моки при тестировании
|
159
|
+
2. **Гибкость** - возможность изменять зависимости без изменения кода команд
|
160
|
+
3. **Управление жизненным циклом** - централизованное управление ресурсами
|
161
|
+
4. **Повторное использование** - возможность использовать одни и те же сервисы в разных командах
|
162
|
+
|
163
|
+
## Практические рекомендации
|
164
|
+
|
165
|
+
1. **Интерфейсы** - определяйте чёткие интерфейсы для сервисов
|
166
|
+
2. **Инициализация** - инициализируйте зависимости при запуске приложения
|
167
|
+
3. **Освобождение ресурсов** - добавляйте обработчики для корректного освобождения ресурсов
|
168
|
+
4. **Группировка** - группируйте логически связанные зависимости в одном сервисе
|
169
|
+
|
170
|
+
## Полные примеры
|
171
|
+
|
172
|
+
Полные примеры использования DI можно найти в директории `examples/di_example/` и `examples/commands/echo_command_di.py`.
|
173
|
+
|
174
|
+
## Совместимость с предыдущими версиями
|
175
|
+
|
176
|
+
Реализация DI полностью совместима с предыдущими версиями библиотеки. Команды без зависимостей продолжат работать без изменений.
|
@@ -0,0 +1,152 @@
|
|
1
|
+
"""
|
2
|
+
Example command with dependency injection.
|
3
|
+
|
4
|
+
This module demonstrates how to use dependency injection in commands.
|
5
|
+
"""
|
6
|
+
|
7
|
+
from typing import Any, Dict, List, Optional
|
8
|
+
|
9
|
+
from mcp_proxy_adapter.commands import Command, SuccessResult
|
10
|
+
from mcp_proxy_adapter.commands.result import CommandResult
|
11
|
+
|
12
|
+
|
13
|
+
class EchoCommandResult(SuccessResult):
|
14
|
+
"""
|
15
|
+
Result of echo command execution.
|
16
|
+
"""
|
17
|
+
|
18
|
+
def __init__(self, message: str, timestamp: str, **kwargs):
|
19
|
+
"""
|
20
|
+
Initializes echo command result.
|
21
|
+
|
22
|
+
Args:
|
23
|
+
message: Echoed message
|
24
|
+
timestamp: Time of execution
|
25
|
+
**kwargs: Additional parameters
|
26
|
+
"""
|
27
|
+
data = {"message": message, "timestamp": timestamp}
|
28
|
+
data.update(kwargs)
|
29
|
+
super().__init__(data=data, message=f"Echo response: {message}")
|
30
|
+
|
31
|
+
@classmethod
|
32
|
+
def get_schema(cls) -> Dict[str, Any]:
|
33
|
+
"""
|
34
|
+
Returns JSON schema for result validation.
|
35
|
+
|
36
|
+
Returns:
|
37
|
+
Dictionary with JSON schema
|
38
|
+
"""
|
39
|
+
return {
|
40
|
+
"type": "object",
|
41
|
+
"properties": {
|
42
|
+
"success": {"type": "boolean"},
|
43
|
+
"data": {
|
44
|
+
"type": "object",
|
45
|
+
"properties": {
|
46
|
+
"message": {"type": "string"},
|
47
|
+
"timestamp": {"type": "string", "format": "date-time"}
|
48
|
+
},
|
49
|
+
"required": ["message", "timestamp"]
|
50
|
+
},
|
51
|
+
"message": {"type": "string"}
|
52
|
+
},
|
53
|
+
"required": ["success", "data"]
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
class TimeService:
|
58
|
+
"""
|
59
|
+
Service for time-related operations.
|
60
|
+
|
61
|
+
This is a dependency that will be injected into the EchoCommand.
|
62
|
+
"""
|
63
|
+
|
64
|
+
def get_current_time(self) -> str:
|
65
|
+
"""
|
66
|
+
Get current time formatted as ISO string.
|
67
|
+
|
68
|
+
Returns:
|
69
|
+
Current time as ISO formatted string
|
70
|
+
"""
|
71
|
+
from datetime import datetime
|
72
|
+
return datetime.now().isoformat()
|
73
|
+
|
74
|
+
|
75
|
+
class EchoCommand(Command):
|
76
|
+
"""
|
77
|
+
Command that echoes back a message with timestamp.
|
78
|
+
|
79
|
+
This command demonstrates how to use dependency injection in commands
|
80
|
+
by accepting a service dependency in the constructor.
|
81
|
+
"""
|
82
|
+
|
83
|
+
# Command name for JSON-RPC endpoint
|
84
|
+
name = "echo_di"
|
85
|
+
# Command result class
|
86
|
+
result_class = EchoCommandResult
|
87
|
+
|
88
|
+
def __init__(self, time_service: TimeService):
|
89
|
+
"""
|
90
|
+
Initialize command with dependencies.
|
91
|
+
|
92
|
+
Args:
|
93
|
+
time_service: Service for getting the current time
|
94
|
+
"""
|
95
|
+
self.time_service = time_service
|
96
|
+
|
97
|
+
async def execute(self, message: str = "Hello, World!") -> CommandResult:
|
98
|
+
"""
|
99
|
+
Executes echo command.
|
100
|
+
|
101
|
+
Args:
|
102
|
+
message: Message to echo back
|
103
|
+
|
104
|
+
Returns:
|
105
|
+
Command execution result with message and timestamp
|
106
|
+
"""
|
107
|
+
timestamp = self.time_service.get_current_time()
|
108
|
+
return EchoCommandResult(message=message, timestamp=timestamp)
|
109
|
+
|
110
|
+
@classmethod
|
111
|
+
def get_schema(cls) -> Dict[str, Any]:
|
112
|
+
"""
|
113
|
+
Returns JSON schema for command parameters validation.
|
114
|
+
|
115
|
+
Returns:
|
116
|
+
Dictionary with JSON schema
|
117
|
+
"""
|
118
|
+
return {
|
119
|
+
"type": "object",
|
120
|
+
"properties": {
|
121
|
+
"message": {
|
122
|
+
"type": "string",
|
123
|
+
"description": "Message to echo back"
|
124
|
+
}
|
125
|
+
},
|
126
|
+
"additionalProperties": False
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
# Example of registering the command with dependency injection
|
131
|
+
def register_echo_command():
|
132
|
+
"""
|
133
|
+
Register echo command with dependencies.
|
134
|
+
|
135
|
+
This function shows how to:
|
136
|
+
1. Create a service dependency
|
137
|
+
2. Create a command instance with the dependency
|
138
|
+
3. Register the command instance in the registry
|
139
|
+
"""
|
140
|
+
from mcp_proxy_adapter.commands import registry, container
|
141
|
+
|
142
|
+
# Create and register service in the container
|
143
|
+
time_service = TimeService()
|
144
|
+
container.register("time_service", time_service)
|
145
|
+
|
146
|
+
# Create command with dependencies
|
147
|
+
echo_command = EchoCommand(time_service)
|
148
|
+
|
149
|
+
# Register command instance
|
150
|
+
registry.register(echo_command)
|
151
|
+
|
152
|
+
return echo_command
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# pytest cache directory #
|
2
|
+
|
3
|
+
This directory contains data from the pytest's cache plugin,
|
4
|
+
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
|
5
|
+
|
6
|
+
**Do not** commit this to version control.
|
7
|
+
|
8
|
+
See [the docs](https://docs.pytest.org/en/stable/how-to/cache.html) for more information.
|