Skip to content

feat(mcp): 添加elicitation功能支持#798

Merged
LearningGp merged 6 commits into
agentscope-ai:mainfrom
miniceM:feature-mcp-elicitation
Apr 8, 2026
Merged

feat(mcp): 添加elicitation功能支持#798
LearningGp merged 6 commits into
agentscope-ai:mainfrom
miniceM:feature-mcp-elicitation

Conversation

@miniceM
Copy link
Copy Markdown
Contributor

@miniceM miniceM commented Feb 13, 2026

#797

  • 在McpClientBuilder中添加asyncElicitation和syncElicitation方法
  • 更新文档说明elicitation特性和使用示例
  • 添加完整的单元测试验证elicitation功能

AgentScope-Java Version

1.0.10-SNAPSHOT

Description

为 McpClientBuilder 添加了 MCP 官方 SDK 定义的 elicitation 功能支持。

核心变更

修改了 McpClientBuilder.java:

新增导入
io.modelcontextprotocol.spec.McpSchema.ElicitRequest
io.modelcontextprotocol.spec.McpSchema.ElicitResult
java.util.function.Function

新增字段
asyncElicitationHandler: 用于异步客户端的 elicitation handler
syncElicitationHandler: 用于同步客户端的 elicitation handler

新增方法
asyncElicitation(Function<ElicitRequest, Mono> handler): 注册异步 elicitation handler
syncElicitation(Function<ElicitRequest, ElicitResult> handler): 注册同步 elicitation handler

修改 buildAsync() 方法
当 asyncElicitationHandler 不为 null 时,在 ClientCapabilities.builder() 中调用 .elicitation()
当 asyncElicitationHandler 不为 null 时,在 McpClient.async() builder 中调用 .elicitation(asyncElicitationHandler)

修改 buildSync() 方法
当 syncElicitationHandler 不为 null 时,在 ClientCapabilities.builder() 中调用 .elicitation()
当 syncElicitationHandler 不为 null 时,在 McpClient.sync() builder 中调用 .elicitation(syncElicitationHandler)

新增单元测试 McpClientBuilderTest 类中相关测试方法
测试命令

mvn test -pl agentscope-core -Dtest='McpClientBuilderTest#test*Elicitation*'

更新了中英两版 mcp.md 文件,添加了使用示例。

- 在McpClientBuilder中添加asyncElicitation和syncElicitation方法
- 更新文档说明elicitation特性和使用示例
- 添加完整的单元测试验证elicitation功能
@miniceM miniceM requested a review from a team February 13, 2026 07:22
@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented Feb 13, 2026

CLA assistant check
All committers have signed the CLA.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @miniceM, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在为 MCP 客户端构建器(McpClientBuilder)引入 elicitation 功能支持。通过此功能,MCP 客户端能够在与服务器端工具交互过程中,实现交互式的信息收集。这增强了客户端的灵活性,允许开发者根据业务需求处理异步或同步的 elicitation 请求,从而提升了 MCP 客户端在复杂场景下的应用能力。

Highlights

  • Elicitation 功能支持: 在 McpClientBuilder 中添加了 asyncElicitationsyncElicitation 方法,用于注册异步和同步的 elicitation 请求处理器。
  • 客户端能力自动启用: 更新了 McpClientBuilderbuildAsync()buildSync() 方法,使其能够根据是否注册了 elicitation 处理器来自动启用客户端的 elicitation 能力并注册相应的处理器。
  • 新导入和字段: 引入了 ElicitRequestElicitResultFunction 等必要的导入,并新增了 asyncElicitationHandlersyncElicitationHandler 字段,以支持 elicitation 功能的实现。
  • 单元测试覆盖: 为 McpClientBuilderTest 添加了全面的单元测试,以验证 asyncElicitationsyncElicitation 功能的正确性。
  • 文档更新: 更新了英文和中文版的 mcp.md 文档,详细说明了 elicitation 特性及其使用示例。
Changelog
  • agentscope-core/src/main/java/io/agentscope/core/tool/mcp/McpClientBuilder.java
    • 新增了 asyncElicitationHandlersyncElicitationHandler 字段。
    • 添加了 asyncElicitationsyncElicitation 方法。
    • 修改了 buildAsync()buildSync() 方法,以在存在 elicitation 处理器时启用 elicitation 能力并注册处理器。
    • 导入了 ElicitRequestElicitResultFunction 类。
    • 调整了 Javadoc 中的格式。
  • agentscope-core/src/test/java/io/agentscope/core/tool/mcp/McpClientBuilderTest.java
    • 新增了针对 asyncElicitationsyncElicitation 方法的单元测试。
    • 调整了现有测试方法的 Javadoc 格式。
  • docs/en/task/mcp.md
    • 添加了关于 elicitation 功能的英文说明和异步/同步客户端的使用示例。
  • docs/zh/task/mcp.md
    • 添加了关于 elicitation 功能的中文说明和异步/同步客户端的使用示例。
