Skip to content

NullPointerException for tools that return void. #6

@krishnanmms

Description

@krishnanmms

For tools that return void or null, it results in an NPE; since the output of the tool method is processed without checking for null.

In class McpServerTool (refer to NPE comment),

 @Override
  public McpSchema.CallToolResult apply(McpSyncServerExchange ex, McpSchema.CallToolRequest req) {

    Object result;
    boolean isError = false;
    try {
      Map<String, Object> arguments = req.arguments();
      List<Object> convertedParams = converter.convertAllParameters(methodCache, arguments);
      // Use cached method for invocation
      result = methodCache.getMethod().invoke(instance, convertedParams.toArray());
    } catch (Exception e) {
      log.error("Error invoking tool method: {}", methodCache.getMethodSignature(), e);
      result = e + ": " + e.getMessage();
      isError = true;
    }
    McpSchema.Content content = new McpSchema.TextContent(result.toString()); // NPE : result, can be null
    return new McpSchema.CallToolResult(List.of(content), isError);
  }

I am fairly new to this library (and to MCP). Apologies in case I have made a mistake in reporting this issue.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestfixed and releasedThis issue has been fixed and included in the latest releasewaiting for userWaiting for user feedback or more details

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions