Skip to content

MCP server doesn't support returning enums #45

@glaforge

Description

@glaforge

Expected Behavior

I tried implementing an MCP tool that returned an enum.

For example, let's say you have a tool that looks like this:

@Tool(name = "sun-state")
public SunState sunState() {
    return SunState.TOTAL_ECLIPSE;
}

My enum looks like this:

public enum SunState {
    FULL, ANNULAR_ECLIPSE, PARTIAL_ECLIPSE, TOTAL_ECLIPSE
}

Actual Behaviour

In the case above, when using the MCP inspector, the output of that tool will be a string surrounded by quotes, corresponding to the name of the enum:

"\"TOTAL_ECLIPSE\""

Instead of just `"TOTAL_ECLIPSE"`, maybe?

Now if I want to make this enum `@Introspected` and have a `@JsonSchema`, my `enum` becomes:

```java
@JsonSchema(
    title = "Sun state",
    description = "Sun state",
    uri = "/sunState"
)
@Introspected
public enum SunState {
    FULL, ANNULAR_ECLIPSE, PARTIAL_ECLIPSE, TOTAL_ECLIPSE;
}

The server runs fine, but then, when I list the tools in the MCP inspector, it tells me:

[
  {
    "received": "string",
    "code": "invalid_literal",
    "expected": "object",
    "path": [
      "tools",
      2,
      "outputSchema",
      "type"
    ],
    "message": "Invalid literal value, expected \"object\""
  }
]

However, if I turn the enum into a similar record:

@JsonSchema
@Introspected
public record SunState(String state) {
}

It works just fine.

Steps To Reproduce

As stated above, trying to annotate, return, an enum, from an MCP tool.

Environment Information

No response

Example Application

No response

Version

4.9.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions