feat: #3583087 Add generic metadata for MCP Apps
Tool API plugins cannot carry definition or result metadata separately from typed inputs and outputs. MCP Apps need UI resource metadata and presentation data, while other consumers may need their own metadata.
This MR adds optional meta to the Tool attribute, getMeta() / setMeta() to ToolDefinition, and metadata on execution results. Metadata is keyed by consumer; each consumer reads only its own entry. For example:
meta: ['mcp' => ['ui' => ['resourceUri' => 'ui://example/media-picker']]],The bridge should map only the mcp entry to MCP _meta; other consumers' entries are not sent to MCP clients. Tool API does not interpret MCP keys. Related work: MCP Server !89 and MCP Server Tool Bridge !28.
Metadata is stored unchanged, bypassing output validation and ToolOutputTransformEvent. Values must be JSON-encodable scalars, nulls, and arrays; entities belong in typed outputs so their transforms can produce handles. FormattedExecutableResult preserves metadata separately from formatted outputs. Metadata defaults to []; setMeta([]) clears it. tool:info --format=json exports the metadata map, using {} when empty.
Existing constructor and factory calls keep working because the new arguments are optional and trailing. We intentionally accept adding getMeta() to ToolResultInterface before rc1 rather than introducing a separate optional interface. Proposed rc1 release note: Implementations and decorators of ToolResultInterface must implement getMeta(): array, returning [] when unused.
Testing
- DDEV PHPUnit against current
1.0.x: 49 tests, 233 assertions pass across the result, definition, execution, and Drush info tests. Coverage includes multiple consumers, replacement/clearing, success/failure formatting, actual execution through the invocation runner, and populated/empty JSON exports. Existing PHPUnit doc-comment deprecation notices remain. - PHPCS (Drupal and DrupalPractice), PHPStan on the changed PHP files, and
git diff --checkpass.
AI disclosure
AI-Generated: Yes. OpenAI Codex generated portions of the implementation and tests and drafted this MR description under human guidance.
Closes #3583087