GitHub - modelcontextprotocol/php-sdk: The official PHP SDK for Model Context Protocol servers and clients. Maintained in collaboration with The PHP Foundation. · GitHub
https://github.com/modelcontextprotocol/php-sdk • 352 KB fetched
Open original page
GitHub - modelcontextprotocol/php-sdk: The official PHP SDK for Model Context Protocol servers and clients. Maintained in collaboration with The PHP Foundation. · GitHub
Skip to content
Navigation Menu
Sign in Appearance settings
* Platform
* AI CODE CREATION
* GitHub Copilot Write better code with AI
* GitHub Copilot app Direct agents from issue to merge
* MCP Registry Integrate external tools
* DEVELOPER WORKFLOWS
* Actions Automate any workflow
* Codespaces Instant dev environments
* Issues Plan and track work
* Code Review Manage code changes
* Code Quality Enforce quality at merge
* APPLICATION SECURITY
* GitHub Advanced Security Find and fix vulnerabilities
* Code security Secure your code as you build
* Secret protection Stop leaks before they start
* EXPLORE
* Why GitHub
* Documentation
* Blog
* Changelog
* Marketplace
View all features
* Solutions
* BY COMPANY SIZE
* Enterprises
* Small and medium teams
* Startups
* Nonprofits
* BY USE CASE
* App Modernization
* DevSecOps
* DevOps
* CI/CD
* View all use cases
* BY INDUSTRY
* Healthcare
* Financial services
* Manufacturing
* Government
* View all industries
View all solutions
* Resources
* EXPLORE BY TOPIC
* AI
* Software Development
* DevOps
* Security
* View all topics
* EXPLORE BY TYPE
* Customer stories
* Events & webinars
* Ebooks & reports
* Business insights
* GitHub Skills
* SUPPORT & SERVICES
* Documentation
* Customer support
* Community forum
* Trust center
* Partners
View all resources
* Open Source
* COMMUNITY
* GitHub Sponsors Fund open source developers
* PROGRAMS
* Security Lab
* Maintainer Community
* GitHub Stars
* Archive Program
* REPOSITORIES
* Topics
* Trending
* Collections
* Enterprise
* ENTERPRISE SOLUTIONS
* Enterprise platform AI-powered developer platform
* AVAILABLE ADD-ONS
* GitHub Advanced Security Enterprise-grade security features
* Copilot for Business Enterprise-grade AI features
* Premium Support Enterprise-grade 24/7 support
* Pricing
Search /
Sign in
Sign up Appearance settings
You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.
You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
Uh oh!
There was an error while loading. Please reload this page .
modelcontextprotocol
/
php-sdk
Public
*
Notifications
You must be signed in to change notification settings
*
Fork
169
*
Star
1.6k
*
Code
*
Issues
56
*
Pull requests
13
*
Actions
*
Projects
*
Security and quality
1
*
Insights
Additional navigation options
*
Code
*
Issues
*
Pull requests
*
Actions
*
Projects
*
Security and quality
*
Insights
main
Branches Tags
Go to file
Code Open more actions menu
Latest commit
History
289 Commits
289 Commits
Folders and files
Name Name Last commit message
Last commit date
.github
.github
.phpdoc/ template
.phpdoc/ template
adr
adr
docs
docs
examples
examples
src
src
tests
tests
.gitattributes
.gitattributes
.gitignore
.gitignore
.php-cs-fixer.dist.php
.php-cs-fixer.dist.php
CHANGELOG.md
CHANGELOG.md
CONTRIBUTING.md
CONTRIBUTING.md
LICENSE
LICENSE
Makefile
Makefile
README.md
README.md
ROADMAP.md
ROADMAP.md
SECURITY.md
SECURITY.md
composer.json
composer.json
mkdocs.yml
mkdocs.yml
phpdoc.dist.xml
phpdoc.dist.xml
phpstan-baseline.neon
phpstan-baseline.neon
phpstan.dist.neon
phpstan.dist.neon
phpunit.xml.dist
phpunit.xml.dist
requirements-docs.txt
requirements-docs.txt
View all files
Repository files navigation
*
* README
* Code of conduct
* Contributing
* License
* Security
More items
MCP PHP SDK
The official PHP SDK for the Model Context Protocol (MCP). It provides a framework-agnostic API for implementing MCP
servers and clients in PHP — tools, resources, prompts, STDIO and HTTP transports, sessions, authorization, and both
protocol eras (the initialize handshake and the stateless 2026-07-28 revision).
This project represents a collaboration between the PHP Foundation and the Symfony project . It adopts
development practices and standards from the Symfony project, including Coding Standards and the
Backward Compatibility Promise .
Until the first major release, this SDK is considered experimental , please see the roadmap for
planned next steps and features.
Protocol Conformance
Measured weekly against the MCP Conformance Test Framework ,
as passing checks out of total. The 2026-07-28 scores run against the framework's alpha releases, so they move as
upstream publishes new scenarios.
Revision
Server
Client
2026-07-28
2025-11-25
Installation
composer require mcp/sdk
Build a server
A server is a plain PHP class plus three lines of wiring:
use Mcp \ Capability \ Attribute \ McpResource ;
use Mcp \ Capability \ Attribute \ McpTool ;
use Mcp \ Server ;
use Mcp \ Server \ Transport \ StdioTransport ;
class Calculator
{
/**
* Adds two numbers.
*/
#[McpTool]
public function add ( int $ a , int $ b ): int
{
return $ a + $ b ;
}
#[McpResource(uri: ' config://calculator/settings ' )]
public function settings (): array
{
return [ ' precision ' => 2 ];
}
}
exit (Server:: builder ()
-> setServerInfo ( ' Calculator ' , ' 1.0.0 ' )
-> setDiscovery ( __DIR__ , [ ' . ' ], excludeDirs: [ ' vendor ' ])
-> build ()
-> run ( new StdioTransport ()));
The walkthrough in First server explains each piece, and
Try it with the Inspector shows it running.
Build a client
use Mcp \ Client ;
use Mcp \ Client \ Transport \ StdioTransport ;
$ client = Client:: builder ()
-> setClientInfo ( ' My Application ' , ' 1.0.0 ' )
-> build ();
$ client -> connect ( new StdioTransport (command: ' php ' , args: [ ' /path/to/server.php ' ]));
$ tools = $ client -> listTools ();
$ result = $ client -> callTool ( ' add ' , [ ' a ' => 5 , ' b ' => 3 ]);
$ client -> disconnect ();
See Connecting to a server for transports, timeouts, and the
handlers that answer server-initiated requests.
Documentation
The full documentation is published at php.sdk.modelcontextprotocol.io .
* Get started — Install the SDK and build your first server
* Servers — Tools, resources, resource templates, prompts, and how to register them
* Inside your handler — Talking back to the client, logging, and asking for input
* Running your server — Server builder, STDIO and HTTP transports, framework integration, sessions, authorization
* Clients — Client SDK for connecting to and communicating with MCP servers
* Protocol versions — The two protocol eras, and what revision 2026-07-28 changed
* Advanced — Events, protocol extensions (including MCP Apps), and custom message handlers
* Examples — Runnable server and client examples
* API Reference — Generated class reference
External Resources
* Model Context Protocol Documentation — Official MCP documentation
* Model Context Protocol Specification — Protocol specification
* Officially Supported Servers — Reference server implementations
PHP Libraries Using the MCP SDK
* api-platform/mcp — MCP integration for API Platform
* bnomei/kirby-mcp — MCP server for the Kirby CMS
* drupal/mcp_server — MCP server for Drupal exposing configuration and entities as MCP elements
* josbeir/cakephp-synapse — CakePHP plugin exposing application functionality over MCP
* nette/mcp-inspector — MCP server for introspecting Nette applications
* symfony/ai-mate — AI development assistant MCP server for Symfony projects
* symfony/mcp-bundle — Symfony integration bundle
Building something on top of the SDK? Open a pull request to add it to this list.
Contributing
We are passionate about supporting contributors of all levels of experience and would love to see you get involved in
the project. Start by reporting issues or
sending pull requests . See
CONTRIBUTING.md for development setup, coding standards, and what to run before
opening a PR.
Credits
The starting point for this SDK was the PHP-MCP project, initiated by Kyrian Obikwelu , and the Symfony AI initiative . We are grateful for the work done by both projects and their contributors, which created a solid foundation for this SDK.
License
This project is licensed under the Apache License, Version 2.0 for new contributions, with existing code under the MIT License — see the LICENSE file for details.
About
The official PHP SDK for Model Context Protocol servers and clients. Maintained in collaboration with The PHP Foundation.
php.sdk.modelcontextprotocol.io
Topics
mcp mcp-client mcp-server php
Resources
Readme
License
Code of conduct
Code of conduct
Contributing
Contributing
Security policy
Security policy
Activity
Custom properties
Stars
1.6k stars
Watchers
24 watching
Forks
169 forks
Report repository
Releases
Used by
Contributors
Languages
Footer
(c) 2026 GitHub, Inc.
Footer navigation
*
Terms
*
Privacy
*
Security
*
Status
*
Community
*
Docs
*
Contact
*
Manage cookies
*
Do not share my personal information
You can’t perform that action at this time.
Links found on this page
- Skip to content [direct]
- Sign in [direct]
- GitHub Copilot Write better code with AI [direct]
- GitHub Copilot app Direct agents from issue to merge [direct]
- MCP Registry Integrate external tools [direct]
- Actions Automate any workflow [direct]
- Codespaces Instant dev environments [direct]
- Issues Plan and track work [direct]
- Code Review Manage code changes [direct]
- Code Quality Enforce quality at merge [direct]
- GitHub Advanced Security Find and fix vulnerabilities [direct]
- Code security Secure your code as you build [direct]
- Secret protection Stop leaks before they start [direct]
- Why GitHub [direct]
- Documentation [direct]
- Blog [direct]
- Changelog [direct]
- Marketplace [direct]
- View all features [direct]
- Enterprises [direct]
- Small and medium teams [direct]
- Startups [direct]
- Nonprofits [direct]
- App Modernization [direct]
- DevSecOps [direct]
- DevOps [direct]
- CI/CD [direct]
- View all use cases [direct]
- Healthcare [direct]
- Financial services [direct]
- Manufacturing [direct]
- Government [direct]
- View all industries [direct]
- View all solutions [direct]
- AI [direct]
- Software Development [direct]
- DevOps [direct]
- Security [direct]
- View all topics [direct]
- Customer stories [direct]
- Events & webinars [direct]
- Ebooks & reports [direct]
- Business insights [direct]
- GitHub Skills [direct]
- Customer support [direct]
- Community forum [direct]
- Trust center [direct]
- Partners [direct]
- View all resources [direct]
- GitHub Sponsors Fund open source developers [direct]
- Security Lab [direct]
- Maintainer Community [direct]
- GitHub Stars [direct]
- Archive Program [direct]
- Topics [direct]
- Trending [direct]
- Collections [direct]
- Copilot for Business Enterprise-grade AI features [direct]
- Premium Support Enterprise-grade 24/7 support [direct]
- Pricing [direct]
- Sign up [direct]
- modelcontextprotocol [direct]
- Notifications [direct]
- Issues
56 [direct]
- Pull requests
13 [direct]
- Actions [direct]
- Projects [direct]
- Security and quality
1 [direct]
- Insights [direct]
- Branches [direct]
- Tags [direct]
- 289 Commits [direct]
- .github [direct]
- .phpdoc/ template [direct]
- adr [direct]
- docs [direct]
- examples [direct]
- src [direct]
- tests [direct]
- .gitattributes [direct]