awslabs.openapi-mcp-server 0.1.1__py3-none-any.whl
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.
- awslabs/__init__.py +16 -0
- awslabs/openapi_mcp_server/__init__.py +69 -0
- awslabs/openapi_mcp_server/api/__init__.py +18 -0
- awslabs/openapi_mcp_server/api/config.py +200 -0
- awslabs/openapi_mcp_server/auth/__init__.py +27 -0
- awslabs/openapi_mcp_server/auth/api_key_auth.py +185 -0
- awslabs/openapi_mcp_server/auth/auth_cache.py +190 -0
- awslabs/openapi_mcp_server/auth/auth_errors.py +206 -0
- awslabs/openapi_mcp_server/auth/auth_factory.py +146 -0
- awslabs/openapi_mcp_server/auth/auth_protocol.py +63 -0
- awslabs/openapi_mcp_server/auth/auth_provider.py +160 -0
- awslabs/openapi_mcp_server/auth/base_auth.py +218 -0
- awslabs/openapi_mcp_server/auth/basic_auth.py +171 -0
- awslabs/openapi_mcp_server/auth/bearer_auth.py +108 -0
- awslabs/openapi_mcp_server/auth/cognito_auth.py +538 -0
- awslabs/openapi_mcp_server/auth/register.py +100 -0
- awslabs/openapi_mcp_server/patch/__init__.py +17 -0
- awslabs/openapi_mcp_server/prompts/__init__.py +18 -0
- awslabs/openapi_mcp_server/prompts/generators/__init__.py +22 -0
- awslabs/openapi_mcp_server/prompts/generators/operation_prompts.py +642 -0
- awslabs/openapi_mcp_server/prompts/generators/workflow_prompts.py +257 -0
- awslabs/openapi_mcp_server/prompts/models.py +70 -0
- awslabs/openapi_mcp_server/prompts/prompt_manager.py +150 -0
- awslabs/openapi_mcp_server/server.py +511 -0
- awslabs/openapi_mcp_server/utils/__init__.py +18 -0
- awslabs/openapi_mcp_server/utils/cache_provider.py +249 -0
- awslabs/openapi_mcp_server/utils/config.py +35 -0
- awslabs/openapi_mcp_server/utils/error_handler.py +349 -0
- awslabs/openapi_mcp_server/utils/http_client.py +263 -0
- awslabs/openapi_mcp_server/utils/metrics_provider.py +503 -0
- awslabs/openapi_mcp_server/utils/openapi.py +217 -0
- awslabs/openapi_mcp_server/utils/openapi_validator.py +253 -0
- awslabs_openapi_mcp_server-0.1.1.dist-info/METADATA +418 -0
- awslabs_openapi_mcp_server-0.1.1.dist-info/RECORD +38 -0
- awslabs_openapi_mcp_server-0.1.1.dist-info/WHEEL +4 -0
- awslabs_openapi_mcp_server-0.1.1.dist-info/entry_points.txt +2 -0
- awslabs_openapi_mcp_server-0.1.1.dist-info/licenses/LICENSE +175 -0
- awslabs_openapi_mcp_server-0.1.1.dist-info/licenses/NOTICE +2 -0
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: awslabs.openapi-mcp-server
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: An AWS Labs Model Context Protocol (MCP) server for OpenAPI
|
|
5
|
+
Project-URL: Homepage, https://awslabs.github.io/mcp/
|
|
6
|
+
Project-URL: Documentation, https://awslabs.github.io/mcp/servers/openapi-mcp-server/
|
|
7
|
+
Project-URL: Source, https://github.com/awslabs/mcp.git
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/awslabs/mcp/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/awslabs/mcp/blob/main/src/openapi-mcp-server/CHANGELOG.md
|
|
10
|
+
Author: Amazon Web Services
|
|
11
|
+
Author-email: "AWSLabs Model Context Protocol (MCP)" <203918161+awslabs-mcp@users.noreply.github.com>
|
|
12
|
+
License: Apache-2.0
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
License-File: NOTICE
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: bcrypt>=4.0.0
|
|
25
|
+
Requires-Dist: boto3>=1.28.0
|
|
26
|
+
Requires-Dist: cachetools>=5.3.0
|
|
27
|
+
Requires-Dist: fastmcp>=0.1.0
|
|
28
|
+
Requires-Dist: httpx>=0.24.1
|
|
29
|
+
Requires-Dist: loguru>=0.7.0
|
|
30
|
+
Requires-Dist: openapi-spec-validator>=0.6.0
|
|
31
|
+
Requires-Dist: prance>=23.6.21.0
|
|
32
|
+
Requires-Dist: pydantic>=2.0.0
|
|
33
|
+
Requires-Dist: pyyaml>=6.0.0
|
|
34
|
+
Requires-Dist: tenacity>=8.2.0
|
|
35
|
+
Requires-Dist: typing-extensions>=4.0.0
|
|
36
|
+
Requires-Dist: uvicorn>=0.23.0
|
|
37
|
+
Provides-Extra: all
|
|
38
|
+
Requires-Dist: prometheus-client>=0.17.0; extra == 'all'
|
|
39
|
+
Requires-Dist: pyyaml>=6.0.0; extra == 'all'
|
|
40
|
+
Provides-Extra: dev
|
|
41
|
+
Requires-Dist: commitizen>=4.4.1; extra == 'dev'
|
|
42
|
+
Requires-Dist: lxml>=4.9.0; extra == 'dev'
|
|
43
|
+
Requires-Dist: pre-commit>=4.2.0; extra == 'dev'
|
|
44
|
+
Requires-Dist: pyright>=1.1.398; extra == 'dev'
|
|
45
|
+
Requires-Dist: pytest-asyncio>=0.21.1; extra == 'dev'
|
|
46
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
|
|
47
|
+
Requires-Dist: pytest>=7.4.0; extra == 'dev'
|
|
48
|
+
Requires-Dist: ruff>=0.11.2; extra == 'dev'
|
|
49
|
+
Provides-Extra: prometheus
|
|
50
|
+
Requires-Dist: prometheus-client>=0.17.0; extra == 'prometheus'
|
|
51
|
+
Provides-Extra: test
|
|
52
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'test'
|
|
53
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
|
|
54
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == 'test'
|
|
55
|
+
Requires-Dist: pytest>=7.0.0; extra == 'test'
|
|
56
|
+
Provides-Extra: yaml
|
|
57
|
+
Requires-Dist: pyyaml>=6.0.0; extra == 'yaml'
|
|
58
|
+
Description-Content-Type: text/markdown
|
|
59
|
+
|
|
60
|
+
# AWS Labs OpenAPI MCP Server
|
|
61
|
+
|
|
62
|
+
This project is a server that dynamically creates Model Context Protocol (MCP) tools and resources from OpenAPI specifications. It allows Large Language Models (LLMs) to interact with APIs through the Model Context Protocol.
|
|
63
|
+
|
|
64
|
+
## Features
|
|
65
|
+
|
|
66
|
+
- **Dynamic Tool Generation**: Automatically creates MCP tools from OpenAPI endpoints
|
|
67
|
+
- **Intelligent Route Mapping**: Maps GET operations with query parameters to TOOLS instead of RESOURCES
|
|
68
|
+
- Makes API operations with query parameters easier for LLMs to understand and use
|
|
69
|
+
- Improves usability of search and filtering endpoints
|
|
70
|
+
- Configurable via the route_patch module
|
|
71
|
+
- **Dynamic Prompt Generation**: Creates helpful prompts based on API structure
|
|
72
|
+
- **Operation-Specific Prompts**: Generates natural language prompts for each API operation
|
|
73
|
+
- **API Documentation Prompts**: Creates comprehensive API documentation prompts
|
|
74
|
+
- **Prompt Optimization**: Implements token efficiency strategies to reduce costs and enhance clarity
|
|
75
|
+
- Follows MCP-compliant structure with name, description, arguments, and metadata
|
|
76
|
+
- Achieves 70-75% reduction in token usage while maintaining functionality
|
|
77
|
+
- Uses concise descriptions with essential information for better developer experience
|
|
78
|
+
- **Transport Options**: Supports stdio transport
|
|
79
|
+
- **Flexible Configuration**: Configure via environment variables or command line arguments
|
|
80
|
+
- **OpenAPI Support**: Works with OpenAPI 3.x specifications in JSON or YAML format
|
|
81
|
+
- **OpenAPI Specification Validation**: Validates specifications without failing startup if issues detected, logging warnings instead to work with specs having minor issues or non-standard extensions
|
|
82
|
+
- **Authentication Support**: Supports multiple authentication methods (Basic, Bearer Token, API Key, Cognito)
|
|
83
|
+
- **AWS Best Practices**: Implements AWS best practices for caching, resilience, and observability
|
|
84
|
+
- **Comprehensive Testing**: Includes extensive unit and integration tests with high code coverage
|
|
85
|
+
- **Metrics Collection**: Tracks API calls, tool usage, errors, and performance metrics
|
|
86
|
+
|
|
87
|
+
## Installation
|
|
88
|
+
|
|
89
|
+
### From PyPI
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pip install "awslabs.openapi-mcp-server"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Optional Dependencies
|
|
96
|
+
|
|
97
|
+
The package supports several optional dependencies:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# For YAML OpenAPI specification support
|
|
101
|
+
pip install "awslabs.openapi-mcp-server[yaml]"
|
|
102
|
+
|
|
103
|
+
# For Prometheus metrics support
|
|
104
|
+
pip install "awslabs.openapi-mcp-server[prometheus]"
|
|
105
|
+
|
|
106
|
+
# For testing
|
|
107
|
+
pip install "awslabs.openapi-mcp-server[test]"
|
|
108
|
+
|
|
109
|
+
# For all optional dependencies
|
|
110
|
+
pip install "awslabs.openapi-mcp-server[all]"
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### From Source
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
git clone https://github.com/awslabs/mcp.git
|
|
117
|
+
cd mcp/src/openapi-mcp-server
|
|
118
|
+
pip install -e .
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Using MCP Configuration
|
|
122
|
+
|
|
123
|
+
Here are some ways you can work with MCP across AWS (e.g. for Amazon Q Developer CLI MCP, `~/.aws/amazonq/mcp.json`):
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"mcpServers": {
|
|
128
|
+
"awslabs.openapi-mcp-server": {
|
|
129
|
+
"command": "uvx",
|
|
130
|
+
"args": ["awslabs.openapi-mcp-server@latest"],
|
|
131
|
+
"env": {
|
|
132
|
+
"API_NAME": "your-api-name",
|
|
133
|
+
"API_BASE_URL": "https://api.example.com",
|
|
134
|
+
"API_SPEC_URL": "https://api.example.com/openapi.json",
|
|
135
|
+
"LOG_LEVEL": "ERROR",
|
|
136
|
+
"ENABLE_PROMETHEUS": "false",
|
|
137
|
+
"ENABLE_OPERATION_PROMPTS": "true",
|
|
138
|
+
"UVICORN_TIMEOUT_GRACEFUL_SHUTDOWN": "5.0",
|
|
139
|
+
"UVICORN_GRACEFUL_SHUTDOWN": "true"
|
|
140
|
+
},
|
|
141
|
+
"disabled": false,
|
|
142
|
+
"autoApprove": []
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Usage
|
|
149
|
+
|
|
150
|
+
### Basic Usage
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
# Start with Petstore API example
|
|
154
|
+
awslabs.openapi-mcp-server --api-name petstore --api-url https://petstore3.swagger.io/api/v3 --spec-url https://petstore3.swagger.io/api/v3/openapi.json
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Custom API
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# Use a different API
|
|
161
|
+
awslabs.openapi-mcp-server --api-name myapi --api-url https://api.example.com --spec-url https://api.example.com/openapi.json
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Authenticated API
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Basic Authentication
|
|
168
|
+
awslabs.openapi-mcp-server --api-url https://api.example.com --spec-url https://api.example.com/openapi.json --auth-type basic --auth-username YOUR_USERNAME --auth-password YOUR_PASSWORD # pragma: allowlist secret
|
|
169
|
+
|
|
170
|
+
# Bearer Token Authentication
|
|
171
|
+
awslabs.openapi-mcp-server --api-url https://api.example.com --spec-url https://api.example.com/openapi.json --auth-type bearer --auth-token YOUR_TOKEN # pragma: allowlist secret
|
|
172
|
+
|
|
173
|
+
# API Key Authentication (in header)
|
|
174
|
+
awslabs.openapi-mcp-server --api-url https://api.example.com --spec-url https://api.example.com/openapi.json --auth-type api_key --auth-api-key YOUR_API_KEY --auth-api-key-name X-API-Key --auth-api-key-in header # pragma: allowlist secret
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
For detailed information about authentication methods, configuration options, and examples, see [AUTHENTICATION.md](AUTHENTICATION.md).
|
|
178
|
+
|
|
179
|
+
### Local OpenAPI Specification
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
# Use a local OpenAPI specification file
|
|
183
|
+
awslabs.openapi-mcp-server --spec-path ./openapi.json
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### YAML OpenAPI Specification
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Use a YAML OpenAPI specification file (requires pyyaml)
|
|
190
|
+
pip install "awslabs.openapi-mcp-server[yaml]"
|
|
191
|
+
awslabs.openapi-mcp-server --spec-path ./openapi.yaml
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Local Development and Testing
|
|
195
|
+
|
|
196
|
+
For local development and testing, you can use the `uvx` command with the `--refresh` and `--from` options:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Run the server from the local directory with the Petstore API
|
|
200
|
+
uvx --refresh --from . awslabs.openapi-mcp-server --api-url https://petstore3.swagger.io/api/v3 --spec-url https://petstore3.swagger.io/api/v3/openapi.json --log-level DEBUG
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**Command Options Explained:**
|
|
204
|
+
|
|
205
|
+
- `uvx` - The uv package manager's execution tool for running Python packages
|
|
206
|
+
- `--refresh` - Refreshes the package cache to ensure the latest version is used (important during development)
|
|
207
|
+
- `--from .` - Uses the package from the current directory instead of installing from PyPI
|
|
208
|
+
- `awslabs.openapi-mcp-server` - The package name to run
|
|
209
|
+
- `--api-url` - The base URL of the API
|
|
210
|
+
- `--spec-url` - The URL of the OpenAPI specification
|
|
211
|
+
- `--log-level DEBUG` - Sets the logging level to DEBUG for more detailed logs (useful for development)
|
|
212
|
+
**When to Use These Options:**
|
|
213
|
+
|
|
214
|
+
- Use `--refresh` when you've made changes to your code and want to ensure the latest version is used
|
|
215
|
+
- Use `--log-level DEBUG` when you need detailed logs for troubleshooting or development
|
|
216
|
+
|
|
217
|
+
**Note:** The Petstore API is a standard OpenAPI schema endpoint that can be used for simple testing without any API authentication configuration. It's perfect for testing your MCP server implementation without setting up your own API.
|
|
218
|
+
|
|
219
|
+
## Configuration
|
|
220
|
+
|
|
221
|
+
### Environment Variables
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# Server configuration
|
|
225
|
+
export SERVER_NAME="My API Server"
|
|
226
|
+
export SERVER_DEBUG=true
|
|
227
|
+
export SERVER_MESSAGE_TIMEOUT=60
|
|
228
|
+
export SERVER_HOST="0.0.0.0"
|
|
229
|
+
export SERVER_PORT=8000
|
|
230
|
+
export SERVER_TRANSPORT="stdio" # Option: stdio
|
|
231
|
+
export LOG_LEVEL="INFO" # Options: DEBUG, INFO, WARNING, ERROR, CRITICAL
|
|
232
|
+
|
|
233
|
+
# Metrics and monitoring configuration
|
|
234
|
+
export ENABLE_PROMETHEUS="false" # Enable/disable Prometheus metrics (default: false)
|
|
235
|
+
export PROMETHEUS_PORT=9090 # Port for Prometheus metrics server
|
|
236
|
+
export ENABLE_OPERATION_PROMPTS="true" # Enable/disable operation-specific prompts (default: true)
|
|
237
|
+
|
|
238
|
+
# Graceful shutdown configuration
|
|
239
|
+
export UVICORN_TIMEOUT_GRACEFUL_SHUTDOWN=5.0 # Timeout for graceful shutdown in seconds
|
|
240
|
+
export UVICORN_GRACEFUL_SHUTDOWN=true # Enable/disable graceful shutdown
|
|
241
|
+
|
|
242
|
+
# API configuration
|
|
243
|
+
export API_NAME="myapi"
|
|
244
|
+
export API_BASE_URL="https://api.example.com"
|
|
245
|
+
export API_SPEC_URL="https://api.example.com/openapi.json"
|
|
246
|
+
export API_SPEC_PATH="/path/to/local/openapi.json" # Optional: local file path
|
|
247
|
+
|
|
248
|
+
# Authentication configuration
|
|
249
|
+
export AUTH_TYPE="none" # Options: none, basic, bearer, api_key
|
|
250
|
+
export AUTH_USERNAME="PLACEHOLDER_USERNAME" # For basic authentication # pragma: allowlist secret
|
|
251
|
+
export AUTH_PASSWORD="PLACEHOLDER_PASSWORD" # For basic authentication # pragma: allowlist secret
|
|
252
|
+
export AUTH_TOKEN="PLACEHOLDER_TOKEN" # For bearer token authentication # pragma: allowlist secret
|
|
253
|
+
export AUTH_API_KEY="PLACEHOLDER_API_KEY" # For API key authentication # pragma: allowlist secret
|
|
254
|
+
export AUTH_API_KEY_NAME="X-API-Key" # Name of the API key (default: api_key)
|
|
255
|
+
export AUTH_API_KEY_IN="header" # Where to place the API key (options: header, query, cookie)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Documentation
|
|
259
|
+
|
|
260
|
+
The OpenAPI MCP Server includes comprehensive documentation to help you get started and make the most of its features:
|
|
261
|
+
|
|
262
|
+
- [**AUTHENTICATION.md**](AUTHENTICATION.md): Detailed information about authentication methods, configuration options, and troubleshooting
|
|
263
|
+
- [**DEPLOYMENT.md**](DEPLOYMENT.md): Guidelines for deploying the server in various environments, including Docker and AWS
|
|
264
|
+
- [**AWS_BEST_PRACTICES.md**](AWS_BEST_PRACTICES.md): AWS best practices implemented in the server for resilience, caching, and efficiency
|
|
265
|
+
- [**OBSERVABILITY.md**](OBSERVABILITY.md): Information about metrics, logging, and monitoring capabilities
|
|
266
|
+
- [**tests/README.md**](tests/README.md): Overview of the test structure and strategy
|
|
267
|
+
|
|
268
|
+
## AWS Best Practices
|
|
269
|
+
|
|
270
|
+
The OpenAPI MCP Server implements AWS best practices for building resilient, observable, and efficient cloud applications. These include:
|
|
271
|
+
|
|
272
|
+
- **Caching**: Robust caching system with multiple backend options
|
|
273
|
+
- **Resilience**: Patterns to handle transient failures and ensure high availability
|
|
274
|
+
- **Observability**: Comprehensive monitoring, metrics, and logging features
|
|
275
|
+
|
|
276
|
+
For detailed information about these features, including implementation details and configuration options, see [AWS_BEST_PRACTICES.md](AWS_BEST_PRACTICES.md).
|
|
277
|
+
|
|
278
|
+
## Docker Deployment
|
|
279
|
+
|
|
280
|
+
The project includes a Dockerfile for containerized deployment. To build and run:
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
# Build the Docker image
|
|
284
|
+
docker build -t openapi-mcp-server:latest .
|
|
285
|
+
|
|
286
|
+
# Run with default settings
|
|
287
|
+
docker run -p 8000:8000 openapi-mcp-server:latest
|
|
288
|
+
|
|
289
|
+
# Run with custom configuration
|
|
290
|
+
docker run -p 8000:8000 \
|
|
291
|
+
-e API_NAME=myapi \
|
|
292
|
+
-e API_BASE_URL=https://api.example.com \
|
|
293
|
+
-e API_SPEC_URL=https://api.example.com/openapi.json \
|
|
294
|
+
-e SERVER_TRANSPORT=stdio \
|
|
295
|
+
-e ENABLE_PROMETHEUS=false \
|
|
296
|
+
-e ENABLE_OPERATION_PROMPTS=true \
|
|
297
|
+
-e UVICORN_TIMEOUT_GRACEFUL_SHUTDOWN=5.0 \
|
|
298
|
+
-e UVICORN_GRACEFUL_SHUTDOWN=true \
|
|
299
|
+
openapi-mcp-server:latest
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
For detailed information about Docker deployment, AWS service integration, and transport considerations, see the [DEPLOYMENT.md](DEPLOYMENT.md) file.
|
|
303
|
+
|
|
304
|
+
## Testing
|
|
305
|
+
|
|
306
|
+
The project includes a comprehensive test suite covering unit tests, integration tests, and API functionality tests.
|
|
307
|
+
|
|
308
|
+
### Running Tests
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
# Install test dependencies
|
|
312
|
+
pip install "awslabs.openapi-mcp-server[test]"
|
|
313
|
+
|
|
314
|
+
# Run all tests
|
|
315
|
+
pytest
|
|
316
|
+
|
|
317
|
+
# Run tests with coverage
|
|
318
|
+
pytest --cov=awslabs
|
|
319
|
+
|
|
320
|
+
# Run specific test modules
|
|
321
|
+
pytest tests/api/
|
|
322
|
+
pytest tests/utils/
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
The test suite covers:
|
|
326
|
+
|
|
327
|
+
1. **API Configuration**: Tests for API configuration handling and validation
|
|
328
|
+
2. **API Discovery**: Tests for API endpoint discovery and tool generation
|
|
329
|
+
3. **Caching**: Tests for the caching system and providers
|
|
330
|
+
4. **HTTP Client**: Tests for the HTTP client with resilience features
|
|
331
|
+
5. **Metrics**: Tests for metrics collection and reporting
|
|
332
|
+
6. **OpenAPI Validation**: Tests for OpenAPI specification validation
|
|
333
|
+
|
|
334
|
+
For more information about the test structure and strategy, see the [tests/README.md](tests/README.md) file.
|
|
335
|
+
|
|
336
|
+
## Instructions
|
|
337
|
+
|
|
338
|
+
This server acts as a bridge between OpenAPI specifications and LLMs, allowing models to have a better understanding of available API capabilities without requiring manual tool definitions. The server creates structured MCP tools that LLMs can use to understand and interact with your API endpoints, parameters, and response formats.
|
|
339
|
+
|
|
340
|
+
### Key Features
|
|
341
|
+
|
|
342
|
+
1. **Dynamic Tool Generation**: Automatically creates MCP tools from your API endpoints
|
|
343
|
+
2. **Operation-Specific Prompts**: Generates natural language prompts for each API operation
|
|
344
|
+
3. **API Documentation**: Creates comprehensive documentation prompts for the entire API
|
|
345
|
+
4. **Authentication Support**: Works with Basic Auth, Bearer Token, API Key, and Cognito authentication
|
|
346
|
+
|
|
347
|
+
### Getting Started
|
|
348
|
+
|
|
349
|
+
1. Point the server to your API by providing:
|
|
350
|
+
- API name
|
|
351
|
+
- API base URL
|
|
352
|
+
- OpenAPI specification URL or local file path
|
|
353
|
+
2. Set up appropriate authentication if your API requires it
|
|
354
|
+
3. Configure the stdio transport option
|
|
355
|
+
|
|
356
|
+
### Monitoring and Metrics
|
|
357
|
+
|
|
358
|
+
The server includes built-in monitoring capabilities:
|
|
359
|
+
- Prometheus metrics (disabled by default)
|
|
360
|
+
- Detailed logging of API calls and tool usage
|
|
361
|
+
- Performance tracking for API operations
|
|
362
|
+
## Testing with Amazon Q
|
|
363
|
+
|
|
364
|
+
To test the OpenAPI MCP Server with Amazon Q, you need to configure Amazon Q to use your MCP server. Here's how:
|
|
365
|
+
|
|
366
|
+
1. **Configure Amazon Q MCP Integration**
|
|
367
|
+
|
|
368
|
+
Create or edit the MCP configuration file:
|
|
369
|
+
|
|
370
|
+
```bash
|
|
371
|
+
mkdir -p ~/.aws/amazonq
|
|
372
|
+
nano ~/.aws/amazonq/mcp.json
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
Add the following configuration:
|
|
376
|
+
|
|
377
|
+
```json
|
|
378
|
+
{
|
|
379
|
+
"mcpServers": {
|
|
380
|
+
"awslabs.openapi-mcp-server": {
|
|
381
|
+
"command": "python",
|
|
382
|
+
"args": ["-m", "awslabs.openapi_mcp_server"],
|
|
383
|
+
"cwd": "/path/to/your/openapi-mcp-server",
|
|
384
|
+
"env": {
|
|
385
|
+
"API_NAME": "petstore",
|
|
386
|
+
"API_BASE_URL": "https://petstore3.swagger.io/api/v3",
|
|
387
|
+
"API_SPEC_URL": "https://petstore3.swagger.io/api/v3/openapi.json",
|
|
388
|
+
"LOG_LEVEL": "INFO",
|
|
389
|
+
"ENABLE_PROMETHEUS": "false",
|
|
390
|
+
"ENABLE_OPERATION_PROMPTS": "true",
|
|
391
|
+
"UVICORN_TIMEOUT_GRACEFUL_SHUTDOWN": "5.0",
|
|
392
|
+
"UVICORN_GRACEFUL_SHUTDOWN": "true",
|
|
393
|
+
"PYTHONPATH": "/path/to/your/openapi-mcp-server"
|
|
394
|
+
},
|
|
395
|
+
"disabled": false,
|
|
396
|
+
"autoApprove": []
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
2. **Start Amazon Q CLI**
|
|
403
|
+
|
|
404
|
+
Launch the Amazon Q CLI:
|
|
405
|
+
|
|
406
|
+
```bash
|
|
407
|
+
q chat
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
3. **Test the Operation Prompts**
|
|
411
|
+
|
|
412
|
+
Once connected, you can test the operation prompts by asking Amazon Q to help you with specific API operations:
|
|
413
|
+
|
|
414
|
+
```
|
|
415
|
+
I need to find a pet by ID using the Petstore API
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
Amazon Q should respond with guidance using the natural language prompt.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
awslabs/__init__.py,sha256=WuqxdDgUZylWNmVoPKiK7qGsTB_G4UmuXIrJ-VBwDew,731
|
|
2
|
+
awslabs/openapi_mcp_server/__init__.py,sha256=i5uLJ1Fb0BEzuqKgn9nHUp18pvRhu_OZiuerlNm-NZ0,2060
|
|
3
|
+
awslabs/openapi_mcp_server/server.py,sha256=EmCnLVJOoUAeij76F9jD3XII3N7NnYQRzsVs6avY4Gw,21389
|
|
4
|
+
awslabs/openapi_mcp_server/api/__init__.py,sha256=KWcmd1bH1vact1QJBfR0zFX7knWhFrBgaMEe9Tu9qi0,774
|
|
5
|
+
awslabs/openapi_mcp_server/api/config.py,sha256=0MptnSFtS37GzQPhbbCwWh9CeYOxAu6tlCKRsUzMwow,8404
|
|
6
|
+
awslabs/openapi_mcp_server/auth/__init__.py,sha256=wDFPpe2PmaDVvlYSdzR4saSKthgQmVPr9lwaKe3Z2RE,1109
|
|
7
|
+
awslabs/openapi_mcp_server/auth/api_key_auth.py,sha256=VfnyTaMkVOpdYDKjjjEuJ3rBOmvWAkQgmoUxNn9_ftM,7107
|
|
8
|
+
awslabs/openapi_mcp_server/auth/auth_cache.py,sha256=bCLKBD5kMcD0XwoTa3hKD9TG9rZoEYBBzK0rvaaSWZ0,5256
|
|
9
|
+
awslabs/openapi_mcp_server/auth/auth_errors.py,sha256=Nvt2s00WtTO78cR_-5zmNgU0KdUuAqgY6pU83UK006Q,6270
|
|
10
|
+
awslabs/openapi_mcp_server/auth/auth_factory.py,sha256=7TUUmUIAdLvmUxAeyV2mzoB6kvJoH2Co3cOU524-fpA,4733
|
|
11
|
+
awslabs/openapi_mcp_server/auth/auth_protocol.py,sha256=gCzQIcfhMZn05CO4ZBmUzilOY9MN4RkhlevuDb8hDdg,2141
|
|
12
|
+
awslabs/openapi_mcp_server/auth/auth_provider.py,sha256=z9OSkbxxIrOysxN4-L3D7ZLkkdyRWKS-wsmQbQOFs2I,4240
|
|
13
|
+
awslabs/openapi_mcp_server/auth/base_auth.py,sha256=9xkqh4GvQiD4jHH-_rqFa6tVOQaO_hNsEstkq0NzPMI,7021
|
|
14
|
+
awslabs/openapi_mcp_server/auth/basic_auth.py,sha256=3sdNEZYX3qnkINmpvNKWVqTx31X1eOwbWMvkQkOda2Y,6166
|
|
15
|
+
awslabs/openapi_mcp_server/auth/bearer_auth.py,sha256=KbX1GVeiI_-XNteM66jyRYilO461qXXg6mO5yyaDoG8,3769
|
|
16
|
+
awslabs/openapi_mcp_server/auth/cognito_auth.py,sha256=cBkM805xeIg_1bsNjXj4mlXmfcfQBbfFQ2lnYvPpflU,22736
|
|
17
|
+
awslabs/openapi_mcp_server/auth/register.py,sha256=p6rGLNSkbI-Y4KlSG24koMtS-4vvI_K0d5iZisVqLn0,4104
|
|
18
|
+
awslabs/openapi_mcp_server/patch/__init__.py,sha256=sks2igP1hnfrjYhQmW5e7UpOQ_ZQ_O3NK67lcQMRDa0,795
|
|
19
|
+
awslabs/openapi_mcp_server/prompts/__init__.py,sha256=exMV01HgSORPPbkPC7AZE2UqfrnK1INNW7nrv73wZ_4,783
|
|
20
|
+
awslabs/openapi_mcp_server/prompts/models.py,sha256=rExqLJWMJSYwzgXXilXZCJCHA8inrddOoW4591X2SEo,2748
|
|
21
|
+
awslabs/openapi_mcp_server/prompts/prompt_manager.py,sha256=Vmbv9nkzkAFD7y-ZIhN8WKZDHOA9ljU1mpZdflwLEYg,5700
|
|
22
|
+
awslabs/openapi_mcp_server/prompts/generators/__init__.py,sha256=rd7gP2YOqE0OFgTqlSyS9AFABh_xsT33KdbSwQ5RuMM,968
|
|
23
|
+
awslabs/openapi_mcp_server/prompts/generators/operation_prompts.py,sha256=M3UdyN3PlzGXeby-e8VwEA3H4rRLks0-OaOdn9nsyh4,25291
|
|
24
|
+
awslabs/openapi_mcp_server/prompts/generators/workflow_prompts.py,sha256=IfexW1eQseeW2SBqTPKq3GgqMKTKPtvMXQ4JR-2YdXk,10138
|
|
25
|
+
awslabs/openapi_mcp_server/utils/__init__.py,sha256=6ATm6O_0iCswDeBA2LZKwRdZVePcXrG4VxDo2YW-sK0,728
|
|
26
|
+
awslabs/openapi_mcp_server/utils/cache_provider.py,sha256=gyPOnfrc0RGf-w3e6FbinZFHPTjWmVm66FHi-TjL0Uo,8252
|
|
27
|
+
awslabs/openapi_mcp_server/utils/config.py,sha256=cRbVwP-_-t_MSUxff4HNjvu8Erc9R-_F3c42iFwKZW0,1533
|
|
28
|
+
awslabs/openapi_mcp_server/utils/error_handler.py,sha256=8phJCTVlnalsrAoZzR0LjOFTUuGSHLkBQKYuPHRYnbE,11760
|
|
29
|
+
awslabs/openapi_mcp_server/utils/http_client.py,sha256=a2wu7lfyuq1O_6ilaFQ9geFJydbfp-w1Z9J4UgpWn7s,10003
|
|
30
|
+
awslabs/openapi_mcp_server/utils/metrics_provider.py,sha256=1R__ZUxUrrB5KoKx4q6WYWHhaDTpFnr0UWTgZO28HVI,17731
|
|
31
|
+
awslabs/openapi_mcp_server/utils/openapi.py,sha256=eRQUC5AidkyR1ALQNsR0kLXlr0Mq8ZXCduLVWUXXhuA,8802
|
|
32
|
+
awslabs/openapi_mcp_server/utils/openapi_validator.py,sha256=MVJj84a8vw0BUn21pfkav6oJagDF1dSotcLK9otXzE4,9614
|
|
33
|
+
awslabs_openapi_mcp_server-0.1.1.dist-info/METADATA,sha256=8ki5RcpM4Po80PaP1L_ubxy5xrlz0-ls1kWRuihLrvQ,16496
|
|
34
|
+
awslabs_openapi_mcp_server-0.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
35
|
+
awslabs_openapi_mcp_server-0.1.1.dist-info/entry_points.txt,sha256=0BwvRNOdGm62ExFDks-9tSTWgtOdI3qmg-aemCMXQkM,86
|
|
36
|
+
awslabs_openapi_mcp_server-0.1.1.dist-info/licenses/LICENSE,sha256=CeipvOyAZxBGUsFoaFqwkx54aPnIKEtm9a5u2uXxEws,10142
|
|
37
|
+
awslabs_openapi_mcp_server-0.1.1.dist-info/licenses/NOTICE,sha256=fG29aqEG3L4KHNXheKdyD5TdsgFh7eaaFlXu-okbf5o,94
|
|
38
|
+
awslabs_openapi_mcp_server-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|