{"record":{"id":"39abef34014fb530","repo":"spring-projects/spring-ai","slug":"error-invoking-complete-method","errorCode":null,"errorMessage":"Error invoking complete method: ","messagePattern":"Error invoking complete method: ","errorType":"exception","errorClass":"McpCompleteMethodException","httpStatus":null,"severity":"error","filePath":"mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/complete/SyncMcpCompleteMethodCallback.java","lineNumber":81,"sourceCode":"\t@Override\n\tpublic CompleteResult apply(McpSyncServerExchange exchange, CompleteRequest request) {\n\t\tif (request == null) {\n\t\t\tthrow new IllegalArgumentException(\"Request must not be null\");\n\t\t}\n\n\t\ttry {\n\t\t\t// Build arguments for the method call\n\t\t\tObject[] args = this.buildArgs(this.method, exchange, request);\n\n\t\t\t// Invoke the method\n\t\t\tthis.method.setAccessible(true);\n\t\t\tObject result = this.method.invoke(this.bean, args);\n\n\t\t\t// Convert the result to a CompleteResult\n\t\t\treturn convertToCompleteResult(result);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new McpCompleteMethodException(\"Error invoking complete method: \" + this.method.getName(), e);\n\t\t}\n\t}\n\n\t/**\n\t * Converts the method result to a CompleteResult.\n\t * @param result The method result\n\t * @return The CompleteResult\n\t */\n\tprivate CompleteResult convertToCompleteResult(Object result) {\n\t\tif (result == null) {\n\t\t\treturn new CompleteResult(new CompleteCompletion(List.of(), 0, false));\n\t\t}\n\n\t\tif (result instanceof CompleteResult) {\n\t\t\treturn (CompleteResult) result;\n\t\t}\n\n\t\tif (result instanceof CompleteCompletion) {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/complete/SyncMcpCompleteMethodCallback.java#L63-L99","documentation":"When the reflective invocation of the user's @McpComplete method (this.method.invoke) throws — or the result conversion fails — apply() wraps the cause in McpCompleteMethodException with the message 'Error invoking complete method: <methodName>', preserving the original exception as the cause. This is the generic failure envelope for completion handler execution.","triggerScenarios":"Any exception inside the annotated completion method (NPE, database error, assertion), the method not being accessible for reflection (IllegalAccessException), wrong argument binding, or convertToCompleteResult rejecting the result (see errors 105/106).","commonSituations":"Completion method throws because a downstream service is unavailable; argument name in @McpComplete annotation does not match a method parameter; security manager / module access blocking reflection; returning an unsupported type that fails conversion.","solutions":["Read the cause (e.getCause()) of McpCompleteMethodException to find the real failure inside your method","Verify @McpComplete argument names match the method parameter names and buildArgs expectations","Fix the root exception in the completion method (null checks, service availability)","Ensure the return type is CompleteResult/CompleteCompletion/List<String>/String/Mono<T> so conversion succeeds"],"exampleFix":"// before\n@McpComplete(name:=\"argx\") public List<String> complete(String argument) { ... } // name mismatch -> binding failure\n// after\n@McpComplete(name:=\"argument\") public List<String> complete(String argument) { ... }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return callback.apply(exchange, request);\n} catch (McpCompleteMethodException e) {\n    log.error(\"Completion method {} failed\", e.getMessage(), e.getCause());\n    return new CompleteResult(new CompleteCompletion(List.of(), 0, false));\n}","preventionTips":["Always inspect getCause() — the message only names the method, the cause holds the real error","Keep @McpComplete method bodies defensive: null-check inputs and guard downstream calls","Ensure annotation argument names exactly match method parameter names","Add tests exercising each completion method through the callback to surface reflection/conversion issues early"],"tags":["mcp","completion","reflection","java"],"backgroundTag":"api-request-failed","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}