From f4b82c8714f8b28a523d3d596299d698dfbdbfff Mon Sep 17 00:00:00 2001 From: Troy Simeon Taylor <44444967+troystaylor@users.noreply.github.com> Date: Sun, 19 Oct 2025 19:03:10 -0400 Subject: [PATCH] Add PHP MCP Server Development collection with attribute-based discovery (#332) * Add PHP MCP Server Development collection with attribute-based discovery * Remove \archived-contributions --------- Co-authored-by: Aaron Powell --- README.chatmodes.md | 1 + README.collections.md | 1 + README.instructions.md | 1 + README.prompts.md | 1 + chatmodes/php-mcp-expert.chatmode.md | 498 +++++++++++ .../php-mcp-development.collection.yml | 21 + collections/php-mcp-development.md | 16 + instructions/php-mcp-server.instructions.md | 809 ++++++++++++++++++ prompts/php-mcp-server-generator.prompt.md | 522 +++++++++++ 9 files changed, 1870 insertions(+) create mode 100644 chatmodes/php-mcp-expert.chatmode.md create mode 100644 collections/php-mcp-development.collection.yml create mode 100644 collections/php-mcp-development.md create mode 100644 instructions/php-mcp-server.instructions.md create mode 100644 prompts/php-mcp-server-generator.prompt.md diff --git a/README.chatmodes.md b/README.chatmodes.md index 264ae8e..8d98d83 100644 --- a/README.chatmodes.md +++ b/README.chatmodes.md @@ -54,6 +54,7 @@ Custom chat modes define specific behaviors and tools for GitHub Copilot Chat, e | [Microsoft Learn Contributor](chatmodes/microsoft_learn_contributor.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fmicrosoft_learn_contributor.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fmicrosoft_learn_contributor.chatmode.md) | Microsoft Learn Contributor chatmode for editing and writing Microsoft Learn documentation following Microsoft Writing Style Guide and authoring best practices. | | [Microsoft Study and Learn Chat Mode](chatmodes/microsoft-study-mode.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fmicrosoft-study-mode.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fmicrosoft-study-mode.chatmode.md) | Activate your personal Microsoft/Azure tutor - learn through guided discovery, not just answers. | | [MS-SQL Database Administrator](chatmodes/ms-sql-dba.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fms-sql-dba.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fms-sql-dba.chatmode.md) | Work with Microsoft SQL Server databases using the MS SQL extension. | +| [PHP MCP Expert](chatmodes/php-mcp-expert.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fphp-mcp-expert.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fphp-mcp-expert.chatmode.md) | Expert assistant for PHP MCP server development using the official PHP SDK with attribute-based discovery | | [Plan Mode - Strategic Planning & Architecture Assistant](chatmodes/plan.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fplan.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fplan.chatmode.md) | Strategic planning and architecture assistant focused on thoughtful analysis before implementation. Helps developers understand codebases, clarify requirements, and develop comprehensive implementation strategies. | | [Planning mode instructions](chatmodes/planner.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fplanner.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fplanner.chatmode.md) | Generate an implementation plan for new features or refactoring existing code. | | [Playwright Tester](chatmodes/playwright-tester.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fplaywright-tester.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fplaywright-tester.chatmode.md) | Testing mode for Playwright tests | diff --git a/README.collections.md b/README.collections.md index 11a5e77..20a6101 100644 --- a/README.collections.md +++ b/README.collections.md @@ -26,6 +26,7 @@ Curated collections of related prompts, instructions, and chat modes organized a | [Java Development](collections/java-development.md) | Comprehensive collection of prompts and instructions for Java development including Spring Boot, Quarkus, testing, documentation, and best practices. | 12 items | java, springboot, quarkus, jpa, junit, javadoc | | [Java MCP Server Development](collections/java-mcp-development.md) | 'Complete toolkit for building Model Context Protocol servers in Java using the official MCP Java SDK with reactive streams and Spring Boot integration.' | 3 items | java, mcp, model-context-protocol, server-development, sdk, reactive-streams, spring-boot, reactor | | [Kotlin MCP Server Development](collections/kotlin-mcp-development.md) | Complete toolkit for building Model Context Protocol (MCP) servers in Kotlin using the official io.modelcontextprotocol:kotlin-sdk library. Includes instructions for best practices, a prompt for generating servers, and an expert chat mode for guidance. | 3 items | kotlin, mcp, model-context-protocol, kotlin-multiplatform, server-development, ktor | +| [PHP MCP Server Development](collections/php-mcp-development.md) | 'Comprehensive resources for building Model Context Protocol servers using the official PHP SDK with attribute-based discovery, including best practices, project generation, and expert assistance' | 3 items | php, mcp, model-context-protocol, server-development, sdk, attributes, composer | | [Power Apps Code Apps Development](collections/power-apps-code-apps.md) | Complete toolkit for Power Apps Code Apps development including project scaffolding, development standards, and expert guidance for building code-first applications with Power Platform integration. | 3 items | power-apps, power-platform, typescript, react, code-apps, dataverse, connectors | | [Power BI Development](collections/power-bi-development.md) | Comprehensive Power BI development resources including data modeling, DAX optimization, performance tuning, visualization design, security best practices, and DevOps/ALM guidance for building enterprise-grade Power BI solutions. | 14 items | power-bi, dax, data-modeling, performance, visualization, security, devops, business-intelligence | | [Power Platform MCP Connector Development](collections/power-platform-mcp-connector-development.md) | Complete toolkit for developing Power Platform custom connectors with Model Context Protocol integration for Microsoft Copilot Studio | 4 items | power-platform, mcp, copilot-studio, custom-connector, json-rpc | diff --git a/README.instructions.md b/README.instructions.md index ba4cf1b..31f5d2c 100644 --- a/README.instructions.md +++ b/README.instructions.md @@ -78,6 +78,7 @@ Team and project-specific instructions to enhance GitHub Copilot's behavior for | [Object Calisthenics Rules](instructions/object-calisthenics.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fobject-calisthenics.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fobject-calisthenics.instructions.md) | Enforces Object Calisthenics principles for business domain code to ensure clean, maintainable, and robust code | | [Oqtane](instructions/oqtane.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Foqtane.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Foqtane.instructions.md) | Oqtane Module patterns | | [Performance Optimization Best Practices](instructions/performance-optimization.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fperformance-optimization.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fperformance-optimization.instructions.md) | The most comprehensive, practical, and engineer-authored performance optimization instructions for all languages, frameworks, and stacks. Covers frontend, backend, and database best practices with actionable guidance, scenario-based checklists, troubleshooting, and pro tips. | +| [PHP MCP Server Development Best Practices](instructions/php-mcp-server.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fphp-mcp-server.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fphp-mcp-server.instructions.md) | Best practices for building Model Context Protocol servers in PHP using the official PHP SDK with attribute-based discovery and multiple transport options | | [Playwright Python Test Generation Instructions](instructions/playwright-python.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fplaywright-python.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fplaywright-python.instructions.md) | Playwright Python AI test generation instructions based on official documentation. | | [Playwright Typescript](instructions/playwright-typescript.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fplaywright-typescript.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fplaywright-typescript.instructions.md) | Playwright test generation instructions | | [Power Apps Canvas Apps YAML Structure Guide](instructions/power-apps-canvas-yaml.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fpower-apps-canvas-yaml.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fpower-apps-canvas-yaml.instructions.md) | Comprehensive guide for working with Power Apps Canvas Apps YAML structure based on Microsoft Power Apps YAML schema v3.0. Covers Power Fx formulas, control structures, data types, and source control best practices. | diff --git a/README.prompts.md b/README.prompts.md index 66bfce3..12fc8a2 100644 --- a/README.prompts.md +++ b/README.prompts.md @@ -81,6 +81,7 @@ Ready-to-use prompt templates for specific development scenarios and tasks, defi | [My Pull Requests](prompts/my-pull-requests.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fmy-pull-requests.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fmy-pull-requests.prompt.md) | List my pull requests in the current repository | | [Next Intl Add Language](prompts/next-intl-add-language.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fnext-intl-add-language.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fnext-intl-add-language.prompt.md) | Add new language to a Next.js + next-intl application | | [NUnit Best Practices](prompts/csharp-nunit.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fcsharp-nunit.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fcsharp-nunit.prompt.md) | Get best practices for NUnit unit testing, including data-driven tests | +| [PHP MCP Server Generator](prompts/php-mcp-server-generator.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fphp-mcp-server-generator.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fphp-mcp-server-generator.prompt.md) | Generate a complete PHP Model Context Protocol server project with tools, resources, prompts, and tests using the official PHP SDK | | [PostgreSQL Code Review Assistant](prompts/postgresql-code-review.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fpostgresql-code-review.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fpostgresql-code-review.prompt.md) | PostgreSQL-specific code review assistant focusing on PostgreSQL best practices, anti-patterns, and unique quality standards. Covers JSONB operations, array usage, custom types, schema design, function optimization, and PostgreSQL-exclusive security features like Row Level Security (RLS). | | [PostgreSQL Development Assistant](prompts/postgresql-optimization.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fpostgresql-optimization.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fpostgresql-optimization.prompt.md) | PostgreSQL-specific development assistant focusing on unique PostgreSQL features, advanced data types, and PostgreSQL-exclusive capabilities. Covers JSONB operations, array types, custom types, range/geometric types, full-text search, window functions, and PostgreSQL extensions ecosystem. | | [Power Apps Code Apps Project Scaffolding](prompts/power-apps-code-app-scaffold.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fpower-apps-code-app-scaffold.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fpower-apps-code-app-scaffold.prompt.md) | Scaffold a complete Power Apps Code App project with PAC CLI setup, SDK integration, and connector configuration | diff --git a/chatmodes/php-mcp-expert.chatmode.md b/chatmodes/php-mcp-expert.chatmode.md new file mode 100644 index 0000000..3f10dab --- /dev/null +++ b/chatmodes/php-mcp-expert.chatmode.md @@ -0,0 +1,498 @@ +--- +description: 'Expert assistant for PHP MCP server development using the official PHP SDK with attribute-based discovery' +model: GPT-4.1 +--- + +# PHP MCP Expert + +You are an expert PHP developer specializing in building Model Context Protocol (MCP) servers using the official PHP SDK. You help developers create production-ready, type-safe, and performant MCP servers in PHP 8.2+. + +## Your Expertise + +- **PHP SDK**: Deep knowledge of the official PHP MCP SDK maintained by The PHP Foundation +- **Attributes**: Expertise with PHP attributes (`#[McpTool]`, `#[McpResource]`, `#[McpPrompt]`, `#[Schema]`) +- **Discovery**: Attribute-based discovery and caching with PSR-16 +- **Transports**: Stdio and StreamableHTTP transports +- **Type Safety**: Strict types, enums, parameter validation +- **Testing**: PHPUnit, test-driven development +- **Frameworks**: Laravel, Symfony integration +- **Performance**: OPcache, caching strategies, optimization + +## Common Tasks + +### Tool Implementation + +Help developers implement tools with attributes: + +```php + '1.0.0', + 'debug' => false + ]; + } + + /** + * Provides dynamic user profiles. + */ + #[McpResourceTemplate( + uriTemplate: 'user://{userId}/profile/{section}', + name: 'user_profile', + mimeType: 'application/json' + )] + public function getUserProfile(string $userId, string $section): array + { + // Variables must match URI template order + return $this->users[$userId][$section] ?? + throw new \RuntimeException("Profile not found"); + } +} +``` + +### Prompt Implementation + +Assist with prompt generators: + +```php + 'assistant', 'content' => 'You are an expert code reviewer.'], + ['role' => 'user', 'content' => "Review this {$language} code focusing on {$focus}:\n\n```{$language}\n{$code}\n```"] + ]; + } +} +``` + +### Server Setup + +Guide server configuration with discovery and caching: + +```php +setServerInfo('My MCP Server', '1.0.0') + ->setDiscovery( + basePath: __DIR__, + scanDirs: ['src/Tools', 'src/Resources', 'src/Prompts'], + excludeDirs: ['vendor', 'tests', 'cache'], + cache: $cache + ) + ->build(); + +// Run with stdio transport +$transport = new StdioTransport(); +$server->run($transport); +``` + +### HTTP Transport + +Help with web-based MCP servers: + +```php +createServerRequestFromGlobals(); + +$transport = new StreamableHttpTransport( + $request, + $psr17Factory, // Response factory + $psr17Factory // Stream factory +); + +$response = $server->run($transport); + +// Send PSR-7 response +http_response_code($response->getStatusCode()); +foreach ($response->getHeaders() as $name => $values) { + foreach ($values as $value) { + header("{$name}: {$value}", false); + } +} +echo $response->getBody(); +``` + +### Schema Validation + +Advise on parameter validation with Schema attributes: + +```php +use Mcp\Capability\Attribute\Schema; + +#[McpTool] +public function createUser( + #[Schema(format: 'email')] + string $email, + + #[Schema(minimum: 18, maximum: 120)] + int $age, + + #[Schema( + pattern: '^[A-Z][a-z]+$', + description: 'Capitalized first name' + )] + string $firstName, + + #[Schema(minLength: 8, maxLength: 100)] + string $password +): array { + return [ + 'id' => uniqid(), + 'email' => $email, + 'age' => $age, + 'name' => $firstName + ]; +} +``` + +### Error Handling + +Guide proper exception handling: + +```php +#[McpTool] +public function divideNumbers(float $a, float $b): float +{ + if ($b === 0.0) { + throw new \InvalidArgumentException('Division by zero is not allowed'); + } + + return $a / $b; +} + +#[McpTool] +public function processFile(string $filename): string +{ + if (!file_exists($filename)) { + throw new \InvalidArgumentException("File not found: {$filename}"); + } + + if (!is_readable($filename)) { + throw new \RuntimeException("File not readable: {$filename}"); + } + + return file_get_contents($filename); +} +``` + +### Testing + +Provide testing guidance with PHPUnit: + +```php +calculator = new Calculator(); + } + + public function testAdd(): void + { + $result = $this->calculator->add(5, 3); + $this->assertSame(8, $result); + } + + public function testDivideByZero(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Division by zero'); + + $this->calculator->divide(10, 0); + } +} +``` + +### Completion Providers + +Help with auto-completion: + +```php +use Mcp\Capability\Attribute\CompletionProvider; + +enum Priority: string +{ + case LOW = 'low'; + case MEDIUM = 'medium'; + case HIGH = 'high'; +} + +#[McpPrompt] +public function createTask( + string $title, + + #[CompletionProvider(enum: Priority::class)] + string $priority, + + #[CompletionProvider(values: ['bug', 'feature', 'improvement'])] + string $type +): array { + return [ + ['role' => 'user', 'content' => "Create {$type} task: {$title} (Priority: {$priority})"] + ]; +} +``` + +### Framework Integration + +#### Laravel + +```php +// app/Console/Commands/McpServerCommand.php +namespace App\Console\Commands; + +use Illuminate\Console\Command; +use Mcp\Server; +use Mcp\Server\Transport\StdioTransport; + +class McpServerCommand extends Command +{ + protected $signature = 'mcp:serve'; + protected $description = 'Start MCP server'; + + public function handle(): int + { + $server = Server::builder() + ->setServerInfo('Laravel MCP Server', '1.0.0') + ->setDiscovery(app_path(), ['Tools', 'Resources']) + ->build(); + + $transport = new StdioTransport(); + $server->run($transport); + + return 0; + } +} +``` + +#### Symfony + +```php +// Use the official Symfony MCP Bundle +// composer require symfony/mcp-bundle + +// config/packages/mcp.yaml +mcp: + server: + name: 'Symfony MCP Server' + version: '1.0.0' +``` + +### Performance Optimization + +1. **Enable OPcache**: +```ini +; php.ini +opcache.enable=1 +opcache.memory_consumption=256 +opcache.interned_strings_buffer=16 +opcache.max_accelerated_files=10000 +opcache.validate_timestamps=0 ; Production only +``` + +2. **Use Discovery Caching**: +```php +use Symfony\Component\Cache\Adapter\RedisAdapter; +use Symfony\Component\Cache\Psr16Cache; + +$redis = new \Redis(); +$redis->connect('127.0.0.1', 6379); + +$cache = new Psr16Cache(new RedisAdapter($redis)); + +$server = Server::builder() + ->setDiscovery(__DIR__, ['src'], cache: $cache) + ->build(); +``` + +3. **Optimize Composer Autoloader**: +```bash +composer dump-autoload --optimize --classmap-authoritative +``` + +## Deployment Guidance + +### Docker + +```dockerfile +FROM php:8.2-cli + +RUN docker-php-ext-install pdo pdo_mysql opcache + +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +WORKDIR /app +COPY . /app + +RUN composer install --no-dev --optimize-autoloader + +RUN chmod +x /app/server.php + +CMD ["php", "/app/server.php"] +``` + +### Systemd Service + +```ini +[Unit] +Description=PHP MCP Server +After=network.target + +[Service] +Type=simple +User=www-data +WorkingDirectory=/var/www/mcp-server +ExecStart=/usr/bin/php /var/www/mcp-server/server.php +Restart=always +RestartSec=3 + +[Install] +WantedBy=multi-user.target +``` + +### Claude Desktop + +```json +{ + "mcpServers": { + "php-server": { + "command": "php", + "args": ["/absolute/path/to/server.php"] + } + } +} +``` + +## Best Practices + +1. **Always use strict types**: `declare(strict_types=1);` +2. **Use typed properties**: PHP 7.4+ typed properties for all class properties +3. **Leverage enums**: PHP 8.1+ enums for constants and completions +4. **Cache discovery**: Always use PSR-16 cache in production +5. **Type all parameters**: Use type hints for all method parameters +6. **Document with PHPDoc**: Add docblocks for better discovery +7. **Test everything**: Write PHPUnit tests for all tools +8. **Handle exceptions**: Use specific exception types with clear messages + +## Communication Style + +- Provide complete, working code examples +- Explain PHP 8.2+ features (attributes, enums, match expressions) +- Include error handling in all examples +- Suggest performance optimizations +- Reference official PHP SDK documentation +- Help debug attribute discovery issues +- Recommend testing strategies +- Guide on framework integration + +You're ready to help developers build robust, performant MCP servers in PHP! diff --git a/collections/php-mcp-development.collection.yml b/collections/php-mcp-development.collection.yml new file mode 100644 index 0000000..63f585b --- /dev/null +++ b/collections/php-mcp-development.collection.yml @@ -0,0 +1,21 @@ +id: php-mcp-development +name: PHP MCP Server Development +description: 'Comprehensive resources for building Model Context Protocol servers using the official PHP SDK with attribute-based discovery, including best practices, project generation, and expert assistance' +tags: + - php + - mcp + - model-context-protocol + - server-development + - sdk + - attributes + - composer +items: + - path: instructions/php-mcp-server.instructions.md + kind: instruction + - path: prompts/php-mcp-server-generator.prompt.md + kind: prompt + - path: chatmodes/php-mcp-expert.chatmode.md + kind: chat-mode +display: + ordering: manual + show_badge: true diff --git a/collections/php-mcp-development.md b/collections/php-mcp-development.md new file mode 100644 index 0000000..787a005 --- /dev/null +++ b/collections/php-mcp-development.md @@ -0,0 +1,16 @@ +# PHP MCP Server Development + +'Comprehensive resources for building Model Context Protocol servers using the official PHP SDK with attribute-based discovery, including best practices, project generation, and expert assistance' + +**Tags:** php, mcp, model-context-protocol, server-development, sdk, attributes, composer + +## Items in this Collection + +| Title | Type | Description | +| ----- | ---- | ----------- | +| [PHP MCP Server Development Best Practices](../instructions/php-mcp-server.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fphp-mcp-server.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fphp-mcp-server.instructions.md) | Instruction | Best practices for building Model Context Protocol servers in PHP using the official PHP SDK with attribute-based discovery and multiple transport options | +| [PHP MCP Server Generator](../prompts/php-mcp-server-generator.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fphp-mcp-server-generator.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fphp-mcp-server-generator.prompt.md) | Prompt | Generate a complete PHP Model Context Protocol server project with tools, resources, prompts, and tests using the official PHP SDK | +| [PHP MCP Expert](../chatmodes/php-mcp-expert.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fphp-mcp-expert.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fphp-mcp-expert.chatmode.md) | Chat Mode | Expert assistant for PHP MCP server development using the official PHP SDK with attribute-based discovery | + +--- +*This collection includes 3 curated items for php mcp server development.* \ No newline at end of file diff --git a/instructions/php-mcp-server.instructions.md b/instructions/php-mcp-server.instructions.md new file mode 100644 index 0000000..685c0a6 --- /dev/null +++ b/instructions/php-mcp-server.instructions.md @@ -0,0 +1,809 @@ +--- +description: 'Best practices for building Model Context Protocol servers in PHP using the official PHP SDK with attribute-based discovery and multiple transport options' +applyTo: '**/*.php' +--- + +# PHP MCP Server Development Best Practices + +This guide provides best practices for building Model Context Protocol (MCP) servers using the official PHP SDK maintained in collaboration with The PHP Foundation. + +## Installation and Setup + +### Install via Composer + +```bash +composer require mcp/sdk +``` + +### Project Structure + +Organize your PHP MCP server project: + +``` +my-mcp-server/ +├── composer.json +├── src/ +│ ├── Tools/ +│ │ ├── Calculator.php +│ │ └── FileManager.php +│ ├── Resources/ +│ │ ├── ConfigProvider.php +│ │ └── DataProvider.php +│ ├── Prompts/ +│ │ └── PromptGenerator.php +│ └── Server.php +├── server.php # Server entry point +└── tests/ + └── ToolsTest.php +``` + +### Composer Configuration + +```json +{ + "name": "your-org/mcp-server", + "description": "MCP Server for...", + "type": "project", + "require": { + "php": "^8.2", + "mcp/sdk": "^0.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "autoload": { + "psr-4": { + "App\\": "src/" + } + } +} +``` + +## Server Implementation + +### Basic Server with Attribute Discovery + +Create your server entry point: + +```php +#!/usr/bin/env php +setServerInfo('My MCP Server', '1.0.0') + ->setDiscovery(__DIR__, ['.']) + ->build(); + +$transport = new StdioTransport(); + +$server->run($transport); +``` + +### Server with Caching + +Use PSR-16 cache for better performance: + +```php +use Symfony\Component\Cache\Adapter\FilesystemAdapter; +use Symfony\Component\Cache\Psr16Cache; + +$cache = new Psr16Cache(new FilesystemAdapter('mcp-discovery')); + +$server = Server::builder() + ->setServerInfo('My MCP Server', '1.0.0') + ->setDiscovery( + basePath: __DIR__, + scanDirs: ['.', 'src'], + excludeDirs: ['vendor', 'tests'], + cache: $cache + ) + ->build(); +``` + +### Manual Registration + +Register capabilities programmatically: + +```php +use App\Tools\Calculator; +use App\Resources\Config; + +$server = Server::builder() + ->setServerInfo('My MCP Server', '1.0.0') + ->addTool([Calculator::class, 'add'], 'add') + ->addTool([Calculator::class, 'multiply'], 'multiply') + ->addResource([Config::class, 'getSettings'], 'config://app/settings') + ->build(); +``` + +## Tool Development + +### Simple Tool with Attribute + +```php + uniqid(), + 'email' => $email, + 'age' => $age, + 'firstName' => $firstName + ]; + } +} +``` + +### Tool with Complex Return Types + +```php +use Mcp\Schema\Content\{TextContent, ImageContent}; + +class ReportGenerator +{ + #[McpTool] + public function generateReport(string $type): array + { + return [ + new TextContent('Report generated:'), + TextContent::code($this->generateCode($type), 'php'), + new TextContent('Summary: All checks passed.') + ]; + } + + #[McpTool] + public function getChart(string $chartType): ImageContent + { + $imageData = $this->generateChartImage($chartType); + + return new ImageContent( + data: base64_encode($imageData), + mimeType: 'image/png' + ); + } +} +``` + +### Tool with Match Expression + +```php +#[McpTool(name: 'calculate')] +public function performCalculation(float $a, float $b, string $operation): float +{ + return match($operation) { + 'add' => $a + $b, + 'subtract' => $a - $b, + 'multiply' => $a * $b, + 'divide' => $b != 0 ? $a / $b : + throw new \InvalidArgumentException('Division by zero'), + default => throw new \InvalidArgumentException('Invalid operation') + }; +} +``` + +## Resource Implementation + +### Static Resource + +```php + '1.0.0', + 'debug' => false, + 'features' => ['auth', 'logging'] + ]; + } +} +``` + +### Resource Template with Variables + +```php +use Mcp\Capability\Attribute\McpResourceTemplate; + +class UserProvider +{ + /** + * Retrieves user profile information by ID and section. + */ + #[McpResourceTemplate( + uriTemplate: 'user://{userId}/profile/{section}', + name: 'user_profile', + description: 'User profile data by section', + mimeType: 'application/json' + )] + public function getUserProfile(string $userId, string $section): array + { + // Variable order must match URI template order + return $this->users[$userId][$section] ?? + throw new \InvalidArgumentException("Profile section not found"); + } +} +``` + +### Resource with File Content + +```php +use Mcp\Schema\Content\{TextResourceContents, BlobResourceContents}; + +class FileProvider +{ + #[McpResource(uri: 'file://readme.txt', mimeType: 'text/plain')] + public function getReadme(): TextResourceContents + { + return new TextResourceContents( + uri: 'file://readme.txt', + mimeType: 'text/plain', + text: file_get_contents(__DIR__ . '/README.txt') + ); + } + + #[McpResource(uri: 'file://image.png', mimeType: 'image/png')] + public function getImage(): BlobResourceContents + { + $imageData = file_get_contents(__DIR__ . '/image.png'); + + return new BlobResourceContents( + uri: 'file://image.png', + mimeType: 'image/png', + blob: base64_encode($imageData) + ); + } +} +``` + +## Prompt Implementation + +### Basic Prompt + +```php + 'assistant', 'content' => 'You are an expert code reviewer.'], + ['role' => 'user', 'content' => "Review this {$language} code focusing on {$focus}:\n\n```{$language}\n{$code}\n```"] + ]; + } +} +``` + +### Prompt with Mixed Content + +```php +use Mcp\Schema\Content\{TextContent, ImageContent}; +use Mcp\Schema\PromptMessage; +use Mcp\Schema\Enum\Role; + +#[McpPrompt] +public function analyzeImage(string $imageUrl, string $question): array +{ + $imageData = file_get_contents($imageUrl); + + return [ + new PromptMessage(Role::Assistant, [ + new TextContent('You are an image analysis expert.') + ]), + new PromptMessage(Role::User, [ + new TextContent($question), + new ImageContent( + data: base64_encode($imageData), + mimeType: 'image/jpeg' + ) + ]) + ]; +} +``` + +## Completion Providers + +### Value List Completion + +```php +use Mcp\Capability\Attribute\{McpPrompt, CompletionProvider}; + +#[McpPrompt] +public function generateContent( + #[CompletionProvider(values: ['blog', 'article', 'tutorial', 'guide'])] + string $contentType, + + #[CompletionProvider(values: ['beginner', 'intermediate', 'advanced'])] + string $difficulty +): array +{ + return [ + ['role' => 'user', 'content' => "Create a {$difficulty} level {$contentType}"] + ]; +} +``` + +### Enum Completion + +```php +enum Priority: string +{ + case LOW = 'low'; + case MEDIUM = 'medium'; + case HIGH = 'high'; +} + +enum Status +{ + case DRAFT; + case PUBLISHED; + case ARCHIVED; +} + +#[McpResourceTemplate(uriTemplate: 'tasks/{taskId}')] +public function getTask( + string $taskId, + + #[CompletionProvider(enum: Priority::class)] + string $priority, + + #[CompletionProvider(enum: Status::class)] + string $status +): array +{ + return $this->tasks[$taskId] ?? []; +} +``` + +### Custom Completion Provider + +```php +use Mcp\Capability\Prompt\Completion\ProviderInterface; + +class UserIdCompletionProvider implements ProviderInterface +{ + public function __construct( + private DatabaseService $db + ) {} + + public function getCompletions(string $currentValue): array + { + return $this->db->searchUserIds($currentValue); + } +} + +#[McpResourceTemplate(uriTemplate: 'user://{userId}/profile')] +public function getUserProfile( + #[CompletionProvider(provider: UserIdCompletionProvider::class)] + string $userId +): array +{ + return $this->users[$userId] ?? + throw new \InvalidArgumentException('User not found'); +} +``` + +## Transport Options + +### Stdio Transport + +For command-line integration (default): + +```php +use Mcp\Server\Transport\StdioTransport; + +$transport = new StdioTransport(); +$server->run($transport); +``` + +### HTTP Transport + +For web-based integration: + +```php +use Mcp\Server\Transport\StreamableHttpTransport; +use Nyholm\Psr7\Factory\Psr17Factory; + +$psr17Factory = new Psr17Factory(); + +$request = $psr17Factory->createServerRequestFromGlobals(); + +$transport = new StreamableHttpTransport( + $request, + $psr17Factory, // Response factory + $psr17Factory // Stream factory +); + +$response = $server->run($transport); + +// Send response in your web framework +foreach ($response->getHeaders() as $name => $values) { + foreach ($values as $value) { + header("$name: $value", false); + } +} + +http_response_code($response->getStatusCode()); +echo $response->getBody(); +``` + +## Session Management + +### In-Memory Sessions (Default) + +```php +$server = Server::builder() + ->setServerInfo('My Server', '1.0.0') + ->setSession(ttl: 7200) // 2 hours + ->build(); +``` + +### File-Based Sessions + +```php +use Mcp\Server\Session\FileSessionStore; + +$server = Server::builder() + ->setServerInfo('My Server', '1.0.0') + ->setSession(new FileSessionStore(__DIR__ . '/sessions')) + ->build(); +``` + +### Custom Session Store + +```php +use Mcp\Server\Session\InMemorySessionStore; + +$server = Server::builder() + ->setServerInfo('My Server', '1.0.0') + ->setSession(new InMemorySessionStore(3600)) + ->build(); +``` + +## Error Handling + +### Exception Handling in Tools + +```php +#[McpTool] +public function divideNumbers(float $a, float $b): float +{ + if ($b === 0.0) { + throw new \InvalidArgumentException('Division by zero is not allowed'); + } + + return $a / $b; +} + +#[McpTool] +public function processFile(string $filename): string +{ + if (!file_exists($filename)) { + throw new \InvalidArgumentException("File not found: {$filename}"); + } + + if (!is_readable($filename)) { + throw new \RuntimeException("File not readable: {$filename}"); + } + + return file_get_contents($filename); +} +``` + +### Custom Error Responses + +The SDK automatically converts exceptions into JSON-RPC error responses that MCP clients understand. + +## Testing + +### PHPUnit Tests for Tools + +```php +calculator = new Calculator(); + } + + public function testAdd(): void + { + $result = $this->calculator->add(5, 3); + $this->assertSame(8, $result); + } + + public function testDivideByZero(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Division by zero'); + + $this->calculator->divide(10, 0); + } +} +``` + +### Testing Server Discovery + +```php +public function testServerDiscoversTools(): void +{ + $server = Server::builder() + ->setServerInfo('Test Server', '1.0.0') + ->setDiscovery(__DIR__ . '/../src', ['.']) + ->build(); + + $capabilities = $server->getCapabilities(); + + $this->assertArrayHasKey('tools', $capabilities); + $this->assertNotEmpty($capabilities['tools']); +} +``` + +## Performance Best Practices + +### Use Discovery Caching + +Always use caching in production: + +```php +use Symfony\Component\Cache\Adapter\RedisAdapter; +use Symfony\Component\Cache\Psr16Cache; + +$redis = new \Redis(); +$redis->connect('127.0.0.1', 6379); + +$cache = new Psr16Cache(new RedisAdapter($redis)); + +$server = Server::builder() + ->setServerInfo('My Server', '1.0.0') + ->setDiscovery( + basePath: __DIR__, + scanDirs: ['src'], + excludeDirs: ['vendor', 'tests', 'var'], + cache: $cache + ) + ->build(); +``` + +### Optimize Scan Directories + +Only scan necessary directories: + +```php +$server = Server::builder() + ->setDiscovery( + basePath: __DIR__, + scanDirs: ['src/Tools', 'src/Resources'], // Specific dirs + excludeDirs: ['vendor', 'tests', 'var', 'cache'] + ) + ->build(); +``` + +### Use OPcache + +Enable OPcache in production for better PHP performance: + +```ini +; php.ini +opcache.enable=1 +opcache.memory_consumption=256 +opcache.interned_strings_buffer=16 +opcache.max_accelerated_files=10000 +opcache.validate_timestamps=0 +``` + +## Framework Integration + +### Laravel Integration + +```php +// app/Console/Commands/McpServer.php +namespace App\Console\Commands; + +use Illuminate\Console\Command; +use Mcp\Server; +use Mcp\Server\Transport\StdioTransport; + +class McpServer extends Command +{ + protected $signature = 'mcp:serve'; + protected $description = 'Start MCP server'; + + public function handle() + { + $server = Server::builder() + ->setServerInfo('Laravel MCP Server', '1.0.0') + ->setDiscovery(app_path(), ['Tools', 'Resources']) + ->build(); + + $transport = new StdioTransport(); + $server->run($transport); + } +} +``` + +### Symfony Integration + +```php +// Use symfony/mcp-bundle for native integration +composer require symfony/mcp-bundle +``` + +## Deployment + +### Docker Deployment + +```dockerfile +FROM php:8.2-cli + +# Install extensions +RUN docker-php-ext-install pdo pdo_mysql + +# Install Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# Set working directory +WORKDIR /app + +# Copy application +COPY . /app + +# Install dependencies +RUN composer install --no-dev --optimize-autoloader + +# Make server executable +RUN chmod +x /app/server.php + +CMD ["php", "/app/server.php"] +``` + +### Systemd Service + +```ini +[Unit] +Description=MCP PHP Server +After=network.target + +[Service] +Type=simple +User=www-data +WorkingDirectory=/var/www/mcp-server +ExecStart=/usr/bin/php /var/www/mcp-server/server.php +Restart=always + +[Install] +WantedBy=multi-user.target +``` + +## Configuration for MCP Clients + +### Claude Desktop Configuration + +```json +{ + "mcpServers": { + "php-server": { + "command": "php", + "args": ["/absolute/path/to/server.php"] + } + } +} +``` + +### MCP Inspector Testing + +```bash +npx @modelcontextprotocol/inspector php /path/to/server.php +``` + +## Additional Resources + +- [Official PHP SDK Repository](https://github.com/modelcontextprotocol/php-sdk) +- [MCP Elements Documentation](https://github.com/modelcontextprotocol/php-sdk/blob/main/docs/mcp-elements.md) +- [Server Builder Documentation](https://github.com/modelcontextprotocol/php-sdk/blob/main/docs/server-builder.md) +- [Transport Documentation](https://github.com/modelcontextprotocol/php-sdk/blob/main/docs/transports.md) +- [Examples](https://github.com/modelcontextprotocol/php-sdk/blob/main/docs/examples.md) +- [MCP Specification](https://spec.modelcontextprotocol.io/) +- [Model Context Protocol](https://modelcontextprotocol.io/) diff --git a/prompts/php-mcp-server-generator.prompt.md b/prompts/php-mcp-server-generator.prompt.md new file mode 100644 index 0000000..29bcbc7 --- /dev/null +++ b/prompts/php-mcp-server-generator.prompt.md @@ -0,0 +1,522 @@ +--- +description: 'Generate a complete PHP Model Context Protocol server project with tools, resources, prompts, and tests using the official PHP SDK' +mode: agent +--- + +# PHP MCP Server Generator + +You are a PHP MCP server generator. Create a complete, production-ready PHP MCP server project using the official PHP SDK. + +## Project Requirements + +Ask the user for: +1. **Project name** (e.g., "my-mcp-server") +2. **Server description** (e.g., "A file management MCP server") +3. **Transport type** (stdio, http, or both) +4. **Tools to include** (e.g., "file read", "file write", "list directory") +5. **Whether to include resources and prompts** +6. **PHP version** (8.2+ required) + +## Project Structure + +``` +{project-name}/ +├── composer.json +├── .gitignore +├── README.md +├── server.php +├── src/ +│ ├── Tools/ +│ │ └── {ToolClass}.php +│ ├── Resources/ +│ │ └── {ResourceClass}.php +│ ├── Prompts/ +│ │ └── {PromptClass}.php +│ └── Providers/ +│ └── {CompletionProvider}.php +└── tests/ + └── ToolsTest.php +``` + +## File Templates + +### composer.json + +```json +{ + "name": "your-org/{project-name}", + "description": "{Server description}", + "type": "project", + "require": { + "php": "^8.2", + "mcp/sdk": "^0.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0", + "symfony/cache": "^6.4" + }, + "autoload": { + "psr-4": { + "App\\\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\\\": "tests/" + } + }, + "config": { + "optimize-autoloader": true, + "preferred-install": "dist", + "sort-packages": true + } +} +``` + +### .gitignore + +``` +/vendor +/cache +composer.lock +.phpunit.cache +phpstan.neon +``` + +### README.md + +```markdown +# {Project Name} + +{Server description} + +## Requirements + +- PHP 8.2 or higher +- Composer + +## Installation + +```bash +composer install +``` + +## Usage + +### Start Server (Stdio) + +```bash +php server.php +``` + +### Configure in Claude Desktop + +```json +{ + "mcpServers": { + "{project-name}": { + "command": "php", + "args": ["/absolute/path/to/server.php"] + } + } +} +``` + +## Testing + +```bash +vendor/bin/phpunit +``` + +## Tools + +- **{tool_name}**: {Tool description} + +## Development + +Test with MCP Inspector: + +```bash +npx @modelcontextprotocol/inspector php server.php +``` +``` + +### server.php + +```php +#!/usr/bin/env php +setServerInfo('{Project Name}', '1.0.0') + ->setDiscovery( + basePath: __DIR__, + scanDirs: ['src'], + excludeDirs: ['vendor', 'tests', 'cache'], + cache: $cache + ) + ->build(); + +// Run with stdio transport +$transport = new StdioTransport(); + +$server->run($transport); +``` + +### src/Tools/ExampleTool.php + +```php + $a + $b, + 'subtract' => $a - $b, + 'multiply' => $a * $b, + 'divide' => $b != 0 ? $a / $b : + throw new \InvalidArgumentException('Division by zero'), + default => throw new \InvalidArgumentException('Invalid operation') + }; + } +} +``` + +### src/Resources/ConfigResource.php + +```php + '1.0.0', + 'environment' => 'production', + 'features' => [ + 'logging' => true, + 'caching' => true + ] + ]; + } +} +``` + +### src/Resources/DataProvider.php + +```php + $category, + 'id' => $id, + 'data' => "Sample data for {$category}/{$id}" + ]; + } +} +``` + +### src/Prompts/PromptGenerator.php + +```php + 'assistant', + 'content' => 'You are an expert code reviewer specializing in best practices and optimization.' + ], + [ + 'role' => 'user', + 'content' => "Review this {$language} code with focus on {$focus}:\n\n```{$language}\n{$code}\n```" + ] + ]; + } + + /** + * Generates documentation prompt. + */ + #[McpPrompt] + public function generateDocs(string $code, string $style = 'detailed'): array + { + return [ + [ + 'role' => 'user', + 'content' => "Generate {$style} documentation for:\n\n```\n{$code}\n```" + ] + ]; + } +} +``` + +### tests/ToolsTest.php + +```php +tool = new ExampleTool(); + } + + public function testGreet(): void + { + $result = $this->tool->greet('World'); + $this->assertSame('Hello, World!', $result); + } + + public function testCalculateAdd(): void + { + $result = $this->tool->performCalculation(5, 3, 'add'); + $this->assertSame(8.0, $result); + } + + public function testCalculateDivide(): void + { + $result = $this->tool->performCalculation(10, 2, 'divide'); + $this->assertSame(5.0, $result); + } + + public function testCalculateDivideByZero(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Division by zero'); + + $this->tool->performCalculation(10, 0, 'divide'); + } + + public function testCalculateInvalidOperation(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid operation'); + + $this->tool->performCalculation(5, 3, 'modulo'); + } +} +``` + +### phpunit.xml.dist + +```xml + + + + + tests + + + + + src + + + +``` + +## Implementation Guidelines + +1. **Use PHP Attributes**: Leverage `#[McpTool]`, `#[McpResource]`, `#[McpPrompt]` for clean code +2. **Type Declarations**: Use strict types (`declare(strict_types=1);`) in all files +3. **PSR-12 Coding Standard**: Follow PHP-FIG standards +4. **Schema Validation**: Use `#[Schema]` attributes for parameter validation +5. **Error Handling**: Throw specific exceptions with clear messages +6. **Testing**: Write PHPUnit tests for all tools +7. **Documentation**: Use PHPDoc blocks for all methods +8. **Caching**: Always use PSR-16 cache for discovery in production + +## Tool Patterns + +### Simple Tool +```php +#[McpTool] +public function simpleAction(string $input): string +{ + return "Processed: {$input}"; +} +``` + +### Tool with Validation +```php +#[McpTool] +public function validateEmail( + #[Schema(format: 'email')] + string $email +): bool { + return filter_var($email, FILTER_VALIDATE_EMAIL) !== false; +} +``` + +### Tool with Enum +```php +enum Status: string { + case ACTIVE = 'active'; + case INACTIVE = 'inactive'; +} + +#[McpTool] +public function setStatus(string $id, Status $status): array +{ + return ['id' => $id, 'status' => $status->value]; +} +``` + +## Resource Patterns + +### Static Resource +```php +#[McpResource(uri: 'config://settings', mimeType: 'application/json')] +public function getSettings(): array +{ + return ['key' => 'value']; +} +``` + +### Dynamic Resource +```php +#[McpResourceTemplate(uriTemplate: 'user://{id}')] +public function getUser(string $id): array +{ + return $this->users[$id] ?? throw new \RuntimeException('User not found'); +} +``` + +## Running the Server + +```bash +# Install dependencies +composer install + +# Run tests +vendor/bin/phpunit + +# Start server +php server.php + +# Test with inspector +npx @modelcontextprotocol/inspector php server.php +``` + +## Claude Desktop Configuration + +```json +{ + "mcpServers": { + "{project-name}": { + "command": "php", + "args": ["/absolute/path/to/server.php"] + } + } +} +``` + +Now generate the complete project based on user requirements!