mcpField
S
Symfony Mcp Server

Symfony Mcp Server

ローカル
github.com/klapaudius生産性3216 週間前に更新

Symfony Mcp Server について

Symfony MCP Server は、SSE と StreamableHTTP で通信する Model Context Protocol サーバーを構築するための Symfony パッケージです。既存の Symfony アプリケーションのロジックを AI クライアントに公開したい開発者に向けられています。

主な機能

  1. 01ツール、プロンプト、リソースのサポート
  2. 02ツールから AI モデルを呼び出す Sampling
  3. 03長時間処理の進捗通知
  4. 04テキスト、画像、音声、リソースの出力形式
  5. 05Pub/Sub を用いたアダプター構成

活用シーン

  1. 01Symfony の業務ロジックを AI クライアントに公開
  2. 02実行中に LLM を呼び出すツールの構築
  3. 03長時間処理の進捗表示

MCP 対応

本パッケージは MCP サーバーとして動作し、SSE および StreamableHTTP のエンドポイントを通じて Claude Desktop などの MCP クライアントにツール、プロンプト、リソースを提供します。README では Discovery、Roots、Elicitation は現時点で未対応とされています。

設定

ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。

mcp.json · 共通設定
{
"mcpServers": {
"symfony": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/inspector"
]
}
}
}
起動コマンドnpx -y @modelcontextprotocol/inspector

ローカルサーバーにはマシン上の実行環境(Node.js 18 以上など)が必要です。設定ファイルの場所はクライアントごとに異なります。

パッケージ
npm@modelcontextprotocol/inspector

ツール

ツール一覧はまだ取得されていません

ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。

詳細

Symfony MCP サーバー

Model Context Protocol サーバーをシームレスに構築し、
インテリジェントな AI エージェントを構築するための、強力な Symfony パッケージです。
Symfony アプリケーションを、強力な AI 駆動型システムへと変革します

ビルドステータス カバレッジ ライセンス 最新の安定版 ダウンロード総数

🤖 Symfony アプリで AI エージェントの力を解き放つ

Symfony MCP Server を使用すると、推論し、判断を下し、アプリケーションのビジネスロジックと連携できる、インテリジェントでコンテキストを認識する AI エージェントを構築できます。Model Context Protocol(MCP)を実装することで、Symfony アプリケーションは、高度な AI 駆動型の自動化とインテリジェンスを実現するプラットフォームになります。

🎯 Symfony MCP Server でエージェントを構築する理由

静的なツールをインテリジェントなエージェントへ変革:

  • 🧠 AI による推論:ツールは実行中に LLM に問い合わせ、賢く判断できます
  • 🔄 動的な適応:エージェントはコンテキストとリアルタイム分析に基づいて動作を適応させます
  • 💡 複雑な問題解決:複雑なタスクを分解し、AI の支援を受けながら段階的に解決します
  • 🎨 クリエイティブな生成:ユーザーのニーズに合わせて進化するコンテンツやソリューションを生成します

エンタープライズグレードのセキュリティ:

  • 🔒 安全なトランスポート:本番環境では STDIO の代わりに StreamableHTTP と SSE を使用します
  • 🛡️ 保護された API:AI 機能を公開しながら、内部システムを安全に保ちます
  • 🎛️ きめ細かな制御:あらゆるレベルで認証、認可、アクセスを管理します

主な機能:

  • 🛠️ ツール:LLM が呼び出してアプリケーションと連携できる、強力な実行可能関数を作成します
  • 💬 プロンプト:AI の動作や対話を導く、会話のきっかけやテンプレートを定義します
  • 📚 リソース:AI が読み取り、推論できる構造化データやドキュメントを公開します
  • 🧠 サンプリング:ツールが実行中に AI モデルへ問い合わせ、インテリジェントな判断を下せるようにします
  • 📊 進捗のストリーミング:時間のかかる処理の進捗をリアルタイムで通知します
  • 🎨 マルチモーダルな結果:ツールからのテキスト、画像、音声、リソースの出力に対応します
  • 🔌 柔軟なアーキテクチャ:スケーラブルなデプロイに適した、Pub/Sub メッセージングを備えたアダプターベースの設計です

🚀 エージェント優先の機能

🧪 サンプリング:エージェント的な動作の中核(v1.4.0+)

思考し、推論できる自律型エージェントへ、ツールを変革します:

class IntelligentAnalyzer implements SamplingAwareToolInterface
{
    private SamplingClient $samplingClient;

    public function execute(array $arguments): ToolResultInterface
    {
        // Check if sampling is available
        if ($this->samplingClient !== null && $this->samplingClient->isEnabled()) {
            try {
                // Let AI analyze and reason about complex data
                $response = $this->samplingClient->createTextRequest(
                    "Analyze this data and suggest optimizations: {$arguments['data']}",
                    new ModelPreferences(
                        [['name' => 'claude-3-sonnet']],
                        0.3, // costPriority
                        0.8, // intelligencePriority
                        0.2  // speedPriority
                    ),
                    'You are a data analysis expert.',
                    2000
                );
                
                // Execute actions based on AI reasoning
                return new TextToolResult($response->getContent()->getText());
            } catch (\Exception $e) {
                // Fallback to basic analysis
                return new TextToolResult('Basic analysis: Data structure appears valid.');
            }
        }
        
        return new TextToolResult('Advanced analysis requires AI capabilities.');
    }
    
    public function setSamplingClient(SamplingClient $samplingClient): void
    {
        $this->samplingClient = $samplingClient;
    }
}
🛠️ ツールシステム:エージェントを構成する基本要素

AI エージェントが連携して実行できる、強力なツールを作成します:

  • StreamableToolInterface:時間のかかる処理の進捗をリアルタイムで更新します
  • 複数の結果に対応:テキスト、画像、音声、リソースを返します
  • 進捗通知:複雑なエージェント処理の実行中に、ユーザーへ状況を知らせます
  • 動的なツール検出:エージェントは機能に応じてツールを検出し、利用できます
🎭 エージェントの動作を決めるプロンプトエンジニアリング

高度なプロンプトシステムを通じて、エージェントの個性や動作を定義します。

  • コンテキスト認識型プロンプト:アプリケーションの状態に応じてエージェントの動作を導きます
  • マルチモーダル対応:テキスト、画像、音声、リソースベースのプロンプトに対応します
  • 動的なプロンプト生成:ユーザーとのやり取りに応じて適応するプロンプトです
📚 エージェントの記憶のためのリソース管理

エージェントが構造化された知識にアクセスできるようにします。

  • 動的なリソース読み込み:エージェントがデータにアクセスし、推論できます
  • テンプレートベースのリソース:コンテキストに基づいて、その場でリソースを生成します
  • マルチプロバイダー対応:ファイルシステム、データベース、API、またはカスタムプロバイダーに対応します

🎯 実際のエージェントの例

🔍 インテリジェントなコードレビューエージェント
class CodeReviewAgent implements SamplingAwareToolInterface
{
    private SamplingClient $samplingClient;

    public function execute(array $arguments): ToolResultInterface
    {
        // Check if sampling is available
        if ($this->samplingClient !== null && $this->samplingClient->isEnabled()) {
            try {
                // AI analyzes code for patterns, security, and best practices
                $review = $this->samplingClient->createTextRequest(
                    "Review this code for security vulnerabilities, performance issues, and suggest improvements: {$arguments['code']}",
                    new ModelPreferences(
                        [['name' => 'claude-3-sonnet']],
                        0.2, // costPriority
                        0.8, // intelligencePriority
                        0.2  // speedPriority
                    ),
                    'You are a senior code reviewer with expertise in security and performance.',
                    2000
                );
                
                // Generate actionable recommendations
                return new TextToolResult($this->formatReview($review->getContent()->getText()));
            } catch (\Exception $e) {
                // Fallback to basic analysis
                return new TextToolResult('Basic code review: Structure appears valid.');
            }
        }
        
        return new TextToolResult('Advanced code review requires AI capabilities.');
    }
    
    public function setSamplingClient(SamplingClient $samplingClient): void
    {
        $this->samplingClient = $samplingClient;
    }
}
📊 データ分析エージェント
class DataInsightAgent implements SamplingAwareToolInterface, StreamableToolInterface
{
    private SamplingClient $samplingClient;
    private ?ProgressNotifierInterface $progressNotifier = null;