Activity
  • 暂无活动记录。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

这个 PR 很好地为 McpClientBuilder 添加了 elicitation 功能的支持,包括核心逻辑、单元测试和文档更新。代码整体质量很高。

我提出了一些改进建议:

  1. McpClientBuilder.java 中,buildAsyncbuildSync 方法中存在一些重复代码,建议通过提取辅助方法来优化,以提高代码的可维护性。
  2. 在英文文档 docs/en/task/mcp.md 中,新添加的部分存在中英文混用的情况,建议统一为英文,以保证文档的一致性。

这些修改将有助于进一步提升代码质量和文档的清晰度。

Comment thread agentscope-core/src/main/java/io/agentscope/core/tool/mcp/McpClientBuilder.java Outdated
Comment thread docs/en/task/mcp.md Outdated
- 提取客户端功能构建为独立的私有方法 buildCapabilities
- 简化异步和同步客户端构建中的重复代码
- 将文档中的中文注释翻译为英文
- 调整了 McpClientBuilder 中客户端功能构建的代码缩进
- 改进了版本测试中断言语句的代码布局
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Collaborator

@LearningGp LearningGp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we provide a default implementation for ElicitationHandler (perhaps feeding back to the Model)? This could be handled in a separate PR—let me know if you'd be interested in taking that on.

Comment thread docs/en/task/mcp.md Outdated
@LearningGp LearningGp added this to the 1.0.12 milestone Apr 7, 2026
@miniceM
Copy link
Copy Markdown
Contributor Author

miniceM commented Apr 7, 2026

Should we provide a default implementation for ElicitationHandler (perhaps feeding back to the Model)? This could be handled in a separate PR—let me know if you'd be interested in taking that on.

ok, I will take it

Updated section title from 'elicitation 支持' to 'elicitation support' for consistency.
Copy link
Copy Markdown
Collaborator

@LearningGp LearningGp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LearningGp
Copy link
Copy Markdown
Collaborator

**miniceM **

Please reply to the issue if you are interested in taking this on.#1159

@LearningGp LearningGp merged commit c455436 into agentscope-ai:main Apr 8, 2026
5 checks passed
liangxingguang pushed a commit to liangxingguang/agentscope-java that referenced this pull request May 21, 2026
agentscope-ai#797 
- 在McpClientBuilder中添加asyncElicitation和syncElicitation方法
- 更新文档说明elicitation特性和使用示例
- 添加完整的单元测试验证elicitation功能

## AgentScope-Java Version

<revision>1.0.10-SNAPSHOT</revision>

## Description

为 McpClientBuilder 添加了 MCP 官方 SDK 定义的 elicitation 功能支持。

### 核心变更
修改了 McpClientBuilder.java:

新增导入
io.modelcontextprotocol.spec.McpSchema.ElicitRequest
io.modelcontextprotocol.spec.McpSchema.ElicitResult
java.util.function.Function

新增字段
asyncElicitationHandler: 用于异步客户端的 elicitation handler
syncElicitationHandler: 用于同步客户端的 elicitation handler

新增方法
asyncElicitation(Function<ElicitRequest, Mono> handler): 注册异步
elicitation handler
syncElicitation(Function<ElicitRequest, ElicitResult> handler): 注册同步
elicitation handler

修改 buildAsync() 方法
当 asyncElicitationHandler 不为 null 时,在 ClientCapabilities.builder() 中调用
.elicitation()
当 asyncElicitationHandler 不为 null 时,在 McpClient.async() builder 中调用
.elicitation(asyncElicitationHandler)

修改 buildSync() 方法
当 syncElicitationHandler 不为 null 时,在 ClientCapabilities.builder() 中调用
.elicitation()
当 syncElicitationHandler 不为 null 时,在 McpClient.sync() builder 中调用
.elicitation(syncElicitationHandler)

新增单元测试 McpClientBuilderTest 类中相关测试方法
测试命令 
```
mvn test -pl agentscope-core -Dtest='McpClientBuilderTest#test*Elicitation*'
```

更新了中英两版 mcp.md 文件,添加了使用示例。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants