mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
🐛 fix: Improve Error Handling when Adding MCP Server Fails (#10823)
* 🐛 fix: Improve error handling when adding MCP server fails
* Update api/server/controllers/mcp.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update api/server/controllers/mcp.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Atef Bellaaj <slalom.bellaaj@external.daimlertruck.com>
Co-authored-by: Danny Avila <danny@librechat.ai>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
885508fc74
commit
d08f7c2c8a
4 changed files with 30 additions and 3 deletions
|
|
@ -175,6 +175,12 @@ const createMCPServerController = async (req, res) => {
|
|||
});
|
||||
} catch (error) {
|
||||
logger.error('[createMCPServer]', error);
|
||||
if (error.message?.startsWith('MCP_INSPECTION_FAILED')) {
|
||||
return res.status(400).json({
|
||||
error: 'MCP_INSPECTION_FAILED',
|
||||
message: error.message,
|
||||
});
|
||||
}
|
||||
res.status(500).json({ message: error.message });
|
||||
}
|
||||
};
|
||||
|
|
@ -229,6 +235,12 @@ const updateMCPServerController = async (req, res) => {
|
|||
res.status(200).json(parsedConfig);
|
||||
} catch (error) {
|
||||
logger.error('[updateMCPServer]', error);
|
||||
if (error.message?.startsWith('MCP_INSPECTION_FAILED:')) {
|
||||
return res.status(400).json({
|
||||
error: 'MCP_INSPECTION_FAILED',
|
||||
message: error.message,
|
||||
});
|
||||
}
|
||||
res.status(500).json({ message: error.message });
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -283,7 +283,9 @@ export default function MCPServerDialog({
|
|||
|
||||
if (error && typeof error === 'object' && 'response' in error) {
|
||||
const axiosError = error as any;
|
||||
if (axiosError.response?.data?.error) {
|
||||
if (axiosError.response?.data?.error === 'MCP_INSPECTION_FAILED') {
|
||||
errorMessage = localize('com_ui_mcp_server_connection_failed');
|
||||
} else if (axiosError.response?.data?.error) {
|
||||
errorMessage = axiosError.response.data.error;
|
||||
}
|
||||
} else if (error.message) {
|
||||
|
|
|
|||
|
|
@ -633,6 +633,7 @@
|
|||
"com_ui_add_first_mcp_server": "Create your first MCP server to get started",
|
||||
"com_ui_mcp_server_created": "MCP server created successfully",
|
||||
"com_ui_mcp_server_updated": "MCP server updated successfully",
|
||||
"com_ui_mcp_server_connection_failed": "Connection attempt to the provided MCP server failed. Please make sure the URL, the server type, and any authentication configuration are correct, then try again. Also ensure the URL is reachable.",
|
||||
"com_ui_add_model_preset": "Add a model or preset for an additional response",
|
||||
"com_ui_add_multi_conversation": "Add multi-conversation",
|
||||
"com_ui_add_special_variables": "Add Special Variables",
|
||||
|
|
|
|||
|
|
@ -78,7 +78,13 @@ export class MCPServersRegistry {
|
|||
userId?: string,
|
||||
): Promise<t.AddServerResult> {
|
||||
const configRepo = this.getConfigRepository(storageLocation);
|
||||
const parsedConfig = await MCPServerInspector.inspect(serverName, config);
|
||||
let parsedConfig: t.ParsedServerConfig;
|
||||
try {
|
||||
parsedConfig = await MCPServerInspector.inspect(serverName, config);
|
||||
} catch (error) {
|
||||
logger.error(`[MCPServersRegistry] Failed to inspect server "${serverName}":`, error);
|
||||
throw new Error(`MCP_INSPECTION_FAILED: Failed to connect to MCP server "${serverName}"`);
|
||||
}
|
||||
return await configRepo.add(serverName, parsedConfig, userId);
|
||||
}
|
||||
|
||||
|
|
@ -89,7 +95,13 @@ export class MCPServersRegistry {
|
|||
userId?: string,
|
||||
): Promise<t.ParsedServerConfig> {
|
||||
const configRepo = this.getConfigRepository(storageLocation);
|
||||
const parsedConfig = await MCPServerInspector.inspect(serverName, config);
|
||||
let parsedConfig: t.ParsedServerConfig;
|
||||
try {
|
||||
parsedConfig = await MCPServerInspector.inspect(serverName, config);
|
||||
} catch (error) {
|
||||
logger.error(`[MCPServersRegistry] Failed to inspect server "${serverName}":`, error);
|
||||
throw new Error(`MCP_INSPECTION_FAILED: Failed to connect to MCP server "${serverName}"`);
|
||||
}
|
||||
await configRepo.update(serverName, parsedConfig, userId);
|
||||
return parsedConfig;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue