Skip to content

Add WithAppTool helper for MCP Apps - #1815

Open
KirschBluteX wants to merge 2 commits into
modelcontextprotocol:mainfrom
KirschBluteX:feat/with-app-tool-1607
Open

Add WithAppTool helper for MCP Apps#1815
KirschBluteX wants to merge 2 commits into
modelcontextprotocol:mainfrom
KirschBluteX:feat/with-app-tool-1607

Conversation

@KirschBluteX

@KirschBluteX KirschBluteX commented Aug 13, 2026

Copy link
Copy Markdown

Fixes #1607

Summary

  • add WithAppTool to register a tool and its linked HTML app resource in one call
  • make resourceUri authoritative: require a concrete absolute ui:// URI, reject URI templates, and reject conflicting _meta.ui.resourceUri values
  • preserve other existing UI metadata and fill in a missing UI resource URI
  • reuse the existing resource delegate pipeline so HTML handlers can be synchronous or asynchronous and accept CancellationToken
  • document and verify that duplicate resource URIs use the first registered HTML handler

Behavior

If _meta.ui.resourceUri is present, it must exactly match resourceUri; otherwise registration throws ArgumentException. When the UI object exists without a resource URI, the helper adds the authoritative value while preserving fields such as visibility. This guarantees that every registered tool link identifies the resource that can actually be read.

The helper accepts direct UI resource URIs only. Resource templates belong to the lower-level resource APIs and are rejected here because an app tool links to one concrete UI resource.

Testing

  • dotnet test tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj -f net10.0 --no-restore --filter FullyQualifiedName~WithAppTool (15 passed)
  • dotnet test tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj -f net10.0 --no-restore --filter FullyQualifiedName~McpApps (48 passed)
  • dotnet test tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj -f net10.0 --no-build --no-restore --filter (Execution!=Manual) (2371 passed)
  • dotnet build src/ModelContextProtocol.Extensions.Apps/ModelContextProtocol.Extensions.Apps.csproj --configuration Release --no-restore --no-incremental (4 projects, 0 warnings, 0 errors)
  • scoped dotnet format whitespace --verify-no-changes for the three changed C# files

GitHub Actions currently reports action_required for this fork PR and has not started jobs; it is waiting for maintainer approval rather than reporting a test failure.

@KirschBluteX
KirschBluteX force-pushed the feat/with-app-tool-1607 branch from 7fc29e4 to f19fc75 Compare August 14, 2026 18:31
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 ergonomic WithAppTool helper to reduce wiring boilerplate

1 participant