    public function execute(array $arguments): ToolResultInterface
    {
        // Check if sampling is available
        if ($this->samplingClient !== null && $this->samplingClient->isEnabled()) {
            try {
                // Multi-step reasoning process
                $steps = [
                    'Identify patterns and anomalies',
                    'Generate statistical insights',
                    'Create visualizations',
                    'Recommend actions'
                ];
                $this->progressNotifier?->sendProgress(
                    progress: 0,
                    total: count($steps)+1,
                    message: "Analyzing dataset..."
                );
                
                $insights = [];
                foreach ($steps as $i => $step) {
                    $response = $this->samplingClient->createTextRequest(
                        "$step for this data: {$arguments['data']}",
                        new ModelPreferences(
                            [['name' => 'claude-3-sonnet']],
                            0.2, // costPriority
                            0.8, // intelligencePriority
                            0.2  // speedPriority
                        ),
                        'You are a data analysis expert.',
                        2000
                    );
                    $insights[] = $response->getContent()->getText();
                    $this->progressNotifier?->sendProgress(
                        progress: $i+1,
                        total: count($steps)+1,
                        message: $step
                    );
                }
                
                return new TextToolResult($this->compileReport($insights));
            } catch (\Exception $e) {
                return new TextToolResult('Basic data analysis: Dataset appears well-formed.');
            }
        }
        
        return new TextToolResult('Advanced data analysis requires AI capabilities.');
    }
    
    public function setSamplingClient(SamplingClient $samplingClient): void
    {
        $this->samplingClient = $samplingClient;
    }
    
    public function setProgressNotifier(ProgressNotifierInterface $progressNotifier): void
    {
        $this->progressNotifier = $progressNotifier;
    }
}
🤝 カスタマーサポートエージェント
class SupportAgent implements SamplingAwareToolInterface
{
    private SamplingClient $samplingClient;

    public function execute(array $arguments): ToolResultInterface
    {
        // Check if sampling is available
        if ($this->samplingClient !== null && $this->samplingClient->isEnabled()) {
            try {
                // Load customer context
                $context = $this->loadCustomerHistory($arguments['customer_id']);
                
                // AI determines best response strategy
                $response = $this->samplingClient->createTextRequest(
                    "Customer issue: {$arguments['issue']}\nHistory: $context\nDetermine the best resolution approach.",
                    new ModelPreferences(
                        [['name' => 'claude-3-sonnet']],
                        0.2, // costPriority
                        0.8, // intelligencePriority
                        0.2  // speedPriority
                    ),
                    'You are an expert customer support agent.',
                    2000
                );
                
                // Send back the strategy for user approval
                return new TextToolResult($response->getContent()->getText());
            } catch (\Exception $e) {
                return new TextToolResult('Standard support response: We will review your issue and respond within 24 hours.');
            }
        }
        
        return new TextToolResult('Personalized support requires AI capabilities.');
    }
    
    public function setSamplingClient(SamplingClient $samplingClient): void
    {
        $this->samplingClient = $samplingClient;
    }
}

🚀 クイックスタート:最初のエージェントを構築する

1. 必要条件
  • PHP >=8.2
  • Symfony >=6.4
2. Symfony MCP サーバーをインストールする
設定ファイル config/packages/klp_mcp_server.yaml を作成し、以下を貼り付けます。
```yaml
klp_mcp_server:
    enabled: true
    server:
        name: 'My MCP Server'
        version: '1.0.0'
    default_path: 'mcp'
    ping:
        enabled: true  # 無効にする前に、デフォルト設定ファイルの警告セクションを読んでください
        interval: 30
    server_providers: ['streamable_http','sse']
    sse_adapter: 'cache'
    adapters:
        cache:
            prefix: 'mcp_sse_'
            ttl: 100
    tools:
        - KLP\KlpMcpServer\Services\ToolService\Examples\CodeAnalyzerTool     # エージェント型ツールのサンプル
        - KLP\KlpMcpServer\Services\ToolService\Examples\HelloWorldTool
        - KLP\KlpMcpServer\Services\ToolService\Examples\ProfileGeneratorTool
        - KLP\KlpMcpServer\Services\ToolService\Examples\SearchResultsTool
        - KLP\KlpMcpServer\Services\ToolService\Examples\StreamingDataTool
        - KLP\KlpMcpServer\Services\ToolService\Examples\VersionCheckTool
    prompts:
        - KLP\KlpMcpServer\Services\PromptService\Examples\CodeReviewPrompt   # エージェント型プロンプトのサンプル
        - KLP\KlpMcpServer\Services\PromptService\Examples\HelloWorldPrompt
    resources:
        - KLP\KlpMcpServer\Services\ResourceService\Examples\HelloWorldResource
        - KLP\KlpMcpServer\Services\ResourceService\Examples\ProjectSummaryResource # エージェント型リソースのサンプル
    resources_templates:
        - KLP\KlpMcpServer\Services\ResourceService\Examples\DynamicAnalysisResource # エージェント型リソーステンプレートのサンプル
        - KLP\KlpMcpServer\Services\ResourceService\Examples\McpDocumentationResource
```

