mcp-openapi-proxy 0.1.1741340797__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_openapi_proxy-0.1.1741340797/LICENSE +21 -0
- mcp_openapi_proxy-0.1.1741340797/PKG-INFO +225 -0
- mcp_openapi_proxy-0.1.1741340797/README.md +210 -0
- mcp_openapi_proxy-0.1.1741340797/mcp_openapi_proxy/__init__.py +0 -0
- mcp_openapi_proxy-0.1.1741340797/mcp_openapi_proxy/__main__.py +53 -0
- mcp_openapi_proxy-0.1.1741340797/mcp_openapi_proxy/server_fastmcp.py +250 -0
- mcp_openapi_proxy-0.1.1741340797/mcp_openapi_proxy/server_lowlevel.py +283 -0
- mcp_openapi_proxy-0.1.1741340797/mcp_openapi_proxy/utils.py +255 -0
- mcp_openapi_proxy-0.1.1741340797/mcp_openapi_proxy.egg-info/PKG-INFO +225 -0
- mcp_openapi_proxy-0.1.1741340797/mcp_openapi_proxy.egg-info/SOURCES.txt +14 -0
- mcp_openapi_proxy-0.1.1741340797/mcp_openapi_proxy.egg-info/dependency_links.txt +1 -0
- mcp_openapi_proxy-0.1.1741340797/mcp_openapi_proxy.egg-info/entry_points.txt +2 -0
- mcp_openapi_proxy-0.1.1741340797/mcp_openapi_proxy.egg-info/requires.txt +7 -0
- mcp_openapi_proxy-0.1.1741340797/mcp_openapi_proxy.egg-info/top_level.txt +1 -0
- mcp_openapi_proxy-0.1.1741340797/pyproject.toml +32 -0
- mcp_openapi_proxy-0.1.1741340797/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 mhand
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: mcp-openapi-proxy
|
|
3
|
+
Version: 0.1.1741340797
|
|
4
|
+
Summary: MCP server for exposing OpenAPI specifications as MCP tools.
|
|
5
|
+
Author-email: Matthew Hand <matthewhandau@gmail.com>
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: mcp[cli]>=1.2.0
|
|
9
|
+
Requires-Dist: python-dotenv>=1.0.1
|
|
10
|
+
Requires-Dist: requests>=2.25.0
|
|
11
|
+
Requires-Dist: fastapi>=0.100.0
|
|
12
|
+
Requires-Dist: pydantic>=2.0
|
|
13
|
+
Requires-Dist: prance>=23.6.21.0
|
|
14
|
+
Requires-Dist: openapi-spec-validator>=0.7.1
|
|
15
|
+
|
|
16
|
+
# mcp-openapi-proxy
|
|
17
|
+
|
|
18
|
+
**mcp-openapi-proxy** is a Python package implementing a Model Context Protocol (MCP) server that dynamically exposes REST APIs defined by OpenAPI specifications as MCP tools. This allows you to easily integrate any OpenAPI-described API into MCP-based workflows.
|
|
19
|
+
|
|
20
|
+
## Overview
|
|
21
|
+
|
|
22
|
+
The package supports two operation modes:
|
|
23
|
+
|
|
24
|
+
- **Low-Level Mode (Default):** Dynamically registers tools for all API endpoints defined in an OpenAPI specification eg. /chat/completions becomes chat_completions().
|
|
25
|
+
- **FastMCP Mode (Simple Mode):** Provides a simplified mode for exposing specific pre-configured API endpoints as tools ie. list_functions() and call_functions().
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- **Dynamic Tool Generation:** Automatically creates MCP tools from OpenAPI endpoint definitions.
|
|
30
|
+
- **Simple Mode Option:** Offers a static configuration option with FastMCP mode.
|
|
31
|
+
- **OpenAPI Specification Support:** Works with OpenAPI v3 specifications, and potentially v2.
|
|
32
|
+
- **Flexible Filtering:** Supports filtering endpoints by tags, paths, methods, etc. (if implemented)
|
|
33
|
+
- **MCP Integration:** Integrates seamlessly with MCP ecosystems to invoke REST APIs as tools.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
### MCP Ecosystem Integration
|
|
38
|
+
|
|
39
|
+
Add **mcp-openapi-proxy** to your MCP ecosystem by configuring your `mcpServers`. Generic example:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"mcpServers": {
|
|
44
|
+
"mcp-openapi-proxy": {
|
|
45
|
+
"command": "uvx",
|
|
46
|
+
"args": [
|
|
47
|
+
"--from",
|
|
48
|
+
"git+https://github.com/matthewhand/mcp-openapi-proxy",
|
|
49
|
+
"mcp-openapi-proxy"
|
|
50
|
+
],
|
|
51
|
+
"env": {
|
|
52
|
+
"OPENAPI_SPEC_URL": "${OPENAPI_SPEC_URL}",
|
|
53
|
+
"API_AUTH_BEARER": "",
|
|
54
|
+
"TOOL_WHITELIST": "",
|
|
55
|
+
"TOOL_NAME_PREFIX": ""
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
For examples of real world APIs like GetZep, Open-Webui, Netlify, Vercel, etc refer to [examples](./examples).
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## Modes of Operation
|
|
66
|
+
|
|
67
|
+
### FastMCP Mode (Simple Mode)
|
|
68
|
+
|
|
69
|
+
- **Enabled by:** Setting `OPENAPI_SIMPLE_MODE=true`
|
|
70
|
+
- **Description:** Exposes a pre-defined set of tools based on specific OpenAPI endpoints defined in code.
|
|
71
|
+
- **Configuration:** Requires environment variables for tool definitions.
|
|
72
|
+
|
|
73
|
+
### Low-Level Mode (Default)
|
|
74
|
+
|
|
75
|
+
- **Description:** Dynamically registers all valid API endpoints from the provided OpenAPI specification as separate tools.
|
|
76
|
+
- **Tool Naming:** Tools are named based on normalized OpenAPI path and method.
|
|
77
|
+
- **Behavior:** Descriptions are generated from the OpenAPI operation summaries and descriptions.
|
|
78
|
+
|
|
79
|
+
## Environment Variables
|
|
80
|
+
|
|
81
|
+
- `OPENAPI_SPEC_URL`: URL to the OpenAPI specification JSON file (required).
|
|
82
|
+
- `OPENAPI_LOGFILE_PATH`: (Optional) Path for the log file.
|
|
83
|
+
- `OPENAPI_SIMPLE_MODE`: (Optional) Set to `true` for FastMCP mode.
|
|
84
|
+
- `TOOL_WHITELIST`: (Optional) A prefix filter to select only certain tools.
|
|
85
|
+
- `TOOL_NAME_PREFIX`: (Optional) A string to prepend to all tool names when mapping.
|
|
86
|
+
|
|
87
|
+
## Examples
|
|
88
|
+
|
|
89
|
+
### OpenWebUI Example
|
|
90
|
+
|
|
91
|
+
**1. Confirming the OpenAPI Endpoint**
|
|
92
|
+
|
|
93
|
+
Run the following command to retrieve the OpenAPI specification:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
curl http://localhost:3000/openapi.json
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
If the output is a valid OpenAPI JSON document, it confirms that the endpoint is working correctly.
|
|
100
|
+
|
|
101
|
+
**2. Configuring mcp-openapi-proxy**
|
|
102
|
+
|
|
103
|
+
In your MCP ecosystem configuration file, set the `OPENAPI_SPEC_URL` to the above endpoint. For example:
|
|
104
|
+
|
|
105
|
+
```json
|
|
106
|
+
{
|
|
107
|
+
"mcpServers": {
|
|
108
|
+
"mcp-openapi-proxy": {
|
|
109
|
+
"command": "uvx",
|
|
110
|
+
"args": [
|
|
111
|
+
"--from",
|
|
112
|
+
"git+https://github.com/matthewhand/mcp-openapi-proxy",
|
|
113
|
+
"mcp-openapi-proxy"
|
|
114
|
+
],
|
|
115
|
+
"env": {
|
|
116
|
+
"OPENAPI_SPEC_URL": "http://localhost:3000/openapi.json",
|
|
117
|
+
"SERVER_URL_OVERRIDE": "http://localhost:3000/v1",
|
|
118
|
+
"TOOL_WHITELIST": "/models,/chat/completion",
|
|
119
|
+
"API_AUTH_BEARER": "your_openwebui_token_here"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- **OPENAPI_SPEC_URL**: The URL to the OpenAPI specification.
|
|
127
|
+
- **SERVER_URL_OVERRIDE**: Should the spec not include servers, or you wish to use a different URL.
|
|
128
|
+
- **TOOL_WHITELIST**: A comma-separated list of endpoint paths to expose as tools. In this example, only the `/api/models` and `/api/chat/completions` endpoints are allowed.
|
|
129
|
+
- **API_AUTH_BEARER**: The bearer token for endpoints requiring authentication. Alternatively use ${OPENWEBUI_API_KEY} if configured as an environment variable or stored securely in a `.env` file.
|
|
130
|
+
|
|
131
|
+
**3. Resulting Tools**
|
|
132
|
+
|
|
133
|
+
With this configuration, the MCP server will dynamically generate tools for the whitelisted endpoints. For example:
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
[
|
|
137
|
+
{
|
|
138
|
+
"name": "api_models",
|
|
139
|
+
"description": "Fetches available models from /api/models"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"name": "api_chat_completions",
|
|
143
|
+
"description": "Generates chat completions via /api/chat/completions"
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**4. Visual Verification**
|
|
149
|
+
|
|
150
|
+
You can verify the registration of these tools by inspecting the MCP server logs or using your MCP client.
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
## Fly.io Example
|
|
154
|
+
|
|
155
|
+
**1. Verify the OpenAPI Endpoint**
|
|
156
|
+
|
|
157
|
+
Run the following command to retrieve the Fly.io OpenAPI JSON specification:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
curl https://raw.githubusercontent.com/abhiaagarwal/peristera/refs/heads/main/fly-machines-gen/fixed_spec.json
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Ensure the response is a valid OpenAPI JSON document containing an "openapi" field (e.g., "openapi": "3.0.0") and defined API paths.
|
|
164
|
+
|
|
165
|
+
**2. Configure mcp-openapi-proxy for Fly.io**
|
|
166
|
+
|
|
167
|
+
Update your MCP ecosystem configuration to point to the Fly.io endpoint. For example:
|
|
168
|
+
|
|
169
|
+
```json
|
|
170
|
+
{
|
|
171
|
+
"mcpServers": {
|
|
172
|
+
"mcp-openapi-proxy": {
|
|
173
|
+
"command": "uvx",
|
|
174
|
+
"args": [
|
|
175
|
+
"--from",
|
|
176
|
+
"git+https://github.com/matthewhand/mcp-openapi-proxy",
|
|
177
|
+
"mcp-openapi-proxy"
|
|
178
|
+
],
|
|
179
|
+
"env": {
|
|
180
|
+
"OPENAPI_SPEC_URL": "https://raw.githubusercontent.com/abhiaagarwal/peristera/refs/heads/main/fly-machines-gen/fixed_spec.json",
|
|
181
|
+
"SERVER_URL_OVERRIDE": "https://api.machines.dev",
|
|
182
|
+
"TOOL_WHITELIST": "/machines/list,/machines/start,/machines/status",
|
|
183
|
+
"API_AUTH_BEARER": "${FLY_API_TOKEN}"
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**3. Resulting Tools**
|
|
191
|
+
|
|
192
|
+
With this configuration, the MCP server will dynamically generate tools for the whitelisted endpoints. For example:
|
|
193
|
+
|
|
194
|
+
```json
|
|
195
|
+
[
|
|
196
|
+
{
|
|
197
|
+
"name": "machines_list",
|
|
198
|
+
"description": "Fetches machine listing from /machines/list"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"name": "machines_start",
|
|
202
|
+
"description": "Initiates machine start via /machines/start"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"name": "machines_status",
|
|
206
|
+
"description": "Retrieves machine status from /machines/status"
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Troubleshooting
|
|
212
|
+
|
|
213
|
+
- **Missing OPENAPI_SPEC_URL:** Verify that the `OPENAPI_SPEC_URL` environment variable is set and points to a valid OpenAPI JSON file.
|
|
214
|
+
- **Invalid OpenAPI Spec:** Ensure the JSON specification complies with the OpenAPI standard.
|
|
215
|
+
- **Filtering Issues:** Check that `TOOL_WHITELIST` is correctly defined to filter the desired classes.
|
|
216
|
+
- **Logging:** Consult the logs (as defined by `MCP_OPENAPI_LOGFILE_PATH`) for debugging information.
|
|
217
|
+
- **Verify `uvx`** Run the server directly from the GitHub repository using `uvx`:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
uvx --from git+https://github.com/matthewhand/mcp-openapi-proxy mcp-openapi-proxy
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# mcp-openapi-proxy
|
|
2
|
+
|
|
3
|
+
**mcp-openapi-proxy** is a Python package implementing a Model Context Protocol (MCP) server that dynamically exposes REST APIs defined by OpenAPI specifications as MCP tools. This allows you to easily integrate any OpenAPI-described API into MCP-based workflows.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The package supports two operation modes:
|
|
8
|
+
|
|
9
|
+
- **Low-Level Mode (Default):** Dynamically registers tools for all API endpoints defined in an OpenAPI specification eg. /chat/completions becomes chat_completions().
|
|
10
|
+
- **FastMCP Mode (Simple Mode):** Provides a simplified mode for exposing specific pre-configured API endpoints as tools ie. list_functions() and call_functions().
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **Dynamic Tool Generation:** Automatically creates MCP tools from OpenAPI endpoint definitions.
|
|
15
|
+
- **Simple Mode Option:** Offers a static configuration option with FastMCP mode.
|
|
16
|
+
- **OpenAPI Specification Support:** Works with OpenAPI v3 specifications, and potentially v2.
|
|
17
|
+
- **Flexible Filtering:** Supports filtering endpoints by tags, paths, methods, etc. (if implemented)
|
|
18
|
+
- **MCP Integration:** Integrates seamlessly with MCP ecosystems to invoke REST APIs as tools.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
### MCP Ecosystem Integration
|
|
23
|
+
|
|
24
|
+
Add **mcp-openapi-proxy** to your MCP ecosystem by configuring your `mcpServers`. Generic example:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"mcpServers": {
|
|
29
|
+
"mcp-openapi-proxy": {
|
|
30
|
+
"command": "uvx",
|
|
31
|
+
"args": [
|
|
32
|
+
"--from",
|
|
33
|
+
"git+https://github.com/matthewhand/mcp-openapi-proxy",
|
|
34
|
+
"mcp-openapi-proxy"
|
|
35
|
+
],
|
|
36
|
+
"env": {
|
|
37
|
+
"OPENAPI_SPEC_URL": "${OPENAPI_SPEC_URL}",
|
|
38
|
+
"API_AUTH_BEARER": "",
|
|
39
|
+
"TOOL_WHITELIST": "",
|
|
40
|
+
"TOOL_NAME_PREFIX": ""
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
For examples of real world APIs like GetZep, Open-Webui, Netlify, Vercel, etc refer to [examples](./examples).
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Modes of Operation
|
|
51
|
+
|
|
52
|
+
### FastMCP Mode (Simple Mode)
|
|
53
|
+
|
|
54
|
+
- **Enabled by:** Setting `OPENAPI_SIMPLE_MODE=true`
|
|
55
|
+
- **Description:** Exposes a pre-defined set of tools based on specific OpenAPI endpoints defined in code.
|
|
56
|
+
- **Configuration:** Requires environment variables for tool definitions.
|
|
57
|
+
|
|
58
|
+
### Low-Level Mode (Default)
|
|
59
|
+
|
|
60
|
+
- **Description:** Dynamically registers all valid API endpoints from the provided OpenAPI specification as separate tools.
|
|
61
|
+
- **Tool Naming:** Tools are named based on normalized OpenAPI path and method.
|
|
62
|
+
- **Behavior:** Descriptions are generated from the OpenAPI operation summaries and descriptions.
|
|
63
|
+
|
|
64
|
+
## Environment Variables
|
|
65
|
+
|
|
66
|
+
- `OPENAPI_SPEC_URL`: URL to the OpenAPI specification JSON file (required).
|
|
67
|
+
- `OPENAPI_LOGFILE_PATH`: (Optional) Path for the log file.
|
|
68
|
+
- `OPENAPI_SIMPLE_MODE`: (Optional) Set to `true` for FastMCP mode.
|
|
69
|
+
- `TOOL_WHITELIST`: (Optional) A prefix filter to select only certain tools.
|
|
70
|
+
- `TOOL_NAME_PREFIX`: (Optional) A string to prepend to all tool names when mapping.
|
|
71
|
+
|
|
72
|
+
## Examples
|
|
73
|
+
|
|
74
|
+
### OpenWebUI Example
|
|
75
|
+
|
|
76
|
+
**1. Confirming the OpenAPI Endpoint**
|
|
77
|
+
|
|
78
|
+
Run the following command to retrieve the OpenAPI specification:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
curl http://localhost:3000/openapi.json
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
If the output is a valid OpenAPI JSON document, it confirms that the endpoint is working correctly.
|
|
85
|
+
|
|
86
|
+
**2. Configuring mcp-openapi-proxy**
|
|
87
|
+
|
|
88
|
+
In your MCP ecosystem configuration file, set the `OPENAPI_SPEC_URL` to the above endpoint. For example:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"mcpServers": {
|
|
93
|
+
"mcp-openapi-proxy": {
|
|
94
|
+
"command": "uvx",
|
|
95
|
+
"args": [
|
|
96
|
+
"--from",
|
|
97
|
+
"git+https://github.com/matthewhand/mcp-openapi-proxy",
|
|
98
|
+
"mcp-openapi-proxy"
|
|
99
|
+
],
|
|
100
|
+
"env": {
|
|
101
|
+
"OPENAPI_SPEC_URL": "http://localhost:3000/openapi.json",
|
|
102
|
+
"SERVER_URL_OVERRIDE": "http://localhost:3000/v1",
|
|
103
|
+
"TOOL_WHITELIST": "/models,/chat/completion",
|
|
104
|
+
"API_AUTH_BEARER": "your_openwebui_token_here"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- **OPENAPI_SPEC_URL**: The URL to the OpenAPI specification.
|
|
112
|
+
- **SERVER_URL_OVERRIDE**: Should the spec not include servers, or you wish to use a different URL.
|
|
113
|
+
- **TOOL_WHITELIST**: A comma-separated list of endpoint paths to expose as tools. In this example, only the `/api/models` and `/api/chat/completions` endpoints are allowed.
|
|
114
|
+
- **API_AUTH_BEARER**: The bearer token for endpoints requiring authentication. Alternatively use ${OPENWEBUI_API_KEY} if configured as an environment variable or stored securely in a `.env` file.
|
|
115
|
+
|
|
116
|
+
**3. Resulting Tools**
|
|
117
|
+
|
|
118
|
+
With this configuration, the MCP server will dynamically generate tools for the whitelisted endpoints. For example:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
[
|
|
122
|
+
{
|
|
123
|
+
"name": "api_models",
|
|
124
|
+
"description": "Fetches available models from /api/models"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"name": "api_chat_completions",
|
|
128
|
+
"description": "Generates chat completions via /api/chat/completions"
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**4. Visual Verification**
|
|
134
|
+
|
|
135
|
+
You can verify the registration of these tools by inspecting the MCP server logs or using your MCP client.
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
## Fly.io Example
|
|
139
|
+
|
|
140
|
+
**1. Verify the OpenAPI Endpoint**
|
|
141
|
+
|
|
142
|
+
Run the following command to retrieve the Fly.io OpenAPI JSON specification:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
curl https://raw.githubusercontent.com/abhiaagarwal/peristera/refs/heads/main/fly-machines-gen/fixed_spec.json
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Ensure the response is a valid OpenAPI JSON document containing an "openapi" field (e.g., "openapi": "3.0.0") and defined API paths.
|
|
149
|
+
|
|
150
|
+
**2. Configure mcp-openapi-proxy for Fly.io**
|
|
151
|
+
|
|
152
|
+
Update your MCP ecosystem configuration to point to the Fly.io endpoint. For example:
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"mcpServers": {
|
|
157
|
+
"mcp-openapi-proxy": {
|
|
158
|
+
"command": "uvx",
|
|
159
|
+
"args": [
|
|
160
|
+
"--from",
|
|
161
|
+
"git+https://github.com/matthewhand/mcp-openapi-proxy",
|
|
162
|
+
"mcp-openapi-proxy"
|
|
163
|
+
],
|
|
164
|
+
"env": {
|
|
165
|
+
"OPENAPI_SPEC_URL": "https://raw.githubusercontent.com/abhiaagarwal/peristera/refs/heads/main/fly-machines-gen/fixed_spec.json",
|
|
166
|
+
"SERVER_URL_OVERRIDE": "https://api.machines.dev",
|
|
167
|
+
"TOOL_WHITELIST": "/machines/list,/machines/start,/machines/status",
|
|
168
|
+
"API_AUTH_BEARER": "${FLY_API_TOKEN}"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**3. Resulting Tools**
|
|
176
|
+
|
|
177
|
+
With this configuration, the MCP server will dynamically generate tools for the whitelisted endpoints. For example:
|
|
178
|
+
|
|
179
|
+
```json
|
|
180
|
+
[
|
|
181
|
+
{
|
|
182
|
+
"name": "machines_list",
|
|
183
|
+
"description": "Fetches machine listing from /machines/list"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"name": "machines_start",
|
|
187
|
+
"description": "Initiates machine start via /machines/start"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"name": "machines_status",
|
|
191
|
+
"description": "Retrieves machine status from /machines/status"
|
|
192
|
+
}
|
|
193
|
+
]
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Troubleshooting
|
|
197
|
+
|
|
198
|
+
- **Missing OPENAPI_SPEC_URL:** Verify that the `OPENAPI_SPEC_URL` environment variable is set and points to a valid OpenAPI JSON file.
|
|
199
|
+
- **Invalid OpenAPI Spec:** Ensure the JSON specification complies with the OpenAPI standard.
|
|
200
|
+
- **Filtering Issues:** Check that `TOOL_WHITELIST` is correctly defined to filter the desired classes.
|
|
201
|
+
- **Logging:** Consult the logs (as defined by `MCP_OPENAPI_LOGFILE_PATH`) for debugging information.
|
|
202
|
+
- **Verify `uvx`** Run the server directly from the GitHub repository using `uvx`:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
uvx --from git+https://github.com/matthewhand/mcp-openapi-proxy mcp-openapi-proxy
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
File without changes
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Entry point for the mcp_openapi_proxy package.
|
|
3
|
+
|
|
4
|
+
This script determines which server to run based on the presence of
|
|
5
|
+
the OPENAPI_SIMPLE_MODE environment variable:
|
|
6
|
+
- Low-Level Server: For dynamic tool creation from OpenAPI spec.
|
|
7
|
+
- FastMCP Server: For static tool configurations defined in code.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
from dotenv import load_dotenv
|
|
13
|
+
from mcp_openapi_proxy.utils import setup_logging
|
|
14
|
+
|
|
15
|
+
# Load environment variables from .env if present
|
|
16
|
+
load_dotenv()
|
|
17
|
+
|
|
18
|
+
def main():
|
|
19
|
+
"""
|
|
20
|
+
Main entry point for the mcp_openapi_proxy package.
|
|
21
|
+
|
|
22
|
+
Depending on the OPENAPI_SIMPLE_MODE environment variable, this function
|
|
23
|
+
launches either:
|
|
24
|
+
- Low-Level Server (dynamic tools from OpenAPI spec)
|
|
25
|
+
- FastMCP Server (static tools defined in server_fastmcp.py)
|
|
26
|
+
"""
|
|
27
|
+
# Configure logging
|
|
28
|
+
DEBUG = os.getenv("DEBUG", "").lower() in ("true", "1", "yes")
|
|
29
|
+
logger = setup_logging(debug=DEBUG)
|
|
30
|
+
|
|
31
|
+
logger.debug("Starting mcp_openapi_proxy package entry point.")
|
|
32
|
+
|
|
33
|
+
# Default to Low-Level Mode unless SIMPLE_MODE is explicitly enabled
|
|
34
|
+
OPENAPI_SIMPLE_MODE = os.getenv("OPENAPI_SIMPLE_MODE", "false").lower() in ("true", "1", "yes") # Default to false, enable with "true" etc.
|
|
35
|
+
if OPENAPI_SIMPLE_MODE:
|
|
36
|
+
logger.debug("OPENAPI_SIMPLE_MODE is enabled. Launching FastMCP Server.")
|
|
37
|
+
from mcp_openapi_proxy.server_fastmcp import run_simple_server
|
|
38
|
+
selected_server = run_simple_server
|
|
39
|
+
else:
|
|
40
|
+
logger.debug("OPENAPI_SIMPLE_MODE is disabled. Launching Low-Level Server.")
|
|
41
|
+
from mcp_openapi_proxy.server_lowlevel import run_server
|
|
42
|
+
selected_server = run_server
|
|
43
|
+
|
|
44
|
+
# Run the selected server
|
|
45
|
+
try:
|
|
46
|
+
selected_server()
|
|
47
|
+
except Exception as e:
|
|
48
|
+
logger.critical("Unhandled exception occurred while running the server.", exc_info=True)
|
|
49
|
+
sys.exit(1)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
if __name__ == "__main__":
|
|
53
|
+
main()
|