( mcpId: number, newServiceName: string, newMcpUrl: string, newAuthorizationToken?: string | null, newCustomHeaders?: Record<string, string> | null, description?: string | null, tags?: string[], tenantId?: string | null )
| 157 | * Update MCP server |
| 158 | */ |
| 159 | export const updateMcpServer = async ( |
| 160 | mcpId: number, |
| 161 | newServiceName: string, |
| 162 | newMcpUrl: string, |
| 163 | newAuthorizationToken?: string | null, |
| 164 | newCustomHeaders?: Record<string, string> | null, |
| 165 | description?: string | null, |
| 166 | tags?: string[], |
| 167 | tenantId?: string | null |
| 168 | ) => { |
| 169 | try { |
| 170 | const url = tenantId |
| 171 | ? `${API_ENDPOINTS.mcp.update}?tenant_id=${encodeURIComponent(tenantId)}` |
| 172 | : API_ENDPOINTS.mcp.update; |
| 173 | const body: any = { |
| 174 | mcp_id: mcpId, |
| 175 | name: newServiceName, |
| 176 | server_url: newMcpUrl, |
| 177 | description: description ?? null, |
| 178 | tags: tags ?? [], |
| 179 | }; |
| 180 | if (newAuthorizationToken !== undefined) { |
| 181 | body.authorization_token = newAuthorizationToken; |
| 182 | } |
| 183 | if (newCustomHeaders !== undefined) { |
| 184 | body.custom_headers = newCustomHeaders; |
| 185 | } |
| 186 | const response = await fetch(url, { |
| 187 | method: "PUT", |
| 188 | headers: getAuthHeaders(), |
| 189 | body: JSON.stringify(body), |
| 190 | }); |
| 191 | |
| 192 | const data = await response.json(); |
| 193 | |
| 194 | if (response.ok && data.status === "success") { |
| 195 | return { |
| 196 | success: true, |
| 197 | data: data, |
| 198 | message: data.message || t("mcpService.message.updateServerSuccess"), |
| 199 | }; |
| 200 | } else { |
| 201 | // Handle specific error status codes and error information |
| 202 | let errorMessage = |
| 203 | data.message || t("mcpService.message.updateServerFailed"); |
| 204 | |
| 205 | if (response.status === 409) { |
| 206 | errorMessage = t("mcpService.message.nameAlreadyUsed"); |
| 207 | } else if (response.status === 503) { |
| 208 | errorMessage = t("mcpService.message.cannotConnectToServer"); |
| 209 | } else { |
| 210 | errorMessage = t("mcpService.message.updateProxyFailed"); |
| 211 | } |
| 212 | |
| 213 | return { |
| 214 | success: false, |
| 215 | data: null, |
| 216 | message: errorMessage, |
no test coverage detected