We've refactored the original generator.py into a proper Python package structure while ensuring backward compatibility. This makes the code more maintainable and easier to use as a library.
-
Preserved Original Script: The original
generator.pyscript still works exactly as before. -
Same Templates Directory: The refactored code uses the exact same
/templatesdirectory, with no changes needed. -
Backward Compatible: Users can continue using the script as they always have.
-
Package Structure: Added proper Python package structure for better maintainability.
-
Docker Support: All Docker-related functionality is preserved without changes.
generator.py # Original entry point (unchanged functionality)
mcp_generator.py # Alternative entry point using modular code
openapi_mcp_generator/ # Package containing modular components
__init__.py # Package initialization
cli.py # Command-line interface
generator.py # Main generator module
generators.py # Code generators
http.py # HTTP client utilities
parser.py # OpenAPI parser
project.py # Project builder (uses templates/)
templates/ # Original templates directory (unchanged)
...
The ProjectBuilder class in project.py initializes with the path to the templates directory:
# In generator.py in the modular package
TEMPLATE_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "templates")This ensures that the modular code uses the exact same templates as the original script.
- Better Organization: Each component has a single responsibility
- Testability: Components can be tested independently
- Reusability: Functions can be imported and used programmatically
- Packageability: Can be installed as a proper Python package
You can use the refactored code in multiple ways:
- Continue using
generator.pyexactly as before - Install as a package and use the
mcp-generatorcommand - Import functions for use in your own Python code