Skip to content

Add round-trip integration tests for MCP Apps _meta.ui serialization#1698

Open
yayayouyou wants to merge 2 commits into
modelcontextprotocol:mainfrom
yayayouyou:test/mcp-apps-meta-ui-roundtrip
Open

Add round-trip integration tests for MCP Apps _meta.ui serialization#1698
yayayouyou wants to merge 2 commits into
modelcontextprotocol:mainfrom
yayayouyou:test/mcp-apps-meta-ui-roundtrip

Conversation

@yayayouyou

Copy link
Copy Markdown

Fixes #1608.

Summary

Adds the round-trip integration coverage requested in #1608 (from @halter73's review comment on #1484): all existing _meta.ui tests are unit tests on the option pipeline, so nothing verified the metadata actually survives serialization through McpClient.ListToolsAsync().

New McpAppsIntegrationTests (via ClientServerTestBase) registers tools with [McpAppUi] behind WithTools<T>().WithMcpApps() and asserts, after the client/server wire round-trip:

  • _meta.ui.resourceUri is present and correctly shaped for an attributed tool, with visibility omitted when not restricted
  • _meta.ui.visibility round-trips for a [McpAppUi(Visibility = [McpUiToolVisibility.Model])] tool
  • tools without the attribute carry no ui metadata

Testing

  • dotnet test --filter FullyQualifiedName~McpAppsIntegrationTests: 3/3 pass on net10.0 locally; net8.0/net9.0 targets compile but were not run locally (runtimes not installed on this machine — CI covers them)
  • dotnet format --verify-no-changes clean on the new file

Used AI assistance; reviewed and tested by me.

🤖 Generated with Claude Code

Covers the gap called out in modelcontextprotocol#1608: tools registered with [McpAppUi] and
processed by WithMcpApps() are listed through McpClient.ListToolsAsync()
via ClientServerTestBase, verifying the structured _meta.ui object
end-to-end across the transport rather than only on the option pipeline:

- resourceUri round-trips for an attributed tool
- visibility round-trips for a restricted tool (and is omitted when not
  restricted)
- tools without the attribute stay free of ui metadata

Used AI assistance; reviewed and tested by me (3/3 pass on net10.0
locally; net8.0/net9.0 compile but need runtimes not installed locally).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 10, 2026 13:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds end-to-end (client/server wire) integration coverage ensuring MCP Apps _meta.ui tool metadata survives JSON serialization when enumerated via McpClient.ListToolsAsync(), addressing the gap noted in #1608.

Changes:

  • Introduces McpAppsIntegrationTests based on ClientServerTestBase to round-trip ListToolsAsync() results.
  • Validates _meta.ui.resourceUri is preserved and _meta.ui.visibility round-trips when configured.
  • Verifies tools without [McpAppUi] do not emit UI metadata.

Comment on lines +45 to +46
// Visibility was not restricted, so the attribute must not add the property.
Assert.Null(uiNode["visibility"]);

var plainTool = Assert.Single(tools, t => t.Name == "plain_tool");

Assert.Null(plainTool.ProtocolTool.Meta?["ui"]);
Address Copilot review on modelcontextprotocol#1698: Assert.Null on a JsonObject indexer
passes both when a key is absent and when it is serialized as JSON null,
which doesn't prove the intended omission. Assert the "visibility" and
"ui" keys are not present at all (ContainsKey) so the tests fail if the
server ever emits an explicit null.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

MCP Apps: Add round-trip integration test for _meta.ui serialization

2 participants