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

Function addMcpServer

frontend/services/mcpService.ts:98–154  ·  view source on GitHub ↗
(mcpUrl: string, serviceName: string, authorizationToken?: string | null, customHeaders?: Record<string, string> | null, tenantId?: string | null)

Source from the content-addressed store, hash-verified

96 * Add MCP server
97 */
98export const addMcpServer = async (mcpUrl: string, serviceName: string, authorizationToken?: string | null, customHeaders?: Record<string, string> | null, tenantId?: string | null) => {
99 try {
100 const url = tenantId
101 ? `${API_ENDPOINTS.mcp.add}?tenant_id=${encodeURIComponent(tenantId)}`
102 : API_ENDPOINTS.mcp.add;
103 const body: any = {
104 name: serviceName,
105 server_url: mcpUrl,
106 enabled: true,
107 };
108 if (authorizationToken) {
109 body.authorization_token = authorizationToken;
110 }
111 if (customHeaders) {
112 body.custom_headers = customHeaders;
113 }
114 const response = await fetch(url, {
115 method: 'POST',
116 headers: getAuthHeaders(),
117 body: JSON.stringify(body),
118 });
119
120 const data = await response.json();
121
122 if (response.ok && data.status === 'success') {
123 return {
124 success: true,
125 data: data,
126 message: data.message || t('mcpService.message.addServerSuccess')
127 };
128 } else {
129 // Handle specific error status codes and error information
130 let errorMessage = data.detail || data.message || t('mcpService.message.addServerFailed');
131
132 if (response.status === 409) {
133 errorMessage = t('mcpService.message.nameAlreadyUsed');
134 } else if (response.status === 503) {
135 errorMessage = t('mcpService.message.cannotConnectToServer');
136 } else {
137 errorMessage = t('mcpService.message.addProxyFailed');
138 }
139
140 return {
141 success: false,
142 data: null,
143 message: errorMessage
144 };
145 }
146 } catch (error) {
147 log.error(t('mcpService.debug.addServerFailed'), error);
148 return {
149 success: false,
150 data: null,
151 message: t('mcpService.message.networkError')
152 };
153 }
154};
155

Callers 2

handleInstallMcpFunction · 0.90
useMcpConfigFunction · 0.90

Calls 4

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

Tested by

no test coverage detected