agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Feature]: Support outputSchema for MCP tools

Open bgy675939778 opened this issue 7 months ago • 3 comments

MCP标准协议中,对于 tools/list 已经支持了 outputSchema;

在使用 agentscope-java时,按照文档介绍使用方式:

McpClientWrapper httpClient = McpClientBuilder.create("http-mcp")
        .streamableHttpTransport("https://mcp.example.com/http")
        .header("X-API-Key", apiKey)
        .queryParam("queryKey", "queryValue")
        .buildAsync()
        .block();

toolkit.registerMcpClient(httpClient ).block();

// 调用 
List<ToolSchema> allSchemas = toolkit.getToolSchemas();

getToolSchemas() 方法返回 List,ToolSchema的定义为:

public class ToolSchema {
    private final String name;
    private final String description;
    private final Map<String, Object> parameters;
    private final Boolean strict;
}

从类结构定义,以及真实测试之后,应该是 parameters对应了 inputSchema,但是没有 outputSchema。

在某些特殊情况下,比如 会在outputSchema的说明里面定义各种单位,可能不同的tool的单位定义不一样;如果获取不到 outputSchema,agent/llm 拿不到具体的 output定义,返回的推理和结论可能就会出现问题。

参考 腾讯 solon ai 中,在 MethodFunctionTool 是实现了 outputSchema 的支持的:

public class MethodFunctionTool implements FunctionTool {
    static final Logger log = LoggerFactory.getLogger(MethodFunctionTool.class);
    private final BeanWrap beanWrap;
    private final MethodWrap methodWrap;
    private final Type returnType;
    private final String name;
    private final String title;
    private final String description;
    private final Map<String, Object> meta = new HashMap();
    private final boolean returnDirect;
    private final Map<String, ParamDesc> params;
    private final ToolCallResultConverter resultConverter;
    private final String inputSchema;
    private String outputSchema;
}

请问这块是否有考虑支持或者计划支持呢。

bgy675939778 avatar Apr 12 '26 07:04 bgy675939778

I traced this locally and confirmed the gap: MCP already exposes McpSchema.Tool.outputSchema(), but the current registration path only carries inputSchema -> ToolSchema.parameters, so Toolkit.getToolSchemas() drops MCP output schemas entirely.

I'm working on a fix that threads optional outputSchema through the MCP registration / ToolSchema pipeline and adds regression tests around MCP tool registration and schema exposure.

Alexxigang avatar Apr 13 '26 15:04 Alexxigang

Opened PR: https://github.com/agentscope-ai/agentscope-java/pull/1221

This carries the MCP output-schema support discussed here and includes targeted regression coverage.

Alexxigang avatar Apr 14 '26 11:04 Alexxigang

Hi, I'd like to work on this issue. My proposed scope is:

  1. Add optional outputSchema support to ToolSchema while preserving backward compatibility.
  2. Propagate MCP tools/list outputSchema during MCP tool registration.
  3. Add tests for schemas with and without outputSchema.
  4. Update the MCP documentation/example if needed.

Could a maintainer confirm whether outputSchema should only be exposed as metadata to the model, or also be used for runtime result validation?

If this scope is aligned, please assign the issue to me.

wangxuefen88 avatar Jul 27 '26 10:07 wangxuefen88