apache/shenyu · error · IllegalStateException

Request configuration cannot be empty

Error message

Request configuration cannot be empty

What it means

extractRequestConfig reads the requestConfig string from the ShenyuToolDefinition and throws IllegalStateException when it is null or blank. The ShenYu MCP bridge needs this config (target path, method, etc.) to translate a tool call into an HTTP request, so an empty config makes the tool unusable.

Solutions

  1. Provide a non-empty requestConfig when building the ShenyuToolDefinition (JSON describing method/path of the downstream call).
  2. In the admin dashboard, fill in the tool's request configuration and re-publish.
  3. Print/inspect definition.requestConfig() during registration to catch blanks early.

Example fix

// before
ShenyuToolDefinition.builder().name("get-user").build();
// after
ShenyuToolDefinition.builder().name("get-user").requestConfig("{\"request\":{\"method\":\"GET\",\"path\":\"/user\"}}").build();
Defensive patterns

Strategy: validation

Validate before calling

if (def instanceof ShenyuToolDefinition s
        && !StringUtils.hasText(s.requestConfig())) {
    throw new IllegalArgumentException("Tool '" + s.name() + "' has empty requestConfig");
}

Try / catch

try {
    return callback.call(args, ctx);
} catch (IllegalStateException e) {
    if ("Request configuration cannot be empty".equals(e.getMessage())) {
        return "Tool is misconfigured: request configuration missing";
    }
    throw e;
}

Prevention

When it happens

Trigger: A tool definition was registered with requestConfig missing, empty, or whitespace-only — e.g. ShenyuToolDefinition built without requestConfig, or admin-side MCP tool config where the request config field was left blank.

Common situations: Hand-crafting tool specs in code and omitting requestConfig; creating an MCP tool in the ShenYu admin dashboard without filling the request configuration JSON; sync lag leaving a partially populated tool definition.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12). Data as JSON: /api/errors/df4ca53c9e3de53f. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/callback/ShenyuToolCallback.java:188

    private ShenyuToolDefinition validateToolDefinition() {
        if (!(this.toolDefinition instanceof ShenyuToolDefinition)) {
            throw new IllegalStateException("Tool definition must be of type ShenyuToolDefinition, got: "
                    + this.toolDefinition.getClass().getSimpleName());
        }
        return (ShenyuToolDefinition) this.toolDefinition;
    }

    /**
     * Extracts and validates the request configuration from the tool definition.
     *
     * @param definition the Shenyu tool definition
     * @return the request configuration string
     * @throws IllegalStateException if configuration is missing or invalid
     */
    private String extractRequestConfig(final ShenyuToolDefinition definition) {
        final String config = definition.requestConfig();
        if (!StringUtils.hasText(config)) {
            throw new IllegalStateException("Request configuration cannot be empty");
        }
        LOG.debug("Using request configuration with length: {} chars", config.length());
        return config;
    }

    /**
     * Extracts the plugin chain from the exchange.
     *
     * @param exchange the server web exchange
     * @return the plugin chain
     * @throws IllegalStateException if chain is not found
     */
    private ShenyuPluginChain getPluginChain(final ServerWebExchange exchange) {
        final ShenyuPluginChain chain = exchange.getAttribute(Constants.CHAIN);
        Assert.notNull(chain, "ShenyuPluginChain cannot be null");
        return chain;
    }

View on GitHub (pinned to 567142e072)