Skip to content

MCP Apps: Add [McpAppResource] attribute and resource-collection processing in WithMcpApps() #1636

@mikekistler

Description

@mikekistler

From PR #1484 review comment by @halter73:

The tool-side has three layers (attribute → builder → programmatic), but resource-side currently only has programmatic (SetResourceUi). There's no [McpAppResource] attribute and WithMcpApps() doesn't process the resource collection.

Server authors using attribute-based registration currently fall back to raw JSON strings in [McpMeta] to set UI metadata on resources, bypassing the typed McpUiResourceMeta / McpUiResourceCsp types.

Preferred approach:
Add [McpAppResource] mirroring [McpAppUi] and extend WithMcpApps() to iterate options.ResourceCollection. Then the sample can drop the raw JSON and use:

[McpServerResource(...)]
[McpAppResource(ConnectDomains = new[] { "https://api.weather.gov" }, PrefersBorder = true)]
public static string GetWeatherForecastUi() => ...;

Minimum:
Update the sample to call SetResourceUi() from a manual-registration code path in Program.cs so the typed types are exercised somewhere in user-facing docs.

Related to #1607.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions