{"record":{"id":"7d786e6388143862","repo":"apache/shardingsphere","slug":"s-must-be-an-integer-between-d-and-d-7d786e","errorCode":null,"errorMessage":"%s must be an integer between %d and %d.","messagePattern":"(.+?) must be an integer between (.+?) and (.+?)\\.","errorType":"validation","errorClass":"MCPInvalidRequestException","httpStatus":null,"severity":"error","filePath":"mcp/core/src/main/java/org/apache/shardingsphere/mcp/core/tool/request/MCPToolArguments.java","lineNumber":112,"sourceCode":"    public String getStringArgument(final String name) {\n        return Objects.toString(arguments.get(name), \"\").trim();\n    }\n    \n    /**\n     * Get bounded integer argument.\n     *\n     * @param name argument name\n     * @param defaultValue default value\n     * @param minValue minimum accepted value\n     * @param maxValue maximum accepted value\n     * @return argument value\n     * @throws MCPInvalidRequestException when value is not an integer or is outside the accepted range\n     */\n    public int getIntegerArgument(final String name, final int defaultValue, final int minValue, final int maxValue) {\n        Object value = arguments.get(name);\n        int result = parseIntegerArgument(name, value, defaultValue);\n        if (result < minValue || result > maxValue) {\n            throw new MCPInvalidRequestException(String.format(\"%s must be an integer between %d and %d.\", name, minValue, maxValue));\n        }\n        return result;\n    }\n    \n    private int parseIntegerArgument(final String name, final Object value, final int defaultValue) {\n        if (null == value) {\n            return defaultValue;\n        }\n        String actualValue = Objects.toString(value, \"\").trim();\n        if (actualValue.isEmpty()) {\n            return defaultValue;\n        }\n        try {\n            return Integer.parseInt(actualValue);\n        } catch (final NumberFormatException ex) {\n            throw new MCPInvalidRequestException(String.format(\"%s must be an integer.\", name), ex);\n        }\n    }","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/mcp/core/src/main/java/org/apache/shardingsphere/mcp/core/tool/request/MCPToolArguments.java#L94-L130","documentation":"Thrown by MCPToolArguments.getIntegerArgument (MCPInvalidRequestException) when a numeric argument parses as an integer but falls outside the tool's accepted [minValue, maxValue] range. The message names the argument and the exact accepted bounds, e.g. \"limit must be an integer between 1 and 1000.\".","triggerScenarios":"getIntegerArgument(name, default, min, max) with a present, non-blank value whose parse succeeds but result < min or > max — e.g. limit=0, limit=10000, timeout=-1. Null or blank values fall back to the default and do NOT throw; only out-of-range explicit values do.","commonSituations":"Agents setting limit=1000000 to 'fetch everything'; copying defaults between tools whose ranges differ (pagination limit vs timeout); negative values from arithmetic on unset variables in client code.","solutions":["Clamp the value into the range reported in the message before retrying (e.g. limit to the documented max, then paginate)","Omit the argument entirely to accept the tool default when you do not need a specific value","Cache each tool's declared min/max from its descriptor and validate client-side"],"exampleFix":"// before\nquery({\"sql\": \"...\", \"limit\": 100000})\n\n// after\nquery({\"sql\": \"...\", \"limit\": 1000}) -- and paginate with offset if more rows needed","handlingStrategy":"validation","validationCode":"// Clamp numeric args to the tool's declared range before sending\nint v = Integer.parseInt(String.valueOf(arguments.get(\"limit\")));\nif (v < LIMIT_MIN || v > LIMIT_MAX) arguments.put(\"limit\", Math.max(LIMIT_MIN, Math.min(LIMIT_MAX, v)));","typeGuard":"const inRange = (v: unknown, min: number, max: number): v is number =>\n  typeof v === \"number\" && Number.isInteger(v) && v >= min && v <= max;","tryCatchPattern":"try {\n    query(arguments);\n} catch (MCPInvalidRequestException e) {\n    Matcher m = Pattern.compile(\"(\\\\w+) must be an integer between (-?\\\\d+) and (-?\\\\d+)\").matcher(e.getMessage());\n    if (m.find()) { arguments.put(m.group(1), Integer.parseInt(m.group(3))); return query(arguments); }\n    throw e;\n}","preventionTips":["Clamp pagination limits to the documented max and paginate beyond it","Cache each tool's min/max from its descriptor and validate client-side","Omit the argument to accept the default when unsure"],"tags":["mcp","request-validation","integer-range","pagination","shardingsphere"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}