使用说明
openapi-to-mcp-generator/
├── openapi_to_mcp/ # Main Python package directory
│ ├── __init__.py # Makes the directory a package; exposes main functions
│ ├── cli.py # Command-line interface logic (e.g., using Click)
│ ├── config.py # Configuration settings (e.g., default model, prompts)
│ ├── parser.py # Logic to parse and validate the OpenAPI JSON
│ ├── generator.py # Core logic: interacts with the AI to generate code
│ ├── utils.py # Helper functions (e.g., formatting, validation)
│ └── templates/ # Directory for Jinja2 templates
│ └── mcp_server_template.py.j2 # Template for the final MCP server file
│
├── tests/ # Directory for unit and integration tests
│ ├── __init__.py
│ ├── test_parser.py
│ ├── test_generator.py
│ └── fixtures/ # Sample OpenAPI files for testing
│ └── sample_api.json
│
├── .gitignore # Files and directories to ignore in Git
├── LICENSE # Project license (e.g., MIT)
├── README.md # Project documentation
├── pyproject.toml # Modern Python packaging and project metadata file
└── requirements.txt # Project dependencies
.\venv\Scripts\activate(在命令行中激活虚拟环境)
`pip install -e .` 翻译成中文是:“使用pip以可编辑模式安装当前目录下的包”。
将 OpenAPI 转换为 MCP(微服务通信协议)生成
--input openapi.json(可翻译为:“输入文件 openapi.json”)
--output mcp_server.py(输出为 mcp_server.py)
--模型 llama3
运行 `npx @modelcontextprotocol/inspector` 并执行 `python mcp_server.py`
