|
| 1 | +# Tadata Node SDK |
| 2 | + |
| 3 | +A Node.js SDK for deploying MCP (Multi-Channel Proxy) servers with your OpenAPI specifications. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install @tadata/node-sdk |
| 9 | +# or |
| 10 | +yarn add @tadata/node-sdk |
| 11 | +# or |
| 12 | +pnpm add @tadata/node-sdk |
| 13 | +``` |
| 14 | + |
| 15 | +## Quickstart |
| 16 | + |
| 17 | +Deploy an MCP server with your OpenAPI specification: |
| 18 | + |
| 19 | +```typescript |
| 20 | +import { TadataNodeSDK, OpenApiSource } from '@tadata/node-sdk'; |
| 21 | + |
| 22 | +// Initialize the SDK |
| 23 | +const tadata = new TadataNodeSDK({ |
| 24 | + apiKey: process.env.TADATA_KEY!, |
| 25 | + dev: process.env.NODE_ENV !== 'production', |
| 26 | + version: '10-10-2024', // Optional: specify API version |
| 27 | + logger: pino(), // Optional: use custom logger |
| 28 | +}); |
| 29 | + |
| 30 | +// Create an OpenAPI source from various formats |
| 31 | +const source = await OpenApiSource.fromFile('./acme-openapi.yaml'); |
| 32 | + |
| 33 | +// Deploy the MCP server |
| 34 | +const deployment = await tadata.mcp.deploy({ |
| 35 | + spec: source, |
| 36 | + specBaseUrl: 'https://acme.com/api', |
| 37 | + name: 'Acme API', // Optional |
| 38 | +}); |
| 39 | + |
| 40 | +console.log(`Deployed MCP server: ${deployment.url}`); |
| 41 | +``` |
| 42 | + |
| 43 | +## OpenAPI Source Formats |
| 44 | + |
| 45 | +The SDK supports multiple ways to provide your OpenAPI specification: |
| 46 | + |
| 47 | +```typescript |
| 48 | +// From a file (YAML or JSON) |
| 49 | +const source = await OpenApiSource.fromFile('./openapi.yaml'); |
| 50 | + |
| 51 | +// From a JSON string |
| 52 | +const source = OpenApiSource.fromJson(jsonString); |
| 53 | + |
| 54 | +// From a YAML string |
| 55 | +const source = OpenApiSource.fromYaml(yamlString); |
| 56 | + |
| 57 | +// From a JavaScript object |
| 58 | +const source = OpenApiSource.fromObject({ |
| 59 | + openapi: '3.0.0', |
| 60 | + info: { title: 'Example API', version: '1.0.0' }, |
| 61 | + paths: { /* ... */ } |
| 62 | +}); |
| 63 | + |
| 64 | +// From an Express application |
| 65 | +const source = OpenApiSource.fromExpress(app); |
| 66 | + |
| 67 | +// From a Fastify instance |
| 68 | +const source = OpenApiSource.fromFastify(fastifyApp); |
| 69 | +``` |
| 70 | + |
| 71 | +## Error Handling |
| 72 | + |
| 73 | +The SDK provides specific error classes for better error handling: |
| 74 | + |
| 75 | +```typescript |
| 76 | +import { SpecInvalidError, AuthError, ApiError, NetworkError } from '@tadata/node-sdk'; |
| 77 | + |
| 78 | +try { |
| 79 | + await tadata.mcp.deploy({ /* ... */ }); |
| 80 | +} catch (error) { |
| 81 | + if (error instanceof SpecInvalidError) { |
| 82 | + console.error('Invalid OpenAPI spec:', error.message, error.details); |
| 83 | + } else if (error instanceof AuthError) { |
| 84 | + console.error('Authentication failed:', error.message); |
| 85 | + } else if (error instanceof ApiError) { |
| 86 | + console.error('API error:', error.message, error.statusCode); |
| 87 | + } else if (error instanceof NetworkError) { |
| 88 | + console.error('Network error:', error.message); |
| 89 | + } else { |
| 90 | + console.error('Unexpected error:', error); |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +## Custom Logging |
| 96 | + |
| 97 | +You can provide your own logger implementation: |
| 98 | + |
| 99 | +```typescript |
| 100 | +import pino from 'pino'; |
| 101 | +import { TadataNodeSDK, Logger } from '@tadata/node-sdk'; |
| 102 | + |
| 103 | +// Use pino |
| 104 | +const pinoLogger = pino(); |
| 105 | + |
| 106 | +const tadata = new TadataNodeSDK({ |
| 107 | + apiKey: 'your-api-key', |
| 108 | + logger: pinoLogger, |
| 109 | +}); |
| 110 | + |
| 111 | +// Or create a custom logger |
| 112 | +class CustomLogger implements Logger { |
| 113 | + debug(msg: string, ...meta: unknown[]): void { |
| 114 | + // Your implementation |
| 115 | + } |
| 116 | + info(msg: string, ...meta: unknown[]): void { |
| 117 | + // Your implementation |
| 118 | + } |
| 119 | + warn(msg: string, ...meta: unknown[]): void { |
| 120 | + // Your implementation |
| 121 | + } |
| 122 | + error(msg: string, ...meta: unknown[]): void { |
| 123 | + // Your implementation |
| 124 | + } |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +## License |
| 129 | + |
| 130 | +MIT |
0 commit comments