承接 wordpress/php-mcp-schema 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

统计信息

  • 总下载量: 102.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2026-03-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固