Download the PHP package elliottlawson/mcp-php-sdk without Composer
On this page you can find all versions of the php package elliottlawson/mcp-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elliottlawson/mcp-php-sdk
More information about elliottlawson/mcp-php-sdk
Files in elliottlawson/mcp-php-sdk
Package mcp-php-sdk
Short Description PHP SDK for Model Context Protocol
License MIT
Informations about the package mcp-php-sdk
MCP PHP SDK
A PHP SDK for the Model Context Protocol (MCP), allowing seamless integration between applications and Large Language Models (LLMs).
Requirements
- PHP 8.1 or higher
- Composer
Installation
Overview
The Model Context Protocol (MCP) is an open standard for connecting large language models (LLMs) to applications, APIs, and external data sources. This PHP SDK provides a structured implementation for PHP applications to integrate with MCP.
Main Components
Protocol Layer
The Protocol layer handles the core MCP message format and communication patterns:
McpMessage: Represents JSON-RPC 2.0 messages used in MCPProtocol: Handles message framing, request-response linking, and pattern registration
Transport Layer
The Transport layer defines how messages are sent and received:
TransportInterface: Defines the contract for all transport implementationsStdioTransport: Implementation for command-line applications using standard input/outputSseTransport: Implementation for web applications using Server-Sent Events (SSE)
Resources
Resources are data sources that LLMs can access:
Resource: Represents a data sourceResourceTemplate: Handles URI templates and pattern matchingResourceContent: Represents the content of a resource
Tools
Tools enable LLMs to execute code and produce side effects:
Tool: Represents a tool definitionToolResult: Encapsulates the result of a tool execution
Prompts
Prompts define reusable templates for LLM interactions:
Prompt: Represents a prompt definitionPromptArgument: Defines arguments for promptsPromptResult: Represents the result of a prompt execution
Server
The server components tie everything together:
McpServer: The main server class that manages connections, resources, tools, and promptsServerCapabilities: Defines the capabilities of the server
Quick Start
Basic CLI Server
Web Server with SSE
See the examples directory for a complete HTTP/SSE server implementation.
Advanced Usage
Working with Resources
Resources represent data sources that can be accessed by LLMs. To register a resource:
Working with Tools
Tools enable LLMs to perform actions and have side effects. To register a tool:
Working with Prompts
Prompts define reusable templates for LLM interactions. To register a prompt:
Running the Examples
The SDK includes several examples in the examples directory:
basic-server.php: A simple CLI-based MCP serverhttp-server.php: An HTTP server with SSE transportprompts-server.php: A server demonstrating the prompts feature
To run the basic server:
To run the HTTP server:
Then visit http://localhost:8080 in your browser.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.
All versions of mcp-php-sdk with dependencies
psr/log Version ^3.0
psr/http-message Version ^1.0
psr/event-dispatcher Version ^1.0
ramsey/uuid Version ^4.2
react/promise Version ^2.9