
dtyq/php-mcp
Developer toolsこのページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る
サーバとクライアントのサポート、STDIO、HTTP トランスポート、フレームワークの統合で、モデルコンテキストプロトコル(MCP)の完全な PHP 実装
概要
複数のトランスポートプロトコルをサポートし、サーバーとクライアントの両方の機能を提供する、完全なPHPの実装。 - MCP 2025-03-26 仕様をサポート - ➽ - ツール、リソース、およびプロンプトのサポート - 🔌 - STDIO ✅、HTTP ✅、ストリーミング可能な HTTP ◀ - PSR 準拠フレームワーク、組み込みのHyperf統合で動作 - 英語と中国語の包括的なガイド Hyperfフレームワークを使用している場合、統合は非常に簡単です。 : - 🔐 - カスタム認証 - 動的ツール/リソース登録 - 自動登録ツール、リソース、プロンプト Hyperfインテグレーションガイドを見る - - すべてのガイドと参照 - - アーキテクチャ、機能、およびユースケース - - 5分のチュートリアル - MCPサーバーの構築 - MCPクライアントを作成 /examplesディレクトリ: - stdio-server-test.php - 完全なSTDIOサーバー - http-server-test.php - ツール付きのHTTPサーバー - stdio-client-test.php - STDIOクライアント例 - http-client-test.php - HTTPクライアント例 - : 7.
概要(AI 翻訳)
Model Context Protocol (MCP) の完全な PHP の実装で、複数のトランスポートプロトコルをサポートするサーバーとクライアントの両方の機能を提供します。
言語:英語
✨ 主な特長
- OST 最新MCPプロトコル - MCP 2025-03-26仕様をサポート ツール、リソース、プロンプトのサポート
- 🔌 マルチプルトランスポート - STDIO ✅, HTTP ✅, ストリーミング可能なHTTP ◀
- バックアップFramework互換 - PSR準拠フレームワーク、内蔵Hyperf統合で動作します
- 英語と中国語の包括的なガイド
すぐにスタート
インストール
##Hyperfフレームワーククイック統合
Hyperfフレームワークを使用している場合、統合は非常に簡単です。
注意に基づく登録:
高度なオプション:
- 🔐AuthenticatorInterface - カスタム認証
- HttpTransportAuthenticatedEvent** - 動的ツール/リソース登録
- リリース**
Hyperfインテグレーションガイドを見る
##基本サーバ例
##基本クライアント例
代替方法:
ドキュメント
このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。
README
以下は原文 README の抜粋です。原文を見る。
PHP MCP
A complete PHP implementation of the Model Context Protocol (MCP), providing both server and client functionality with support for multiple transport protocols.
✨ Key Features
- 🚀 Latest MCP Protocol - Supports MCP 2025-03-26 specification
- 🔧 Complete Implementation - Tools, resources, and prompts support
- 🔌 Multiple Transports - STDIO ✅, HTTP ✅, Streamable HTTP 🚧
- 🌐 Framework Compatible - Works with any PSR-compliant framework, built-in Hyperf integration
- 📚 Well Documented - Comprehensive guides in English and Chinese
🚀 Quick Start
Installation
composer require dtyq/php-mcp
Hyperf Framework Quick Integration
If you’re using Hyperf framework, integration is extremely simple:
// Just one line of code!
Router::addRoute(['POST', 'GET', 'DELETE'], '/mcp', function () {
return \Hyperf\Context\ApplicationContext::getContainer()->get(HyperfMcpServer::class)->handle('default');
});
Annotation-Based Registration:
class CalculatorService
{
#[McpTool(description: 'Mathematical calculations')]
public function calculate(string $operation, int $a, int $b): array
{
return ['result' => match($operation) {
'add' => $a + $b,
'multiply' => $a * $b,
default => 0
}];
}
#[McpResource(description: 'System information')]
public function systemInfo(): TextResourceContents
{
return new TextResourceContents('mcp://system/info',
json_encode(['php' => PHP_VERSION]), 'application/json');
}
}
Advanced Options:
- 🔐 AuthenticatorInterface - Custom authentication
- 📊 HttpTransportAuthenticatedEvent - Dynamic tool/resource registration
- 📝 Annotation System - Auto-register tools, resources and prompts
👉 View Complete Hyperf Integration Guide
Basic Server Example
<?php
require_once 'vendor/autoload.php';
use Dtyq\PhpMcp\Server\McpServer;
use Dtyq\PhpMcp\Shared\Kernel\Application;
// Create server with simple container
$container = /* your PSR-11 container */;
$app = new Application($container, ['sdk_name' => 'my-server']);
$server = new McpServer('my-server', '1.0.0', $app);
// Add a tool
$server->registerTool(
new \Dtyq\PhpMcp\Types\Tools\Tool('echo', [
インストール
This server does not publish a one-line install command.
Open the repository installation guide MCP 初心者?mcpskill.org のガイドから始めましょう →