Skip to content

fix(mcp): preserve tool identities and result diagnostics - #3796

Open
Buktal wants to merge 7 commits into
agentscope-ai:mainfrom
Buktal:codex/tool-contracts
Open

Buktal wants to merge 7 commits into
agentscope-ai:mainfrom
Buktal:codex/tool-contracts

Conversation

@Buktal

@Buktal Buktal commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

AgentScope-Java Version

2.1.0-SNAPSHOT

Description

Refs #3794, MCP review unit. MCP registration can silently overwrite an existing tool, while prefixed names can violate provider constraints. Result conversion can also lose structured or non-text error diagnostics.

Summary

selected remote tools
  -> derive model-facing names -> validate the complete server batch -> register
model-facing call -> original remote name
MCP response -> explicit state + text / structured / supported non-text diagnostics
  • Normalize names only when prefixing is enabled. Preserve valid names; add a stable identity suffix when normalization or the 64-character limit changes a name. Keep execution names and server-level filters tied to original remote identities.
  • Reject duplicate model-facing names before registering any tool from that server. Share the registry mutation lock across preflight/registration and concurrent writers.
  • Preserve MCP isError, structured JSON, supported non-text content, and resource-link name/URI/description. Protocol _meta is not exposed to the model.
  • Update English and Chinese tool/workspace documentation.

Evidence

  • Before: MCP clients could overwrite tools and publish invalid names; error conversion could drop diagnostics beyond text.
    After: McpNamespacedToolTest, McpContentConverterTest, and McpServerRegistrarTest cover normalization, original execution/filter names, atomic conflict rejection, concurrent registration, and model-visible error content.
  • Independent snapshot: mvn -B -T1C clean verify passed across all 99 modules: 11,321 tests, 0 failures/errors, 242 skipped, including Spotless without skip flags. Docs tests (13/13), static checks (432 pages, 584 redirects), and Mintlify validation passed. npm run broken-links still reports 2,218 links across 326 files, matching the previous counts; individual links were not baseline-attributed.
  • Includes the shared three-line my_skill -> my-skill fixture correction required by fix(skill): block path traversal in skill materialization and disambiguate skillId #3787/fix(skill): move blocking skill reload off reactive event-loop threads #3792. Existing thread/cache assertions and production validation are retained.
  • An initial full check hit a 10-second timeout in the unchanged WeixinChannelLoopbackTest; its standalone two-test rerun passed. The complete check was then rerun for this snapshot.

Merge Danger

Door: two-way

MCP duplicate-name handling changes compatibility: registration fails instead of overwriting, including with prefixing disabled. Use distinct prefixes or server-level enableTools/disableTools filters to resolve conflicts. Global allow/deny runs after registration. Optional servers report failure and bootstrap continues; required servers abort bootstrap.

Blast Radius: MCP

No state migration. Addresses the MCP portion of #3328; local-to-local replacement semantics remain separate.

Checklist

  • Spotless formatting check passes in full verification
  • All executed tests pass; skipped count reported above
  • Javadoc and English/Chinese documentation updated
  • Code ready for review

@mintlify

mintlify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit a43b17f.

Approve preview

@Buktal
Buktal force-pushed the codex/tool-contracts branch from 621ddb0 to 7106f79 Compare October 27, 2026 06:21
@Buktal Buktal changed the title fix: preserve tool outcomes and MCP registration identities fix(mcp): preserve tool identities and result diagnostics Oct 27, 2026
@Buktal
Buktal marked this pull request as ready for review October 27, 2026 06:21
@jujn

jujn commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

May be overlap: #3332

jujn pushed a commit that referenced this pull request Oct 28, 2026
## Description

Refs #3794, tool-feedback review unit. Successful void calls can yield
ambiguous empty/null feedback, PostActing block replacements can miss
stored/model-visible history, and Anthropic tool-result formatting can
lose explicit failure states.

## Summary

```text
tool invocation -> await declared-void completion -> explicit acknowledgement
PostActing replacement -> resulting message -> stored / next-request feedback
Anthropic client-tool result -> explicit failure state -> is_error
```

- Acknowledge successful `void`/`Void`, `Mono<Void>`, and
`CompletableFuture<Void>` calls with `(completed with no output)`.
Conversion runs after completion; ordinary null returns, non-void empty
completion, errors, and cancellation retain their contracts.
- Propagate `PostActingEvent.setToolResult` into the resulting message
unless the hook explicitly replaces that message. Cover non-streaming,
streaming, and stop behavior; already emitted deltas and `returnDirect`
retain their contracts.
- Map Anthropic ERROR/DENIED/INTERRUPTED client-tool results to
`is_error`, preserving IDs/output blocks and the separate server-tool
conversion path.
- Update English and Chinese tool/middleware documentation. MCP
registration/result conversion is covered by #3796.
# Conflicts:
#	agentscope-harness/src/test/java/io/agentscope/harness/agent/tools/McpServerRegistrarTest.java
#	docs/v2/en/docs/harness/workspace.md
#	docs/v2/zh/docs/harness/workspace.md
@jujn jujn added the P2 重要不紧急 label Nov 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 重要不紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants