|
1 | 1 | import { ClientArgs, InitClientReturn } from '@ts-rest/core'; |
2 | 2 | import { StatusCodes } from 'http-status-codes'; |
| 3 | +import { z } from 'zod'; |
3 | 4 | import { Logger } from '../../core/logger'; |
4 | | -import { ApiError, SpecInvalidError, AuthError } from '../../errors'; |
| 5 | +import { ApiError, SpecInvalidError } from '../../errors'; |
5 | 6 | import { deploymentsContract } from '../../http/contracts'; |
6 | 7 | import { OpenApi3Schema } from '../../http/schemas'; |
7 | | -import { z } from 'zod'; |
8 | 8 | import { McpDeployInput, McpDeploymentResult } from './types'; |
9 | 9 |
|
10 | 10 | interface DeploymentSuccessResponse { |
11 | 11 | ok: true; |
12 | 12 | data: { |
| 13 | + updated: boolean; |
13 | 14 | deployment: { |
14 | 15 | id: string; |
15 | | - url: string; |
| 16 | + name: string; |
| 17 | + url?: string; // URL is optional in the server response |
| 18 | + specVersion?: string; // specVersion is optional in the server response |
| 19 | + createdAt?: string; |
| 20 | + updatedAt?: string; |
16 | 21 | }; |
17 | 22 | }; |
18 | 23 | } |
@@ -60,21 +65,22 @@ export class McpResource { |
60 | 65 | // No need to pass apiKey as it's automatically added by the client |
61 | 66 | const response = await this.client.upsertFromOpenApi({ |
62 | 67 | body: { |
63 | | - openapiSpec, |
64 | | - serviceName: input.name, |
65 | | - version: '1.0.0', // Add proper versioning parameter |
| 68 | + openApiSpec: openapiSpec, |
| 69 | + name: input.name, |
| 70 | + baseUrl: input.specBaseUrl, |
66 | 71 | }, |
67 | 72 | }); |
68 | 73 |
|
69 | | - // For successful response, transform to expected McpDeploymentResult format |
70 | 74 | if (isDeploymentResponse(response.body) && response.body.ok) { |
71 | 75 | const deploymentData = response.body.data.deployment; |
72 | 76 |
|
73 | 77 | return { |
74 | 78 | id: deploymentData.id, |
75 | | - url: deploymentData.url, |
76 | | - specVersion: '1.0.0', // Use appropriate version from response when available |
77 | | - createdAt: new Date(), // Use appropriate timestamp from response when available |
| 79 | + // Provide a default value for specVersion if undefined |
| 80 | + specVersion: deploymentData.specVersion || '1.0.0', |
| 81 | + // Provide a default URL value (required by type) if not returned from server |
| 82 | + url: deploymentData.url || `http://localhost:3000/mcp/${deploymentData.id}`, |
| 83 | + createdAt: deploymentData.createdAt ? new Date(deploymentData.createdAt) : new Date(), |
78 | 84 | }; |
79 | 85 | } |
80 | 86 |
|
@@ -116,47 +122,47 @@ export class McpResource { |
116 | 122 | */ |
117 | 123 | function formatErrorForLogging(error: unknown): Record<string, any> { |
118 | 124 | if (!error) return { type: 'unknown' }; |
119 | | - |
| 125 | + |
120 | 126 | // Handle ApiError |
121 | 127 | if (error instanceof ApiError) { |
122 | 128 | const result: Record<string, any> = { |
123 | 129 | type: 'ApiError', |
124 | 130 | message: error.message, |
125 | 131 | code: error.code, |
126 | | - statusCode: error.statusCode |
| 132 | + statusCode: error.statusCode, |
127 | 133 | }; |
128 | | - |
| 134 | + |
129 | 135 | // Extract response body if available |
130 | 136 | if (error.body) { |
131 | | - if (typeof error.body === 'object' && error.body !== null) { |
| 137 | + if (typeof error.body === 'object') { |
132 | 138 | const body = error.body as any; |
133 | 139 | if (body.error) { |
134 | 140 | result.errorCode = body.error.code; |
135 | 141 | result.errorMessage = body.error.message; |
136 | | - |
| 142 | + |
137 | 143 | // Include first validation error if present |
138 | 144 | if (body.error.errors && body.error.errors.length > 0) { |
139 | 145 | result.validation = body.error.errors[0]; |
140 | 146 | } |
141 | 147 | } |
142 | 148 | } |
143 | 149 | } |
144 | | - |
| 150 | + |
145 | 151 | return result; |
146 | 152 | } |
147 | | - |
| 153 | + |
148 | 154 | // Handle AuthError |
149 | 155 | if (error instanceof Error) { |
150 | 156 | return { |
151 | 157 | type: error.constructor.name, |
152 | 158 | message: error.message, |
153 | | - code: (error as any).code |
| 159 | + code: (error as any).code, |
154 | 160 | }; |
155 | 161 | } |
156 | | - |
| 162 | + |
157 | 163 | // Unknown error type |
158 | | - return { |
| 164 | + return { |
159 | 165 | type: 'unknown', |
160 | | - error: String(error) |
| 166 | + error: String(error), |
161 | 167 | }; |
162 | 168 | } |
0 commit comments