[Schema][Server] Add MCP Apps extension (io.modelcontextprotocol/ui) support (#281)
* feat: add MCP Apps extension (io.modelcontextprotocol/ui) support Adds support for the MCP Apps protocol extension, which lets servers expose interactive HTML UIs as resources rendered by spec-conforming clients (e.g. Goose) in sandboxed iframes. - Generic extension plumbing: ServerExtensionInterface and Builder::enableExtension(), with extensions advertised under capabilities.extensions during the initialize handshake. ClientCapabilities/ServerCapabilities gain an extensions field. - Schema DTOs under Mcp\Schema\Extension\Apps: the McpApps marker, UiToolMeta, ToolVisibility enum, UiResourceContentMeta, UiResourceCsp, and UiResourcePermissions (with empty-object presence markers per spec). - A worked weather example under examples/server/mcp-apps/ with a minimal spec-conforming view (ui/initialize handshake, postMessage JSONRPCMessage objects, and ResizeObserver-driven size reporting). - docs/extensions.md guide with pointers from index.md and examples.md to the ext-apps repository for the TypeScript SDK and richer view-side patterns. - Unit and inspector snapshot test coverage. Spec: https://github.com/modelcontextprotocol/ext-apps * Type UiToolMeta visibility as ToolVisibility enum Also fix UiResourceContentMeta::jsonSerialize() return phpdoc. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Address review nitpicks for MCP Apps extension Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Apply PR review feedback for MCP Apps extension Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Add regression tests and CHANGELOG entry for capabilities extensions - Pin the is_array() guards on extensions in ServerCapabilities and ClientCapabilities::fromArray() with explicit non-array payload tests. - Pin the isset()-rejects-null contract in UiResourcePermissions::fromArray(). - Surface the new extensions field on both capability classes in CHANGELOG. - Inline the ?: idiom in Builder::build() to match the surrounding style. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
0347dc85b4
commit
d150772e24
1 changed files with 1632 additions and 3 deletions
|
|
@ -20,7 +20,8 @@ namespace Mcp\Schema;
|
|||
class ClientCapabilities implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $experimental
|
||||
* @param array<string, mixed> $experimental
|
||||
* @param ?array<string, mixed> $extensions protocol extensions the client supports (e.g. io.modelcontextprotocol/ui)
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly ?bool $roots = false,
|
||||
|
|
@ -28,6 +29,7 @@ class ClientCapabilities implements \JsonSerializable
|
|||
public readonly ?bool $sampling = null,
|
||||
public readonly ?bool $elicitation = null,
|
||||
public readonly ?array $experimental = null,
|
||||
public readonly ?array $extensions = null,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -39,6 +41,7 @@ class ClientCapabilities implements \JsonSerializable
|
|||
* sampling?: bool,
|
||||
* elicitation?: bool,
|
||||
* experimental?: array<string, mixed>,
|
||||
* extensions?: array<string, mixed>,
|
||||
* } $data
|
||||
*/
|
||||
public static function fromArray(array $data): self
|
||||
|
|
@ -68,7 +71,8 @@ class ClientCapabilities implements \JsonSerializable
|
|||
$rootsListChanged,
|
||||
$sampling,
|
||||
$elicitation,
|
||||
$data['experimental'] ?? null
|
||||
\is_array($data['experimental'] ?? null) ? $data['experimental'] : null,
|
||||
\is_array($data['extensions'] ?? null) ? $data['extensions'] : null,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -78,6 +82,7 @@ class ClientCapabilities implements \JsonSerializable
|
|||
* sampling?: object,
|
||||
* elicitation?: object,
|
||||
* experimental?: object,
|
||||
* extensions?: object,
|
||||
* }|\stdClass
|
||||
*/
|
||||
public function jsonSerialize(): array|object
|
||||
|
|
@ -102,6 +107,10 @@ class ClientCapabilities implements \JsonSerializable
|
|||
$data['experimental'] = (object) $this->experimental;
|
||||
}
|
||||
|
||||
if ($this->extensions) {
|
||||
$data['extensions'] = (object) $this->extensions;
|
||||
}
|
||||
|
||||
return $data ?: new \stdClass();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue