{"record":{"id":"5e60f1cd2d941e68","repo":"alibaba/spring-ai-alibaba","slug":"deletemcpservererror","errorCode":"DeleteMCPServerError","errorMessage":"Failed to delete MCPServer.","messagePattern":"Failed to delete MCPServer\\.","errorType":"error_code","errorClass":"BizException","httpStatus":500,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/McpServerServiceImpl.java","lineNumber":186,"sourceCode":"\t * @param serverCode Unique identifier of the server\n\t */\n\t@Override\n\tpublic void deleteMcp(String serverCode) {\n\t\ttry {\n\t\t\tRequestContext context = RequestContextHolder.getRequestContext();\n\t\t\tMcpServerEntity entity = getMcpByCode(context.getWorkspaceId(), serverCode, null);\n\t\t\tif (entity == null) {\n\t\t\t\tthrow new BizException(MCP_NOT_FOUND.toError());\n\t\t\t}\n\t\t\tentity.setGmtModified(new Date());\n\t\t\tentity.setStatus(McpServerStatusEnum.Deleted.getCode());\n\t\t\tthis.updateById(entity);\n\t\t\tString key = getMcpCacheKey(context.getWorkspaceId(), serverCode);\n\t\t\tredisManager.put(key, entity);\n\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new BizException(ErrorCode.DELETE_MCP_ERROR.toError(), e);\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves MCP server details by server code\n\t * @param serverCode Unique identifier of the server\n\t * @param needTools Whether to include tool information\n\t * @return Server details\n\t */\n\t@Override\n\tpublic McpServerDetail getMcp(String serverCode, boolean needTools) {\n\t\tRequestContext context = RequestContextHolder.getRequestContext();\n\t\tMcpServerEntity entity = getMcpByCode(context.getWorkspaceId(), serverCode, null);\n\t\tif (entity == null) {\n\t\t\tthrow new BizException(MCP_NOT_FOUND.toError());\n\t\t}\n\t\tMcpServerDetail mcpServerDTO = toMcpServerDTO(entity);\n\t\tif (needTools) {","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/McpServerServiceImpl.java#L168-L204","documentation":"Thrown by McpServerServiceImpl.deleteMcp when any exception occurs while deleting an MCP server. The service updates the DB entity, then writes/evicts the Redis cache entry keyed by workspace+serverCode; any failure in those persistence or cache operations is wrapped as BizException with code DeleteMCPServerError.","triggerScenarios":"Calling deleteMcp(serverCode) when the database update or the redisManager cache operation throws (DB connectivity loss, Redis down, serialization failure, optimistic-lock conflict).","commonSituations":"Redis connection pool exhausted; database deadlocks on concurrent deletes; entity state changed by another request between load and updateById; cache serialization errors after schema changes to McpServerEntity.","solutions":["Check Redis and database connectivity from the admin-server-core service","Inspect the wrapped cause 'e' in logs for the real failure (SQL error, Redis timeout)","Retry the delete after resolving transient infra issues","Clear the stale Redis cache key (workspace:serverCode) if the delete partially succeeded"],"exampleFix":"// before\ntry {\n    this.updateById(entity);\n    redisManager.put(key, entity);\n} catch (Exception e) {\n    throw new BizException(ErrorCode.DELETE_MCP_ERROR.toError(), e);\n}\n// after\ntry {\n    this.updateById(entity);\n} catch (DataAccessException e) {\n    log.error(\"DB delete failed for MCP {}\", serverCode, e);\n    throw new BizException(ErrorCode.DELETE_MCP_ERROR.toError(), e);\n}\ntry {\n    redisManager.delete(key);\n} catch (Exception e) {\n    log.warn(\"Cache evict failed for MCP {}\", serverCode, e); // non-fatal\n}","handlingStrategy":"try-catch","validationCode":"// pre-check server exists and infra is reachable\nMcpServerEntity e = mcpServerService.getMcpByCode(workspaceId, serverCode, null);\nif (e == null) throw new IllegalStateException(\"MCP server not found: \" + serverCode);","typeGuard":null,"tryCatchPattern":"try {\n    mcpServerService.deleteMcp(serverCode);\n} catch (BizException e) {\n    if (e.getCause() instanceof DataAccessException dae) {\n        // retry or alert: DB-side failure\n    } else if (e.getCause() instanceof RedisException re) {\n        // evict cache manually and retry\n    }\n    log.error(\"Delete failed for {}\", serverCode, e.getCause());\n}","preventionTips":["Monitor Redis health from admin-server-core","Avoid concurrent deletes of the same MCP server","Always log the wrapped cause to identify the failing subsystem","Evict cache keys explicitly after schema changes"],"tags":["mcp","redis","database","persistence"],"backgroundTag":"database-write-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}