Skip to content

[Bug] Component meta is dropped when a resource returns list[ResourceContent] #5842

Closed

Description

@BlueX888

Summary

A function resource that declares component-level meta= (for example MCP Apps UI CSP/permissions or team metadata) and returns the documented list[ResourceContent] shape loses all component meta on reads: every returned item has meta=None. The same meta is present in list_resources and is propagated correctly for str, bytes, and JSON-native returns, so only the list shape is affected. Resource templates have the same gap because they share the conversion helper.

Reproduction (current main adf90b6, offline)

from fastmcp import FastMCP, Client
from fastmcp.resources import ResourceContent

mcp = FastMCP("repro")

@mcp.resource("data://multi/{id}", meta={"ui": {"csp": "default-src none"}, "team": "infra"})
def multi(id): return [ResourceContent("a"), ResourceContent("b", meta={"own": 1})]

Reading data://multi/1 through a Client:

  • actual: [None, {'own': 1}]
  • expected: [{'ui': {'csp': 'default-src none'}, 'team': 'infra'}, {'ui': ..., 'team': 'infra', 'own': 1}] — item-level meta wins on conflicts

Root cause

fastmcp_slim/fastmcp/resources/base.py (convert_raw_to_resource_result, ~lines 269-303) computes public_result_meta(meta) and attaches it to the str/bytes and JSON-native paths, but non-empty list[ResourceContent] is explicitly excluded from the JSON branch and falls through to ResourceResult(raw_value), which preserves the items verbatim and drops component meta. ResourceTemplate.convert_result (resources/template.py:484-498) calls the same helper and inherits the bug.

Suggested fix

Add an explicit non-empty list[ResourceContent] branch before the fallthrough: validate the list through ResourceResult(raw_value) (preserving the existing error for non-ResourceContent members), then merge public_result_meta(meta) into each item with item-level keys taking precedence, copying items rather than mutating caller-owned objects. str/bytes/empty-list behavior stays unchanged.

Tests

A fix with five regression tests is ready (component meta on two bare items, item-level override, str control, empty-list control, and the template variant). I'll open the linked PR with red/green evidence.

Activity

  1. added
    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.
    on Oct 19, 2026
  2. added a commit that references this issue on Oct 19, 2026
    f01957f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions