wordpress/php-mcp-schema
Composer 安装命令:
composer require wordpress/php-mcp-schema
包简介
PHP DTOs for the Model Context Protocol (MCP) specification
README 文档
README
A PHP representation of the Model Context Protocol (MCP) schema types.
This package provides Data Transfer Objects (DTOs), Enums, and Unions that mirror the official MCP TypeScript schema. It is not an SDK, client, or server implementation; just the type definitions for building your own MCP-compatible applications in PHP.
Installation
composer require wordpress/php-mcp-schema
Requires PHP 7.4 or higher.
Usage
Creating a Tool Definition
use WP\McpSchema\Server\Tools\DTO\Tool; $tool = Tool::fromArray([ 'name' => 'get_weather', 'description' => 'Get current weather for a location', 'inputSchema' => [ 'type' => 'object', 'properties' => [ 'location' => ['type' => 'string', 'description' => 'City name'], ], 'required' => ['location'], ], ]);
Serialization (toArray)
Convert a DTO to a plain array for JSON encoding:
use WP\McpSchema\Server\Tools\DTO\Tool; $tool = Tool::fromArray([ 'name' => 'get_weather', 'description' => 'Get current weather for a location', 'inputSchema' => ['type' => 'object', 'properties' => []], ]); $array = $tool->toArray(); $json = json_encode($array); // Ready to send over the wire
Deserialization (fromArray)
Decode incoming JSON into a fully typed DTO:
use WP\McpSchema\Server\Tools\DTO\CallToolRequest; $json = '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_weather","arguments":{"location":"Paris"}}}'; $data = json_decode($json, true); $request = CallToolRequest::fromArray($data); $tool_name = $request->getTypedParams()->getName(); // "get_weather" $arguments = $request->getTypedParams()->getArguments(); // ['location' => 'Paris']
Factory / Union Types
Use a factory to resolve polymorphic content blocks without knowing the concrete type up front:
use WP\McpSchema\Common\Protocol\Factory\ContentBlockFactory; use WP\McpSchema\Common\Content\DTO\TextContent; $block = ContentBlockFactory::fromArray(['type' => 'text', 'text' => 'Hello, world!']); // $block implements ContentBlockInterface; cast when you need the concrete API if ($block instanceof TextContent) { echo $block->getText(); // "Hello, world!" }
JSON-RPC Messages
Construct a generic JSON-RPC request for any MCP method:
use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCRequest; $request = JSONRPCRequest::fromArray([ 'jsonrpc' => '2.0', 'id' => 1, 'method' => 'tools/list', ]); $json = json_encode($request->toArray());
Available Types
Server Types (WP\McpSchema\Server\)
- Tools -
Tool,CallToolRequest,CallToolResult,ListToolsRequest,ListToolsResult - Resources -
Resource,ResourceTemplate,ReadResourceRequest,ReadResourceResult - Prompts -
Prompt,PromptMessage,GetPromptRequest,GetPromptResult - Logging -
LoggingMessageNotification,SetLevelRequest
Client Types (WP\McpSchema\Client\)
- Sampling -
CreateMessageRequest,CreateMessageResult,SamplingMessage - Elicitation -
ElicitRequest,ElicitResult - Roots -
ListRootsRequest,ListRootsResult,Root
Common Types (WP\McpSchema\Common\)
- Protocol -
InitializeRequest,InitializeResult,PingRequest - Content -
TextContent,ImageContent,AudioContent - JSON-RPC -
JSONRPCRequest,JSONRPCNotification,JSONRPCResultResponse,JSONRPCErrorResponse
Generator
The PHP code in src/ is auto-generated from the official MCP TypeScript schema. The generator is located in the generator/ directory and is not included in the Composer package.
See generator/README.md for setup and usage instructions.
License
GPL-2.0-or-later - see LICENSE.md for details.
Links
wordpress/php-mcp-schema 适用场景与选型建议
wordpress/php-mcp-schema 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 102.36k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2026 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「schema」 「dto」 「mcp」 「model-context-protocol」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wordpress/php-mcp-schema 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wordpress/php-mcp-schema 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wordpress/php-mcp-schema 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Extension for Opis JSON Schema
PHP library for the MUMSYS project
EAV modeling package for Eloquent and Laravel.
A simple library that allows transform any kind of data to native php data or whatever
serialize Symfony Forms into JSON schema
Build forms from schema
统计信息
- 总下载量: 102.36k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 5
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2026-03-18