|
1 | | -# tadata-python-sdk |
| 1 | +# Tadata Python SDK |
| 2 | + |
| 3 | +The Tadata Python SDK provides an easy-to-use interface for deploying Model Context Protocol (MCP) servers from OpenAPI specifications. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +# Install with pip |
| 9 | +pip install tadata-sdk |
| 10 | + |
| 11 | +# Or with uv (recommended) |
| 12 | +uv pip install tadata-sdk |
| 13 | +``` |
| 14 | + |
| 15 | +## Quickstart |
| 16 | + |
| 17 | +Deploy a Model Context Protocol (MCP) server with your OpenAPI specification: |
| 18 | + |
| 19 | +```python |
| 20 | +from tadata_sdk import deploy, OpenAPISpec |
| 21 | + |
| 22 | +# Deploy from a dictionary |
| 23 | +result = deploy( |
| 24 | + openapi_spec={ |
| 25 | + "openapi": "3.0.0", |
| 26 | + "info": {"title": "My API", "version": "1.0.0"}, |
| 27 | + "paths": {"/hello": {"get": {"responses": {"200": {"description": "OK"}}}}}, |
| 28 | + }, |
| 29 | + api_key="your-tadata-api-key", |
| 30 | + name="My MCP Deployment", # Optional |
| 31 | + base_url="https://api.myservice.com", # Optional |
| 32 | +) |
| 33 | + |
| 34 | +print(f"Deployed MCP server: {result.id}") |
| 35 | +print(f"Created at: {result.created_at}") |
| 36 | +``` |
| 37 | + |
| 38 | +## OpenAPI Specification Sources |
| 39 | + |
| 40 | +The SDK supports multiple ways to provide your OpenAPI specification: |
| 41 | + |
| 42 | +```python |
| 43 | +# From a file (JSON or YAML) |
| 44 | +result = deploy( |
| 45 | + openapi_spec_path="./openapi.json", # or .yaml |
| 46 | + api_key="your-tadata-api-key", |
| 47 | +) |
| 48 | + |
| 49 | +# From a URL |
| 50 | +result = deploy( |
| 51 | + openapi_spec_url="https://example.com/openapi.json", # or .yaml |
| 52 | + api_key="your-tadata-api-key", |
| 53 | +) |
| 54 | + |
| 55 | +# From a dictionary |
| 56 | +result = deploy( |
| 57 | + openapi_spec={ |
| 58 | + "openapi": "3.0.0", |
| 59 | + "info": {"title": "My API", "version": "1.0.0"}, |
| 60 | + "paths": {"/hello": {"get": {"responses": {"200": {"description": "OK"}}}}}, |
| 61 | + }, |
| 62 | + api_key="your-tadata-api-key", |
| 63 | +) |
| 64 | + |
| 65 | +# From an OpenAPISpec object |
| 66 | +spec = OpenAPISpec.from_file("./openapi.json") |
| 67 | +result = deploy( |
| 68 | + openapi_spec=spec, |
| 69 | + api_key="your-tadata-api-key", |
| 70 | +) |
| 71 | +``` |
| 72 | + |
| 73 | +## Authentication Handling |
| 74 | + |
| 75 | +You can configure how authentication is handled between the MCP server and your API: |
| 76 | + |
| 77 | +```python |
| 78 | +result = deploy( |
| 79 | + openapi_spec_path="./openapi.json", |
| 80 | + api_key="your-tadata-api-key", |
| 81 | + auth_config={ |
| 82 | + "pass_headers": ["authorization", "x-api-key"], # Headers to pass through |
| 83 | + "pass_query_params": ["api_key"], # Query parameters to pass through |
| 84 | + "pass_json_body_params": [], # JSON body parameters to extract |
| 85 | + "pass_form_data_params": [], # Form data parameters to extract |
| 86 | + } |
| 87 | +) |
| 88 | +``` |
| 89 | + |
| 90 | +## Error Handling |
| 91 | + |
| 92 | +The SDK provides specific error classes for better error handling: |
| 93 | + |
| 94 | +```python |
| 95 | +from tadata_sdk import deploy, SpecInvalidError, AuthError, ApiError, NetworkError |
| 96 | + |
| 97 | +try: |
| 98 | + result = deploy( |
| 99 | + openapi_spec_path="./openapi.json", |
| 100 | + api_key="your-tadata-api-key", |
| 101 | + ) |
| 102 | + print(f"Deployed MCP server: {result.id}") |
| 103 | +except SpecInvalidError as e: |
| 104 | + print(f"Invalid OpenAPI spec: {e}") |
| 105 | + print(f"Details: {e.details}") |
| 106 | +except AuthError as e: |
| 107 | + print(f"Authentication failed: {e}") |
| 108 | +except ApiError as e: |
| 109 | + print(f"API error: {e}, Status: {e.status_code}") |
| 110 | +except NetworkError as e: |
| 111 | + print(f"Network error: {e}") |
| 112 | +except Exception as e: |
| 113 | + print(f"Unexpected error: {e}") |
| 114 | +``` |
| 115 | + |
| 116 | +## Advanced Usage |
| 117 | + |
| 118 | +### Custom Logging |
| 119 | + |
| 120 | +You can provide your own logger implementation: |
| 121 | + |
| 122 | +```python |
| 123 | +import logging |
| 124 | +from tadata_sdk import deploy |
| 125 | + |
| 126 | +# Configure a custom logger |
| 127 | +logging.basicConfig(level=logging.DEBUG) |
| 128 | +logger = logging.getLogger("tadata-example") |
| 129 | + |
| 130 | +# Use the custom logger |
| 131 | +result = deploy( |
| 132 | + openapi_spec_path="./openapi.json", |
| 133 | + api_key="your-tadata-api-key", |
| 134 | + logger=logger, |
| 135 | +) |
| 136 | +``` |
| 137 | + |
| 138 | +### Development Environment |
| 139 | + |
| 140 | +For testing purposes, you can use the development environment: |
| 141 | + |
| 142 | +```python |
| 143 | +result = deploy( |
| 144 | + openapi_spec_path="./openapi.json", |
| 145 | + api_key="your-tadata-api-key", |
| 146 | + dev=True, # Use development environment |
| 147 | +) |
| 148 | +``` |
| 149 | + |
| 150 | +## License |
| 151 | + |
| 152 | +MIT |
0 commit comments