詳しい説明については、デフォルト設定ファイルをこちらのリンクから開いてください。

Composer を使ってパッケージをインストールします。
composer require klapaudius/symfony-mcp-server
config/routes.yaml にルートを追加します
klp_mcp_server:
    resource: '@KlpMcpServerBundle/Resources/config/routes.php'
    type: php

これで完了です! このセットアップを完了すると、プロジェクトに3つの新しいAPIエンドポイントが追加されます。

  • MCP クライアント用ストリーミングエンドポイント:GET /{default_path}/sse
  • リクエスト送信エンドポイント:POST /{default_path}/messages
  • ストリーミング可能なHTTPエンドポイント:GET|POST /{default_path}
Docker のセットアップ(任意)

このプロジェクトには、開発に使用できる Docker セットアップが含まれています。Docker セットアップには、Nginx、Redis 拡張機能を備えた PHP-FPM、および Redis サーバーが含まれています。

Docker コンテナのセットアップと使用方法の詳しい手順については、開発ガイドラインを参照してください。

3. 最初のツールを作成する
# Generate a new tool
php bin/console make:mcp-tool MyCustomTool

# Test your tool locally
php bin/console mcp:test-tool MyCustomTool --input='{"task":"analyze this code"}'
4. Inspector で可視化する

Model Context Protocol Inspector を使って、MCP ツールを可視化し、テストできます。

# Run the MCP Inspector without installation
npx @modelcontextprotocol/inspector node build/index.js

通常、localhost:6274 にウェブインターフェースが開きます。MCP サーバーをテストするには、以下の手順に従います。

5. AI クライアントを接続する

エージェントは次のクライアントから利用できるようになります。

  • 🤖 Claude Desktop / Claude.ai
  • 🧠 カスタム AI アプリケーション
  • 🔗 MCP 対応のあらゆるクライアント

🏗️ エージェントビルダー向けのアーキテクチャ

セキュアなエージェント通信
  • StreamableHTTP:エージェントとクライアント間の直接的で安全な通信
  • SSE(Server-Sent Events):長時間実行されるエージェントタスクのリアルタイム更新
  • STDIO なし:エンタープライズにも安全で、システムを外部に公開しません
スケーラブルなエージェントインフラストラクチャ
  • Pub/Sub メッセージング:複数のエージェントセッションを同時に処理
  • Redis/Cache アダプター:エージェントプラットフォームを水平スケーリング
  • 進捗のストリーミング:複雑なエージェント操作のリアルタイムフィードバック
エージェント開発ツール
  • MCP Inspector:エージェントの動作を可視化してデバッグ
  • テストコマンド:エージェントの迅速な開発とテスト
現在利用可能な MCP 機能
リソースプロンプトツールディスカバリーサンプリングルートエリシテーション
✅✅✅❌✅❌❌

🎓 エージェント開発リソース

🌟 エージェント革命に参加しましょう

Symfony MCP Server で、次世代の AI 搭載アプリケーションを構築しましょう。ツールはもはや単なる関数ではありません。推論し、学習し、進化する能力を持つインテリジェントなエージェントです。

コミュニティ

📜 ライセンス

MIT ライセンス — 自由に構築しましょう!

📰 MCP レジストリへの掲載


Boris AUBE とコントリビューターが ❤️ を込めて開発 — OP.GG/laravel-mcp-serverに着想を得ています

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。