Automatically generate well-defined MCP tools by scraping Swagger UI with swagger-mcp
swagger-mcp MCP Server?swagger-mcp is an innovative tool designed to integrate AI applications with RESTful APIs and tools through Model Context Protocol (MCP). By utilizing the Swagger UI, it extracts the swagger.json file and dynamically generates well-defined MCP tools at runtime. This server facilitates seamless communication between the MCP client and a wide array of backend services, enhancing the flexibility and adaptability of AI workflows.
swagger-mcp leverages the Model Context Protocol (MCP) to provide a standardized framework for integrating backend APIs with various AI clients. Its primary capabilities include:
The architecture of swagger-mcp is built around a modular design, ensuring that it can seamlessly integrate with different backend services. It follows the Model Context Protocol (MCP) specifications, which are designed to be universally compatible with various AI applications. The protocol flow can be illustrated through the following Mermaid diagram:
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
To ensure compatibility across different AI clients, swagger-mcp supports a wide range of MCP clients. This integration matrix highlights its support for popular AI desktop applications:
| MCP Client | Resources | Tools | Prompts |
|---|---|---|---|
| Claude Desktop | ✅ | ✅ | ✅ |
| Continue | ✅ | ✅ | ✅ |
| Cursor | ❌ | ✅ | ❌ |
To get started, simply install the swagger-mcp package using the following command:
go install github.com/hauntingsteps/swagger-mcp@latest
Alternatively, you can run it directly from the terminal with a specified Swagger API URL:
swagger-mcp --specUrl=https://your_swagger_api_docs.json
The tool supports several flags and options to customize its behavior. Key ones include:
--specUrl: Required parameter specifying the Swagger/OpenAPI JSON file URL.--sseMode: Run in SSE mode if true. Default is false; otherwise, uses stdio.--sseAddr and --sseUrl: Parameters for configuring the SSE server's address and base URL.--baseUrl, --security, --basicAuth, --bearerAuth, --apiKeyAuth: Additional options to handle API requests and authentication.The following flow diagram outlines a typical workflow when integrating swagger-mcp with an AI application:
graph TB
A[Backend Service] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
Here is a step-by-step example of integrating swagger-mcp with an AI application and backend service:
Start a Backend Service:
go install github.com/danishjsheikh/go-backend-demo@latest
go-backend-demo
Run the Ollama Model:
ollama run llama3.2
Configure and Run the MCP Client:
go install github.com/mark3labs/mcphost@latest
mcphost -m ollama:llama3.2 --config <.mcp.json_file_path>
For compatibility, swagger-mcp supports integration with various MCP clients, as demonstrated in the examples below.
To integrate swagger-mcp with an .mcp.json configuration file, use this example:
{
"mcpServers": {
"swagger_loader": {
"command": "swagger-mcp",
"args": ["--specUrl=<swagger/doc.json_url>"]
}
}
}
This setup ensures that the MCP client can connect to the backend service and utilize its tools efficiently.
The performance of swagger-mcp has been tested with various AI clients, ensuring broad compatibility. Here is a compatibility matrix highlighting supported tools:
| Tool | Resources | Tools | Prompts |
|---|---|---|---|
| API Doc Generator | ✅ | ✅ | ✅ |
| Auto-Completion Tool | ✅ | ❌ | ✅ |
swagger-mcp supports robust security measures to protect data integrity and confidentiality:
You can configure these settings via command-line options as needed.
mcphost -m ollama:llama3.2 --config <.mcp.json_file_path> --basicAuth=admin:password --bearerAuth=bearer_token_value --apiKeyAuth=header:token=abc,query:user=foo,cookie:sid=xxx
What is the difference between --sseMode and --stdio?
--sseMode enables Server Sent Events (SSE) mode for real-time updates, while --stdio uses standard input/output streams.Can I change the base URL of API requests?
--baseUrl flag: swagger-mcp --specUrl=https://example.com/swagger.json --baseUrl=http://api.example.com.How do I set up authentication for my AI application?
What tools are supported in swagger-mcp?
swagger-mcp supports a wide range of tools defined in the Swagger/OpenAPI JSON document, including security management and real-time updates.Can I use this with non-Swagger documents?
Contributions are welcome! If you wish to contribute or need help, here are some guidelines:
Your contributions will significantly improve the usability and functionality of swagger-mcp.
For more detailed resources on the Model Context Protocol (MCP) and related tools, explore these links:
By leveraging swagger-mcp, developers can build robust AI applications that seamlessly integrate with backend services through a standardized protocol.
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration