API2MCP (formerly Jule) is a powerful Streamlit application that automatically converts OpenAPI (Swagger) specifications into ready-to-use Model Context Protocol (MCP) servers. This tool bridges the gap between existing REST APIs and AI agents, allowing you to quickly expose your API endpoints as tools for LLMs.
- Universal Parsing: Supports both JSON and YAML OpenAPI specifications.
- Smart Reference Resolution: Automatically handles
$refin OpenAPI specs to ensure all schemas are correctly resolved. - Interactive Selection: specific endpoints to expose as tools via a user-friendly interface.
- Automated Code Generation: Produces a complete, standalone Python server file (
server.py) using thefastmcplibrary. - Type Safety: Maps OpenAPI types to Python types for robust tool definitions.
-
Clone the repository:
git clone https://github.com/aruncs78/API2MCP.git cd API2MCP -
Install dependencies:
pip install -r requirements.txt
-
Run the Streamlit app:
streamlit run app.py
-
Upload OpenAPI Spec: Upload your
openapi.jsonoropenapi.yamlfile. -
Configure: Set the Base URL for your API and the environment variable name for your API Key.
-
Select Tools: Choose which API endpoints you want to expose as MCP tools.
-
Generate & Download: Click "Generate Server Code" to preview the code, then download
server.pyandrequirements.txt.
The main entry point for the Streamlit application.
- Functionality: Handles file upload, UI rendering, user input collection (Base URL, API Key Env), and triggers the parsing and generation logic.
Handles the parsing and normalization of OpenAPI specifications.
-
clean_identifier(name)- Description: Sanitizes a string to ensure it is a valid Python identifier. Replaces invalid characters with underscores and handles Python keywords.
- Args:
name(str) - The string to sanitize. - Returns:
str- A valid Python identifier.
-
parse_openapi(spec_content)- Description: The core parsing logic. Takes raw OpenAPI content (JSON string or dict), resolves references using
jsonref, and extracts a list of valid tool definitions. - Args:
spec_content(str | dict) - The OpenAPI content. - Returns:
tuple(list, str)- A list of parsed tool dictionaries and the default base URL found in the spec.
- Description: The core parsing logic. Takes raw OpenAPI content (JSON string or dict), resolves references using
-
map_type(openapi_type)- Description: Maps OpenAPI data types (e.g., 'integer', 'string') to Python types (e.g., 'int', 'str').
- Args:
openapi_type(str) - The OpenAPI type string. - Returns:
str- The corresponding Python type.
Generates the Python code for the FastMCP server.
generate_mcp_server(parsed_spec, selected_tool_names, base_url, api_key_env_var="API_KEY")- Description: Uses
jinja2templates to construct the finalserver.pyfile. It iterates through selected tools, creates function signatures with type hints, and generates the implementation logic to call the actual API. - Args:
parsed_spec: List of tools fromparser.py.selected_tool_names: List of tool names selected by the user.base_url: The base URL for the API calls.api_key_env_var: Name of the environment variable for the API key.
- Returns:
str- The complete source code for the generated MCP server.
- Description: Uses
The output file is a standalone Python script that:
- Initializes a
FastMCPserver. - Reads the API Key from the specified environment variable.
- Defines tool functions decorated with
@mcp.tool(). - Uses
httpxto make authenticated HTTP requests to the target API.
- Python 3.10+
streamlitfastmcphttpxpyyamljinja2jsonref
MIT