MCPcopy
hub / github.com/ModelEngine-Group/nexent / updateMcpServer

Function updateMcpServer

frontend/services/mcpService.ts:159–227  ·  view source on GitHub ↗
(
  mcpId: number,
  newServiceName: string,
  newMcpUrl: string,
  newAuthorizationToken?: string | null,
  newCustomHeaders?: Record<string, string> | null,
  description?: string | null,
  tags?: string[],
  tenantId?: string | null
)

Source from the content-addressed store, hash-verified

157 * Update MCP server
158 */
159export 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,

Callers 1

useMcpConfigFunction · 0.90

Calls 4

errorMethod · 0.80
getAuthHeadersFunction · 0.70
tFunction · 0.70
jsonMethod · 0.45

Tested by

no test coverage detected