Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/docs.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
name: Deploy Documentation

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: "none"

- name: Install Composer
uses: "ramsey/composer-install@v3"

- name: Generate Documentation
run: make docs

- name: Deploy to gh-pages branch
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./.phpdoc/build
enable_jekyll: false
3 changes: 3 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,3 +142,6 @@ jobs:

- name: PHPStan
run: vendor/bin/phpstan analyse

- name: Documentation
run: make docs
4 changes: 4 additions & 0 deletions .gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,3 +9,7 @@ examples/**/sessions
tests/Conformance/results
tests/Conformance/sessions
tests/Conformance/logs/*.log

# phpDocumentor
.phpdoc/build/
.phpdoc/cache/
13 changes: 13 additions & 0 deletions .phpdoc/template/base.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
{% extends 'layout.html.twig' %}

{% set topMenu = {
"menu": [
{ "name": "Guides", "url": "docs/index.html"},
{ "name": "Specification", "url": "https://modelcontextprotocol.io/" }
],
"social": [
{ "iconClass": "fab fa-github", "url": "https://github.com/modelcontextprotocol/php-sdk"},
{ "iconClass": "fab fa-discord", "url": "https://discord.gg/6CSzBmMkjX"}
]
}
%}
10 changes: 10 additions & 0 deletions .phpdoc/template/components/header-title.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<h1 class="phpdocumentor-title">
<a href="{{ path('/docs/index.html') }}" class="phpdocumentor-title__link">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 195 195" fill="none">
<path d="M25 97.8528L92.8823 29.9706C102.255 20.598 117.451 20.598 126.823 29.9706V29.9706C136.196 39.3431 136.196 54.5391 126.823 63.9117L75.5581 115.177" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M76.2653 114.47L126.823 63.9117C136.196 54.5391 151.392 54.5391 160.765 63.9117L161.118 64.2652C170.491 73.6378 170.491 88.8338 161.118 98.2063L99.7248 159.6C96.6006 162.724 96.6006 167.789 99.7248 170.913L112.331 183.52" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M109.853 46.9411L59.6482 97.1457C50.2757 106.518 50.2757 121.714 59.6482 131.087V131.087C69.0208 140.459 84.2168 140.459 93.5894 131.087L143.794 80.8822" stroke="black" stroke-width="12" stroke-linecap="round"/>
</svg>
<span style="margin-left: 0.25em;">{{ project.name }}</span>
</a>
</h1>
7 changes: 6 additions & 1 deletion Makefile
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests docs

deps-stable:
composer update --prefer-stable
Expand DownExpand Up@@ -36,3 +36,8 @@ ci: ci-stable
ci-stable: deps-stable cs phpstan tests

ci-lowest: deps-low cs phpstan tests

docs:
vendor/bin/phpdoc
@grep -q 'No errors have been found' .phpdoc/build/reports/errors.html || \
(echo "Documentation errors found. See build/docs/reports/errors.html" && exit 1)
5 changes: 4 additions & 1 deletion composer.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,7 +36,9 @@
"laminas/laminas-httphandlerrunner": "^2.12",
"nyholm/psr7": "^1.8",
"nyholm/psr7-server": "^1.1",
"phar-io/composer-distributor": "^1.0.2",
"php-cs-fixer/shim": "^3.91",
"phpdocumentor/shim": "^3",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^10.5",
"psr/simple-cache": "^2.0 || ^3.0",
Expand DownExpand Up@@ -69,7 +71,8 @@
},
"config": {
"allow-plugins": {
"php-http/discovery": false
"php-http/discovery": false,
"phpdocumentor/shim": true
},
"sort-packages": true
}
Expand Down
7 changes: 7 additions & 0 deletions docs/index.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# MCP PHP SDK Guides

- [MCP Elements](mcp-elements.md) — Core capabilities (Tools, Resources, Resource Templates, and Prompts) with registration methods.
- [Server Builder](server-builder.md) — Fluent builder class for creating and configuring MCP server instances.
- [Transports](transports.md) — STDIO and HTTP transport implementations with guidance on choosing between them.
- [Server-Client Communication](server-client-communication.md) — Methods for servers to communicate back to clients: sampling, logging, progress, and notifications.
- [Examples](examples.md) — Example projects demonstrating attribute-based discovery, dependency injection, HTTP transport, and more.
File renamed without changes.
44 changes: 44 additions & 0 deletions phpdoc.dist.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="https://docs.phpdoc.org/latest/phpdoc.xsd"
>
<title>MCP PHP SDK</title>
<paths>
<output>.phpdoc/build</output>
</paths>
<version number="latest">
<folder>latest</folder>
<api ignore-packages="true">
<source dsn=".">
<path>src</path>
</source>
<output>api</output>
<ignore>
<path>vendor/**/*</path>
<path>tests/**/*</path>
</ignore>
<ignore-tags>
<ignore-tag>phpstan-type</ignore-tag>
<ignore-tag>phpstan-type-import</ignore-tag>
<ignore-tag>template</ignore-tag>
<ignore-tag>template-covariant</ignore-tag>
<ignore-tag>template-extends</ignore-tag>
<ignore-tag>template-implements</ignore-tag>
<ignore-tag>extends</ignore-tag>
<ignore-tag>implements</ignore-tag>
</ignore-tags>
</api>
<guide format="md">
<source dsn=".">
<path>docs</path>
</source>
<output>/</output>
</guide>
</version>
<setting name="guides.enabled" value="true"/>
<setting name="graphs.enabled" value="false"/>
<setting name="template.color" value="black"/>
</phpdocumentor>
6 changes: 3 additions & 3 deletions src/JsonRpc/MessageFactory.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ final class MessageFactory
/**
* Registry of all known message classes that have methods.
*
* @var array<int, class-string<Request|Notification>>
* @var list<class-string<Request>|class-string<Notification>>
*/
private const REGISTERED_MESSAGES = [
Schema\Notification\CancelledNotification::class,
Expand DownExpand Up@@ -68,7 +68,7 @@ final class MessageFactory
];

/**
* @param array<int, class-string<Request|Notification>> $registeredMessages
* @param list<class-string<Request>|class-string<Notification>> $registeredMessages
*/
public function __construct(
private readonly array $registeredMessages,
Expand DownExpand Up@@ -151,7 +151,7 @@ private function createMessage(array $data): MessageInterface
/**
* Finds the registered message class for a given method name.
*
* @return class-string<Request|Notification>
* @return class-string<Request>|class-string<Notification>
*
* @throws InvalidInputMessageException
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Session/Psr16StoreSession.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,12 +17,12 @@
use Symfony\Component\Uid\Uuid;

/**
* @author luoyue <1569097443@qq.com>
*
* PSR-16 compliant cache-based session store.
*
* This implementation uses any PSR-16 compliant cache as the storage backend
* for session data. Each session is stored with a prefixed key using the session ID.
*
* @author luoyue <1569097443@qq.com>
*/
class Psr16StoreSession implements SessionStoreInterface
{
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/docs.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
name: Deploy Documentation

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: "none"

- name: Install Composer
uses: "ramsey/composer-install@v3"

- name: Generate Documentation
run: make docs

- name: Deploy to gh-pages branch
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./.phpdoc/build
enable_jekyll: false
3 changes: 3 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,3 +142,6 @@ jobs:

- name: PHPStan
run: vendor/bin/phpstan analyse

- name: Documentation
run: make docs
4 changes: 4 additions & 0 deletions .gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,3 +9,7 @@ examples/**/sessions
tests/Conformance/results
tests/Conformance/sessions
tests/Conformance/logs/*.log

# phpDocumentor
.phpdoc/build/
.phpdoc/cache/
13 changes: 13 additions & 0 deletions .phpdoc/template/base.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
{% extends 'layout.html.twig' %}

{% set topMenu = {
"menu": [
{ "name": "Guides", "url": "docs/index.html"},
{ "name": "Specification", "url": "https://modelcontextprotocol.io/" }
],
"social": [
{ "iconClass": "fab fa-github", "url": "https://github.com/modelcontextprotocol/php-sdk"},
{ "iconClass": "fab fa-discord", "url": "https://discord.gg/6CSzBmMkjX"}
]
}
%}
10 changes: 10 additions & 0 deletions .phpdoc/template/components/header-title.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<h1 class="phpdocumentor-title">
<a href="{{ path('/docs/index.html') }}" class="phpdocumentor-title__link">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 195 195" fill="none">
<path d="M25 97.8528L92.8823 29.9706C102.255 20.598 117.451 20.598 126.823 29.9706V29.9706C136.196 39.3431 136.196 54.5391 126.823 63.9117L75.5581 115.177" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M76.2653 114.47L126.823 63.9117C136.196 54.5391 151.392 54.5391 160.765 63.9117L161.118 64.2652C170.491 73.6378 170.491 88.8338 161.118 98.2063L99.7248 159.6C96.6006 162.724 96.6006 167.789 99.7248 170.913L112.331 183.52" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M109.853 46.9411L59.6482 97.1457C50.2757 106.518 50.2757 121.714 59.6482 131.087V131.087C69.0208 140.459 84.2168 140.459 93.5894 131.087L143.794 80.8822" stroke="black" stroke-width="12" stroke-linecap="round"/>
</svg>
<span style="margin-left: 0.25em;">{{ project.name }}</span>
</a>
</h1>
7 changes: 6 additions & 1 deletion Makefile
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests docs

deps-stable:
composer update --prefer-stable
Expand DownExpand Up@@ -36,3 +36,8 @@ ci: ci-stable
ci-stable: deps-stable cs phpstan tests

ci-lowest: deps-low cs phpstan tests

docs:
vendor/bin/phpdoc
@grep -q 'No errors have been found' .phpdoc/build/reports/errors.html || \
(echo "Documentation errors found. See build/docs/reports/errors.html" && exit 1)
5 changes: 4 additions & 1 deletion composer.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,7 +36,9 @@
"laminas/laminas-httphandlerrunner": "^2.12",
"nyholm/psr7": "^1.8",
"nyholm/psr7-server": "^1.1",
"phar-io/composer-distributor": "^1.0.2",
"php-cs-fixer/shim": "^3.91",
"phpdocumentor/shim": "^3",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^10.5",
"psr/simple-cache": "^2.0 || ^3.0",
Expand DownExpand Up@@ -69,7 +71,8 @@
},
"config": {
"allow-plugins": {
"php-http/discovery": false
"php-http/discovery": false,
"phpdocumentor/shim": true
},
"sort-packages": true
}
Expand Down
7 changes: 7 additions & 0 deletions docs/index.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# MCP PHP SDK Guides

- [MCP Elements](mcp-elements.md) — Core capabilities (Tools, Resources, Resource Templates, and Prompts) with registration methods.
- [Server Builder](server-builder.md) — Fluent builder class for creating and configuring MCP server instances.
- [Transports](transports.md) — STDIO and HTTP transport implementations with guidance on choosing between them.
- [Server-Client Communication](server-client-communication.md) — Methods for servers to communicate back to clients: sampling, logging, progress, and notifications.
- [Examples](examples.md) — Example projects demonstrating attribute-based discovery, dependency injection, HTTP transport, and more.
File renamed without changes.
44 changes: 44 additions & 0 deletions phpdoc.dist.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="https://docs.phpdoc.org/latest/phpdoc.xsd"
>
<title>MCP PHP SDK</title>
<paths>
<output>.phpdoc/build</output>
</paths>
<version number="latest">
<folder>latest</folder>
<api ignore-packages="true">
<source dsn=".">
<path>src</path>
</source>
<output>api</output>
<ignore>
<path>vendor/**/*</path>
<path>tests/**/*</path>
</ignore>
<ignore-tags>
<ignore-tag>phpstan-type</ignore-tag>
<ignore-tag>phpstan-type-import</ignore-tag>
<ignore-tag>template</ignore-tag>
<ignore-tag>template-covariant</ignore-tag>
<ignore-tag>template-extends</ignore-tag>
<ignore-tag>template-implements</ignore-tag>
<ignore-tag>extends</ignore-tag>
<ignore-tag>implements</ignore-tag>
</ignore-tags>
</api>
<guide format="md">
<source dsn=".">
<path>docs</path>
</source>
<output>/</output>
</guide>
</version>
<setting name="guides.enabled" value="true"/>
<setting name="graphs.enabled" value="false"/>
<setting name="template.color" value="black"/>
</phpdocumentor>
6 changes: 3 additions & 3 deletions src/JsonRpc/MessageFactory.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ final class MessageFactory
/**
* Registry of all known message classes that have methods.
*
* @var array<int, class-string<Request|Notification>>
* @var list<class-string<Request>|class-string<Notification>>
*/
private const REGISTERED_MESSAGES = [
Schema\Notification\CancelledNotification::class,
Expand DownExpand Up@@ -68,7 +68,7 @@ final class MessageFactory
];

/**
* @param array<int, class-string<Request|Notification>> $registeredMessages
* @param list<class-string<Request>|class-string<Notification>> $registeredMessages
*/
public function __construct(
private readonly array $registeredMessages,
Expand DownExpand Up@@ -151,7 +151,7 @@ private function createMessage(array $data): MessageInterface
/**
* Finds the registered message class for a given method name.
*
* @return class-string<Request|Notification>
* @return class-string<Request>|class-string<Notification>
*
* @throws InvalidInputMessageException
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Session/Psr16StoreSession.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,12 +17,12 @@
use Symfony\Component\Uid\Uuid;

/**
* @author luoyue <1569097443@qq.com>
*
* PSR-16 compliant cache-based session store.
*
* This implementation uses any PSR-16 compliant cache as the storage backend
* for session data. Each session is stored with a prefixed key using the session ID.
*
* @author luoyue <1569097443@qq.com>
*/
class Psr16StoreSession implements SessionStoreInterface
{
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/docs.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
name: Deploy Documentation

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: "none"

- name: Install Composer
uses: "ramsey/composer-install@v3"

- name: Generate Documentation
run: make docs

- name: Deploy to gh-pages branch
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./.phpdoc/build
enable_jekyll: false
3 changes: 3 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,3 +142,6 @@ jobs:

- name: PHPStan
run: vendor/bin/phpstan analyse

- name: Documentation
run: make docs
4 changes: 4 additions & 0 deletions .gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,3 +9,7 @@ examples/**/sessions
tests/Conformance/results
tests/Conformance/sessions
tests/Conformance/logs/*.log

# phpDocumentor
.phpdoc/build/
.phpdoc/cache/
13 changes: 13 additions & 0 deletions .phpdoc/template/base.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
{% extends 'layout.html.twig' %}

{% set topMenu = {
"menu": [
{ "name": "Guides", "url": "docs/index.html"},
{ "name": "Specification", "url": "https://modelcontextprotocol.io/" }
],
"social": [
{ "iconClass": "fab fa-github", "url": "https://github.com/modelcontextprotocol/php-sdk"},
{ "iconClass": "fab fa-discord", "url": "https://discord.gg/6CSzBmMkjX"}
]
}
%}
10 changes: 10 additions & 0 deletions .phpdoc/template/components/header-title.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<h1 class="phpdocumentor-title">
<a href="{{ path('/docs/index.html') }}" class="phpdocumentor-title__link">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 195 195" fill="none">
<path d="M25 97.8528L92.8823 29.9706C102.255 20.598 117.451 20.598 126.823 29.9706V29.9706C136.196 39.3431 136.196 54.5391 126.823 63.9117L75.5581 115.177" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M76.2653 114.47L126.823 63.9117C136.196 54.5391 151.392 54.5391 160.765 63.9117L161.118 64.2652C170.491 73.6378 170.491 88.8338 161.118 98.2063L99.7248 159.6C96.6006 162.724 96.6006 167.789 99.7248 170.913L112.331 183.52" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M109.853 46.9411L59.6482 97.1457C50.2757 106.518 50.2757 121.714 59.6482 131.087V131.087C69.0208 140.459 84.2168 140.459 93.5894 131.087L143.794 80.8822" stroke="black" stroke-width="12" stroke-linecap="round"/>
</svg>
<span style="margin-left: 0.25em;">{{ project.name }}</span>
</a>
</h1>
7 changes: 6 additions & 1 deletion Makefile
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests docs

deps-stable:
composer update --prefer-stable
Expand DownExpand Up@@ -36,3 +36,8 @@ ci: ci-stable
ci-stable: deps-stable cs phpstan tests

ci-lowest: deps-low cs phpstan tests

docs:
vendor/bin/phpdoc
@grep -q 'No errors have been found' .phpdoc/build/reports/errors.html || \
(echo "Documentation errors found. See build/docs/reports/errors.html" && exit 1)
5 changes: 4 additions & 1 deletion composer.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,7 +36,9 @@
"laminas/laminas-httphandlerrunner": "^2.12",
"nyholm/psr7": "^1.8",
"nyholm/psr7-server": "^1.1",
"phar-io/composer-distributor": "^1.0.2",
"php-cs-fixer/shim": "^3.91",
"phpdocumentor/shim": "^3",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^10.5",
"psr/simple-cache": "^2.0 || ^3.0",
Expand DownExpand Up@@ -69,7 +71,8 @@
},
"config": {
"allow-plugins": {
"php-http/discovery": false
"php-http/discovery": false,
"phpdocumentor/shim": true
},
"sort-packages": true
}
Expand Down
7 changes: 7 additions & 0 deletions docs/index.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# MCP PHP SDK Guides

- [MCP Elements](mcp-elements.md) — Core capabilities (Tools, Resources, Resource Templates, and Prompts) with registration methods.
- [Server Builder](server-builder.md) — Fluent builder class for creating and configuring MCP server instances.
- [Transports](transports.md) — STDIO and HTTP transport implementations with guidance on choosing between them.
- [Server-Client Communication](server-client-communication.md) — Methods for servers to communicate back to clients: sampling, logging, progress, and notifications.
- [Examples](examples.md) — Example projects demonstrating attribute-based discovery, dependency injection, HTTP transport, and more.
File renamed without changes.
44 changes: 44 additions & 0 deletions phpdoc.dist.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="https://docs.phpdoc.org/latest/phpdoc.xsd"
>
<title>MCP PHP SDK</title>
<paths>
<output>.phpdoc/build</output>
</paths>
<version number="latest">
<folder>latest</folder>
<api ignore-packages="true">
<source dsn=".">
<path>src</path>
</source>
<output>api</output>
<ignore>
<path>vendor/**/*</path>
<path>tests/**/*</path>
</ignore>
<ignore-tags>
<ignore-tag>phpstan-type</ignore-tag>
<ignore-tag>phpstan-type-import</ignore-tag>
<ignore-tag>template</ignore-tag>
<ignore-tag>template-covariant</ignore-tag>
<ignore-tag>template-extends</ignore-tag>
<ignore-tag>template-implements</ignore-tag>
<ignore-tag>extends</ignore-tag>
<ignore-tag>implements</ignore-tag>
</ignore-tags>
</api>
<guide format="md">
<source dsn=".">
<path>docs</path>
</source>
<output>/</output>
</guide>
</version>
<setting name="guides.enabled" value="true"/>
<setting name="graphs.enabled" value="false"/>
<setting name="template.color" value="black"/>
</phpdocumentor>
6 changes: 3 additions & 3 deletions src/JsonRpc/MessageFactory.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ final class MessageFactory
/**
* Registry of all known message classes that have methods.
*
* @var array<int, class-string<Request|Notification>>
* @var list<class-string<Request>|class-string<Notification>>
*/
private const REGISTERED_MESSAGES = [
Schema\Notification\CancelledNotification::class,
Expand DownExpand Up@@ -68,7 +68,7 @@ final class MessageFactory
];

/**
* @param array<int, class-string<Request|Notification>> $registeredMessages
* @param list<class-string<Request>|class-string<Notification>> $registeredMessages
*/
public function __construct(
private readonly array $registeredMessages,
Expand DownExpand Up@@ -151,7 +151,7 @@ private function createMessage(array $data): MessageInterface
/**
* Finds the registered message class for a given method name.
*
* @return class-string<Request|Notification>
* @return class-string<Request>|class-string<Notification>
*
* @throws InvalidInputMessageException
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Session/Psr16StoreSession.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,12 +17,12 @@
use Symfony\Component\Uid\Uuid;

/**
* @author luoyue <1569097443@qq.com>
*
* PSR-16 compliant cache-based session store.
*
* This implementation uses any PSR-16 compliant cache as the storage backend
* for session data. Each session is stored with a prefixed key using the session ID.
*
* @author luoyue <1569097443@qq.com>
*/
class Psr16StoreSession implements SessionStoreInterface
{
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/docs.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
name: Deploy Documentation

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: "none"

- name: Install Composer
uses: "ramsey/composer-install@v3"

- name: Generate Documentation
run: make docs

- name: Deploy to gh-pages branch
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./.phpdoc/build
enable_jekyll: false
3 changes: 3 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,3 +142,6 @@ jobs:

- name: PHPStan
run: vendor/bin/phpstan analyse

- name: Documentation
run: make docs
4 changes: 4 additions & 0 deletions .gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,3 +9,7 @@ examples/**/sessions
tests/Conformance/results
tests/Conformance/sessions
tests/Conformance/logs/*.log

# phpDocumentor
.phpdoc/build/
.phpdoc/cache/
13 changes: 13 additions & 0 deletions .phpdoc/template/base.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
{% extends 'layout.html.twig' %}

{% set topMenu = {
"menu": [
{ "name": "Guides", "url": "docs/index.html"},
{ "name": "Specification", "url": "https://modelcontextprotocol.io/" }
],
"social": [
{ "iconClass": "fab fa-github", "url": "https://github.com/modelcontextprotocol/php-sdk"},
{ "iconClass": "fab fa-discord", "url": "https://discord.gg/6CSzBmMkjX"}
]
}
%}
10 changes: 10 additions & 0 deletions .phpdoc/template/components/header-title.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<h1 class="phpdocumentor-title">
<a href="{{ path('/docs/index.html') }}" class="phpdocumentor-title__link">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 195 195" fill="none">
<path d="M25 97.8528L92.8823 29.9706C102.255 20.598 117.451 20.598 126.823 29.9706V29.9706C136.196 39.3431 136.196 54.5391 126.823 63.9117L75.5581 115.177" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M76.2653 114.47L126.823 63.9117C136.196 54.5391 151.392 54.5391 160.765 63.9117L161.118 64.2652C170.491 73.6378 170.491 88.8338 161.118 98.2063L99.7248 159.6C96.6006 162.724 96.6006 167.789 99.7248 170.913L112.331 183.52" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M109.853 46.9411L59.6482 97.1457C50.2757 106.518 50.2757 121.714 59.6482 131.087V131.087C69.0208 140.459 84.2168 140.459 93.5894 131.087L143.794 80.8822" stroke="black" stroke-width="12" stroke-linecap="round"/>
</svg>
<span style="margin-left: 0.25em;">{{ project.name }}</span>
</a>
</h1>
7 changes: 6 additions & 1 deletion Makefile
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests docs

deps-stable:
composer update --prefer-stable
Expand DownExpand Up@@ -36,3 +36,8 @@ ci: ci-stable
ci-stable: deps-stable cs phpstan tests

ci-lowest: deps-low cs phpstan tests

docs:
vendor/bin/phpdoc
@grep -q 'No errors have been found' .phpdoc/build/reports/errors.html || \
(echo "Documentation errors found. See build/docs/reports/errors.html" && exit 1)
5 changes: 4 additions & 1 deletion composer.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,7 +36,9 @@
"laminas/laminas-httphandlerrunner": "^2.12",
"nyholm/psr7": "^1.8",
"nyholm/psr7-server": "^1.1",
"phar-io/composer-distributor": "^1.0.2",
"php-cs-fixer/shim": "^3.91",
"phpdocumentor/shim": "^3",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^10.5",
"psr/simple-cache": "^2.0 || ^3.0",
Expand DownExpand Up@@ -69,7 +71,8 @@
},
"config": {
"allow-plugins": {
"php-http/discovery": false
"php-http/discovery": false,
"phpdocumentor/shim": true
},
"sort-packages": true
}
Expand Down
7 changes: 7 additions & 0 deletions docs/index.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# MCP PHP SDK Guides

- [MCP Elements](mcp-elements.md) — Core capabilities (Tools, Resources, Resource Templates, and Prompts) with registration methods.
- [Server Builder](server-builder.md) — Fluent builder class for creating and configuring MCP server instances.
- [Transports](transports.md) — STDIO and HTTP transport implementations with guidance on choosing between them.
- [Server-Client Communication](server-client-communication.md) — Methods for servers to communicate back to clients: sampling, logging, progress, and notifications.
- [Examples](examples.md) — Example projects demonstrating attribute-based discovery, dependency injection, HTTP transport, and more.
File renamed without changes.
44 changes: 44 additions & 0 deletions phpdoc.dist.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="https://docs.phpdoc.org/latest/phpdoc.xsd"
>
<title>MCP PHP SDK</title>
<paths>
<output>.phpdoc/build</output>
</paths>
<version number="latest">
<folder>latest</folder>
<api ignore-packages="true">
<source dsn=".">
<path>src</path>
</source>
<output>api</output>
<ignore>
<path>vendor/**/*</path>
<path>tests/**/*</path>
</ignore>
<ignore-tags>
<ignore-tag>phpstan-type</ignore-tag>
<ignore-tag>phpstan-type-import</ignore-tag>
<ignore-tag>template</ignore-tag>
<ignore-tag>template-covariant</ignore-tag>
<ignore-tag>template-extends</ignore-tag>
<ignore-tag>template-implements</ignore-tag>
<ignore-tag>extends</ignore-tag>
<ignore-tag>implements</ignore-tag>
</ignore-tags>
</api>
<guide format="md">
<source dsn=".">
<path>docs</path>
</source>
<output>/</output>
</guide>
</version>
<setting name="guides.enabled" value="true"/>
<setting name="graphs.enabled" value="false"/>
<setting name="template.color" value="black"/>
</phpdocumentor>
6 changes: 3 additions & 3 deletions src/JsonRpc/MessageFactory.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ final class MessageFactory
/**
* Registry of all known message classes that have methods.
*
* @var array<int, class-string<Request|Notification>>
* @var list<class-string<Request>|class-string<Notification>>
*/
private const REGISTERED_MESSAGES = [
Schema\Notification\CancelledNotification::class,
Expand DownExpand Up@@ -68,7 +68,7 @@ final class MessageFactory
];

/**
* @param array<int, class-string<Request|Notification>> $registeredMessages
* @param list<class-string<Request>|class-string<Notification>> $registeredMessages
*/
public function __construct(
private readonly array $registeredMessages,
Expand DownExpand Up@@ -151,7 +151,7 @@ private function createMessage(array $data): MessageInterface
/**
* Finds the registered message class for a given method name.
*
* @return class-string<Request|Notification>
* @return class-string<Request>|class-string<Notification>
*
* @throws InvalidInputMessageException
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Session/Psr16StoreSession.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,12 +17,12 @@
use Symfony\Component\Uid\Uuid;

/**
* @author luoyue <1569097443@qq.com>
*
* PSR-16 compliant cache-based session store.
*
* This implementation uses any PSR-16 compliant cache as the storage backend
* for session data. Each session is stored with a prefixed key using the session ID.
*
* @author luoyue <1569097443@qq.com>
*/
class Psr16StoreSession implements SessionStoreInterface
{
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/docs.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
name: Deploy Documentation

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: "none"

- name: Install Composer
uses: "ramsey/composer-install@v3"

- name: Generate Documentation
run: make docs

- name: Deploy to gh-pages branch
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./.phpdoc/build
enable_jekyll: false
3 changes: 3 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,3 +142,6 @@ jobs:

- name: PHPStan
run: vendor/bin/phpstan analyse

- name: Documentation
run: make docs
4 changes: 4 additions & 0 deletions .gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,3 +9,7 @@ examples/**/sessions
tests/Conformance/results
tests/Conformance/sessions
tests/Conformance/logs/*.log

# phpDocumentor
.phpdoc/build/
.phpdoc/cache/
13 changes: 13 additions & 0 deletions .phpdoc/template/base.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
{% extends 'layout.html.twig' %}

{% set topMenu = {
"menu": [
{ "name": "Guides", "url": "docs/index.html"},
{ "name": "Specification", "url": "https://modelcontextprotocol.io/" }
],
"social": [
{ "iconClass": "fab fa-github", "url": "https://github.com/modelcontextprotocol/php-sdk"},
{ "iconClass": "fab fa-discord", "url": "https://discord.gg/6CSzBmMkjX"}
]
}
%}
10 changes: 10 additions & 0 deletions .phpdoc/template/components/header-title.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<h1 class="phpdocumentor-title">
<a href="{{ path('/docs/index.html') }}" class="phpdocumentor-title__link">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 195 195" fill="none">
<path d="M25 97.8528L92.8823 29.9706C102.255 20.598 117.451 20.598 126.823 29.9706V29.9706C136.196 39.3431 136.196 54.5391 126.823 63.9117L75.5581 115.177" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M76.2653 114.47L126.823 63.9117C136.196 54.5391 151.392 54.5391 160.765 63.9117L161.118 64.2652C170.491 73.6378 170.491 88.8338 161.118 98.2063L99.7248 159.6C96.6006 162.724 96.6006 167.789 99.7248 170.913L112.331 183.52" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M109.853 46.9411L59.6482 97.1457C50.2757 106.518 50.2757 121.714 59.6482 131.087V131.087C69.0208 140.459 84.2168 140.459 93.5894 131.087L143.794 80.8822" stroke="black" stroke-width="12" stroke-linecap="round"/>
</svg>
<span style="margin-left: 0.25em;">{{ project.name }}</span>
</a>
</h1>
7 changes: 6 additions & 1 deletion Makefile
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests docs

deps-stable:
composer update --prefer-stable
Expand DownExpand Up@@ -36,3 +36,8 @@ ci: ci-stable
ci-stable: deps-stable cs phpstan tests

ci-lowest: deps-low cs phpstan tests

docs:
vendor/bin/phpdoc
@grep -q 'No errors have been found' .phpdoc/build/reports/errors.html || \
(echo "Documentation errors found. See build/docs/reports/errors.html" && exit 1)
5 changes: 4 additions & 1 deletion composer.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,7 +36,9 @@
"laminas/laminas-httphandlerrunner": "^2.12",
"nyholm/psr7": "^1.8",
"nyholm/psr7-server": "^1.1",
"phar-io/composer-distributor": "^1.0.2",
"php-cs-fixer/shim": "^3.91",
"phpdocumentor/shim": "^3",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^10.5",
"psr/simple-cache": "^2.0 || ^3.0",
Expand DownExpand Up@@ -69,7 +71,8 @@
},
"config": {
"allow-plugins": {
"php-http/discovery": false
"php-http/discovery": false,
"phpdocumentor/shim": true
},
"sort-packages": true
}
Expand Down
7 changes: 7 additions & 0 deletions docs/index.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# MCP PHP SDK Guides

- [MCP Elements](mcp-elements.md) — Core capabilities (Tools, Resources, Resource Templates, and Prompts) with registration methods.
- [Server Builder](server-builder.md) — Fluent builder class for creating and configuring MCP server instances.
- [Transports](transports.md) — STDIO and HTTP transport implementations with guidance on choosing between them.
- [Server-Client Communication](server-client-communication.md) — Methods for servers to communicate back to clients: sampling, logging, progress, and notifications.
- [Examples](examples.md) — Example projects demonstrating attribute-based discovery, dependency injection, HTTP transport, and more.
File renamed without changes.
44 changes: 44 additions & 0 deletions phpdoc.dist.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="https://docs.phpdoc.org/latest/phpdoc.xsd"
>
<title>MCP PHP SDK</title>
<paths>
<output>.phpdoc/build</output>
</paths>
<version number="latest">
<folder>latest</folder>
<api ignore-packages="true">
<source dsn=".">
<path>src</path>
</source>
<output>api</output>
<ignore>
<path>vendor/**/*</path>
<path>tests/**/*</path>
</ignore>
<ignore-tags>
<ignore-tag>phpstan-type</ignore-tag>
<ignore-tag>phpstan-type-import</ignore-tag>
<ignore-tag>template</ignore-tag>
<ignore-tag>template-covariant</ignore-tag>
<ignore-tag>template-extends</ignore-tag>
<ignore-tag>template-implements</ignore-tag>
<ignore-tag>extends</ignore-tag>
<ignore-tag>implements</ignore-tag>
</ignore-tags>
</api>
<guide format="md">
<source dsn=".">
<path>docs</path>
</source>
<output>/</output>
</guide>
</version>
<setting name="guides.enabled" value="true"/>
<setting name="graphs.enabled" value="false"/>
<setting name="template.color" value="black"/>
</phpdocumentor>
6 changes: 3 additions & 3 deletions src/JsonRpc/MessageFactory.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ final class MessageFactory
/**
* Registry of all known message classes that have methods.
*
* @var array<int, class-string<Request|Notification>>
* @var list<class-string<Request>|class-string<Notification>>
*/
private const REGISTERED_MESSAGES = [
Schema\Notification\CancelledNotification::class,
Expand DownExpand Up@@ -68,7 +68,7 @@ final class MessageFactory
];

/**
* @param array<int, class-string<Request|Notification>> $registeredMessages
* @param list<class-string<Request>|class-string<Notification>> $registeredMessages
*/
public function __construct(
private readonly array $registeredMessages,
Expand DownExpand Up@@ -151,7 +151,7 @@ private function createMessage(array $data): MessageInterface
/**
* Finds the registered message class for a given method name.
*
* @return class-string<Request|Notification>
* @return class-string<Request>|class-string<Notification>
*
* @throws InvalidInputMessageException
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Session/Psr16StoreSession.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,12 +17,12 @@
use Symfony\Component\Uid\Uuid;

/**
* @author luoyue <1569097443@qq.com>
*
* PSR-16 compliant cache-based session store.
*
* This implementation uses any PSR-16 compliant cache as the storage backend
* for session data. Each session is stored with a prefixed key using the session ID.
*
* @author luoyue <1569097443@qq.com>
*/
class Psr16StoreSession implements SessionStoreInterface
{
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/docs.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
name: Deploy Documentation

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: "none"

- name: Install Composer
uses: "ramsey/composer-install@v3"

- name: Generate Documentation
run: make docs

- name: Deploy to gh-pages branch
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./.phpdoc/build
enable_jekyll: false
3 changes: 3 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,3 +142,6 @@ jobs:

- name: PHPStan
run: vendor/bin/phpstan analyse

- name: Documentation
run: make docs
4 changes: 4 additions & 0 deletions .gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,3 +9,7 @@ examples/**/sessions
tests/Conformance/results
tests/Conformance/sessions
tests/Conformance/logs/*.log

# phpDocumentor
.phpdoc/build/
.phpdoc/cache/
13 changes: 13 additions & 0 deletions .phpdoc/template/base.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
{% extends 'layout.html.twig' %}

{% set topMenu = {
"menu": [
{ "name": "Guides", "url": "docs/index.html"},
{ "name": "Specification", "url": "https://modelcontextprotocol.io/" }
],
"social": [
{ "iconClass": "fab fa-github", "url": "https://github.com/modelcontextprotocol/php-sdk"},
{ "iconClass": "fab fa-discord", "url": "https://discord.gg/6CSzBmMkjX"}
]
}
%}
10 changes: 10 additions & 0 deletions .phpdoc/template/components/header-title.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<h1 class="phpdocumentor-title">
<a href="{{ path('/docs/index.html') }}" class="phpdocumentor-title__link">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 195 195" fill="none">
<path d="M25 97.8528L92.8823 29.9706C102.255 20.598 117.451 20.598 126.823 29.9706V29.9706C136.196 39.3431 136.196 54.5391 126.823 63.9117L75.5581 115.177" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M76.2653 114.47L126.823 63.9117C136.196 54.5391 151.392 54.5391 160.765 63.9117L161.118 64.2652C170.491 73.6378 170.491 88.8338 161.118 98.2063L99.7248 159.6C96.6006 162.724 96.6006 167.789 99.7248 170.913L112.331 183.52" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M109.853 46.9411L59.6482 97.1457C50.2757 106.518 50.2757 121.714 59.6482 131.087V131.087C69.0208 140.459 84.2168 140.459 93.5894 131.087L143.794 80.8822" stroke="black" stroke-width="12" stroke-linecap="round"/>
</svg>
<span style="margin-left: 0.25em;">{{ project.name }}</span>
</a>
</h1>
7 changes: 6 additions & 1 deletion Makefile
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests docs

deps-stable:
composer update --prefer-stable
Expand DownExpand Up@@ -36,3 +36,8 @@ ci: ci-stable
ci-stable: deps-stable cs phpstan tests

ci-lowest: deps-low cs phpstan tests

docs:
vendor/bin/phpdoc
@grep -q 'No errors have been found' .phpdoc/build/reports/errors.html || \
(echo "Documentation errors found. See build/docs/reports/errors.html" && exit 1)
5 changes: 4 additions & 1 deletion composer.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,7 +36,9 @@
"laminas/laminas-httphandlerrunner": "^2.12",
"nyholm/psr7": "^1.8",
"nyholm/psr7-server": "^1.1",
"phar-io/composer-distributor": "^1.0.2",
"php-cs-fixer/shim": "^3.91",
"phpdocumentor/shim": "^3",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^10.5",
"psr/simple-cache": "^2.0 || ^3.0",
Expand DownExpand Up@@ -69,7 +71,8 @@
},
"config": {
"allow-plugins": {
"php-http/discovery": false
"php-http/discovery": false,
"phpdocumentor/shim": true
},
"sort-packages": true
}
Expand Down
7 changes: 7 additions & 0 deletions docs/index.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# MCP PHP SDK Guides

- [MCP Elements](mcp-elements.md) — Core capabilities (Tools, Resources, Resource Templates, and Prompts) with registration methods.
- [Server Builder](server-builder.md) — Fluent builder class for creating and configuring MCP server instances.
- [Transports](transports.md) — STDIO and HTTP transport implementations with guidance on choosing between them.
- [Server-Client Communication](server-client-communication.md) — Methods for servers to communicate back to clients: sampling, logging, progress, and notifications.
- [Examples](examples.md) — Example projects demonstrating attribute-based discovery, dependency injection, HTTP transport, and more.
File renamed without changes.
44 changes: 44 additions & 0 deletions phpdoc.dist.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="https://docs.phpdoc.org/latest/phpdoc.xsd"
>
<title>MCP PHP SDK</title>
<paths>
<output>.phpdoc/build</output>
</paths>
<version number="latest">
<folder>latest</folder>
<api ignore-packages="true">
<source dsn=".">
<path>src</path>
</source>
<output>api</output>
<ignore>
<path>vendor/**/*</path>
<path>tests/**/*</path>
</ignore>
<ignore-tags>
<ignore-tag>phpstan-type</ignore-tag>
<ignore-tag>phpstan-type-import</ignore-tag>
<ignore-tag>template</ignore-tag>
<ignore-tag>template-covariant</ignore-tag>
<ignore-tag>template-extends</ignore-tag>
<ignore-tag>template-implements</ignore-tag>
<ignore-tag>extends</ignore-tag>
<ignore-tag>implements</ignore-tag>
</ignore-tags>
</api>
<guide format="md">
<source dsn=".">
<path>docs</path>
</source>
<output>/</output>
</guide>
</version>
<setting name="guides.enabled" value="true"/>
<setting name="graphs.enabled" value="false"/>
<setting name="template.color" value="black"/>
</phpdocumentor>
6 changes: 3 additions & 3 deletions src/JsonRpc/MessageFactory.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ final class MessageFactory
/**
* Registry of all known message classes that have methods.
*
* @var array<int, class-string<Request|Notification>>
* @var list<class-string<Request>|class-string<Notification>>
*/
private const REGISTERED_MESSAGES = [
Schema\Notification\CancelledNotification::class,
Expand DownExpand Up@@ -68,7 +68,7 @@ final class MessageFactory
];

/**
* @param array<int, class-string<Request|Notification>> $registeredMessages
* @param list<class-string<Request>|class-string<Notification>> $registeredMessages
*/
public function __construct(
private readonly array $registeredMessages,
Expand DownExpand Up@@ -151,7 +151,7 @@ private function createMessage(array $data): MessageInterface
/**
* Finds the registered message class for a given method name.
*
* @return class-string<Request|Notification>
* @return class-string<Request>|class-string<Notification>
*
* @throws InvalidInputMessageException
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Session/Psr16StoreSession.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,12 +17,12 @@
use Symfony\Component\Uid\Uuid;

/**
* @author luoyue <1569097443@qq.com>
*
* PSR-16 compliant cache-based session store.
*
* This implementation uses any PSR-16 compliant cache as the storage backend
* for session data. Each session is stored with a prefixed key using the session ID.
*
* @author luoyue <1569097443@qq.com>
*/
class Psr16StoreSession implements SessionStoreInterface
{
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/docs.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
name: Deploy Documentation

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: "none"

- name: Install Composer
uses: "ramsey/composer-install@v3"

- name: Generate Documentation
run: make docs

- name: Deploy to gh-pages branch
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./.phpdoc/build
enable_jekyll: false
3 changes: 3 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,3 +142,6 @@ jobs:

- name: PHPStan
run: vendor/bin/phpstan analyse

- name: Documentation
run: make docs
4 changes: 4 additions & 0 deletions .gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,3 +9,7 @@ examples/**/sessions
tests/Conformance/results
tests/Conformance/sessions
tests/Conformance/logs/*.log

# phpDocumentor
.phpdoc/build/
.phpdoc/cache/
13 changes: 13 additions & 0 deletions .phpdoc/template/base.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
{% extends 'layout.html.twig' %}

{% set topMenu = {
"menu": [
{ "name": "Guides", "url": "docs/index.html"},
{ "name": "Specification", "url": "https://modelcontextprotocol.io/" }
],
"social": [
{ "iconClass": "fab fa-github", "url": "https://github.com/modelcontextprotocol/php-sdk"},
{ "iconClass": "fab fa-discord", "url": "https://discord.gg/6CSzBmMkjX"}
]
}
%}
10 changes: 10 additions & 0 deletions .phpdoc/template/components/header-title.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<h1 class="phpdocumentor-title">
<a href="{{ path('/docs/index.html') }}" class="phpdocumentor-title__link">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 195 195" fill="none">
<path d="M25 97.8528L92.8823 29.9706C102.255 20.598 117.451 20.598 126.823 29.9706V29.9706C136.196 39.3431 136.196 54.5391 126.823 63.9117L75.5581 115.177" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M76.2653 114.47L126.823 63.9117C136.196 54.5391 151.392 54.5391 160.765 63.9117L161.118 64.2652C170.491 73.6378 170.491 88.8338 161.118 98.2063L99.7248 159.6C96.6006 162.724 96.6006 167.789 99.7248 170.913L112.331 183.52" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M109.853 46.9411L59.6482 97.1457C50.2757 106.518 50.2757 121.714 59.6482 131.087V131.087C69.0208 140.459 84.2168 140.459 93.5894 131.087L143.794 80.8822" stroke="black" stroke-width="12" stroke-linecap="round"/>
</svg>
<span style="margin-left: 0.25em;">{{ project.name }}</span>
</a>
</h1>
7 changes: 6 additions & 1 deletion Makefile
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests docs

deps-stable:
composer update --prefer-stable
Expand DownExpand Up@@ -36,3 +36,8 @@ ci: ci-stable
ci-stable: deps-stable cs phpstan tests

ci-lowest: deps-low cs phpstan tests

docs:
vendor/bin/phpdoc
@grep -q 'No errors have been found' .phpdoc/build/reports/errors.html || \
(echo "Documentation errors found. See build/docs/reports/errors.html" && exit 1)
5 changes: 4 additions & 1 deletion composer.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,7 +36,9 @@
"laminas/laminas-httphandlerrunner": "^2.12",
"nyholm/psr7": "^1.8",
"nyholm/psr7-server": "^1.1",
"phar-io/composer-distributor": "^1.0.2",
"php-cs-fixer/shim": "^3.91",
"phpdocumentor/shim": "^3",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^10.5",
"psr/simple-cache": "^2.0 || ^3.0",
Expand DownExpand Up@@ -69,7 +71,8 @@
},
"config": {
"allow-plugins": {
"php-http/discovery": false
"php-http/discovery": false,
"phpdocumentor/shim": true
},
"sort-packages": true
}
Expand Down
7 changes: 7 additions & 0 deletions docs/index.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# MCP PHP SDK Guides

- [MCP Elements](mcp-elements.md) — Core capabilities (Tools, Resources, Resource Templates, and Prompts) with registration methods.
- [Server Builder](server-builder.md) — Fluent builder class for creating and configuring MCP server instances.
- [Transports](transports.md) — STDIO and HTTP transport implementations with guidance on choosing between them.
- [Server-Client Communication](server-client-communication.md) — Methods for servers to communicate back to clients: sampling, logging, progress, and notifications.
- [Examples](examples.md) — Example projects demonstrating attribute-based discovery, dependency injection, HTTP transport, and more.
File renamed without changes.
44 changes: 44 additions & 0 deletions phpdoc.dist.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="https://docs.phpdoc.org/latest/phpdoc.xsd"
>
<title>MCP PHP SDK</title>
<paths>
<output>.phpdoc/build</output>
</paths>
<version number="latest">
<folder>latest</folder>
<api ignore-packages="true">
<source dsn=".">
<path>src</path>
</source>
<output>api</output>
<ignore>
<path>vendor/**/*</path>
<path>tests/**/*</path>
</ignore>
<ignore-tags>
<ignore-tag>phpstan-type</ignore-tag>
<ignore-tag>phpstan-type-import</ignore-tag>
<ignore-tag>template</ignore-tag>
<ignore-tag>template-covariant</ignore-tag>
<ignore-tag>template-extends</ignore-tag>
<ignore-tag>template-implements</ignore-tag>
<ignore-tag>extends</ignore-tag>
<ignore-tag>implements</ignore-tag>
</ignore-tags>
</api>
<guide format="md">
<source dsn=".">
<path>docs</path>
</source>
<output>/</output>
</guide>
</version>
<setting name="guides.enabled" value="true"/>
<setting name="graphs.enabled" value="false"/>
<setting name="template.color" value="black"/>
</phpdocumentor>
6 changes: 3 additions & 3 deletions src/JsonRpc/MessageFactory.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ final class MessageFactory
/**
* Registry of all known message classes that have methods.
*
* @var array<int, class-string<Request|Notification>>
* @var list<class-string<Request>|class-string<Notification>>
*/
private const REGISTERED_MESSAGES = [
Schema\Notification\CancelledNotification::class,
Expand DownExpand Up@@ -68,7 +68,7 @@ final class MessageFactory
];

/**
* @param array<int, class-string<Request|Notification>> $registeredMessages
* @param list<class-string<Request>|class-string<Notification>> $registeredMessages
*/
public function __construct(
private readonly array $registeredMessages,
Expand DownExpand Up@@ -151,7 +151,7 @@ private function createMessage(array $data): MessageInterface
/**
* Finds the registered message class for a given method name.
*
* @return class-string<Request|Notification>
* @return class-string<Request>|class-string<Notification>
*
* @throws InvalidInputMessageException
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Session/Psr16StoreSession.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,12 +17,12 @@
use Symfony\Component\Uid\Uuid;

/**
* @author luoyue <1569097443@qq.com>
*
* PSR-16 compliant cache-based session store.
*
* This implementation uses any PSR-16 compliant cache as the storage backend
* for session data. Each session is stored with a prefixed key using the session ID.
*
* @author luoyue <1569097443@qq.com>
*/
class Psr16StoreSession implements SessionStoreInterface
{
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/docs.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
name: Deploy Documentation

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: "none"

- name: Install Composer
uses: "ramsey/composer-install@v3"

- name: Generate Documentation
run: make docs

- name: Deploy to gh-pages branch
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./.phpdoc/build
enable_jekyll: false
3 changes: 3 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,3 +142,6 @@ jobs:

- name: PHPStan
run: vendor/bin/phpstan analyse

- name: Documentation
run: make docs
4 changes: 4 additions & 0 deletions .gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,3 +9,7 @@ examples/**/sessions
tests/Conformance/results
tests/Conformance/sessions
tests/Conformance/logs/*.log

# phpDocumentor
.phpdoc/build/
.phpdoc/cache/
13 changes: 13 additions & 0 deletions .phpdoc/template/base.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
{% extends 'layout.html.twig' %}

{% set topMenu = {
"menu": [
{ "name": "Guides", "url": "docs/index.html"},
{ "name": "Specification", "url": "https://modelcontextprotocol.io/" }
],
"social": [
{ "iconClass": "fab fa-github", "url": "https://github.com/modelcontextprotocol/php-sdk"},
{ "iconClass": "fab fa-discord", "url": "https://discord.gg/6CSzBmMkjX"}
]
}
%}
10 changes: 10 additions & 0 deletions .phpdoc/template/components/header-title.html.twig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<h1 class="phpdocumentor-title">
<a href="{{ path('/docs/index.html') }}" class="phpdocumentor-title__link">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 195 195" fill="none">
<path d="M25 97.8528L92.8823 29.9706C102.255 20.598 117.451 20.598 126.823 29.9706V29.9706C136.196 39.3431 136.196 54.5391 126.823 63.9117L75.5581 115.177" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M76.2653 114.47L126.823 63.9117C136.196 54.5391 151.392 54.5391 160.765 63.9117L161.118 64.2652C170.491 73.6378 170.491 88.8338 161.118 98.2063L99.7248 159.6C96.6006 162.724 96.6006 167.789 99.7248 170.913L112.331 183.52" stroke="black" stroke-width="12" stroke-linecap="round"/>
<path d="M109.853 46.9411L59.6482 97.1457C50.2757 106.518 50.2757 121.714 59.6482 131.087V131.087C69.0208 140.459 84.2168 140.459 93.5894 131.087L143.794 80.8822" stroke="black" stroke-width="12" stroke-linecap="round"/>
</svg>
<span style="margin-left: 0.25em;">{{ project.name }}</span>
</a>
</h1>
7 changes: 6 additions & 1 deletion Makefile
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests
.PHONY: deps-stable deps-low cs phpstan tests unit-tests inspector-tests coverage ci ci-stable ci-lowest conformance-tests docs

deps-stable:
composer update --prefer-stable
Expand DownExpand Up@@ -36,3 +36,8 @@ ci: ci-stable
ci-stable: deps-stable cs phpstan tests

ci-lowest: deps-low cs phpstan tests

docs:
vendor/bin/phpdoc
@grep -q 'No errors have been found' .phpdoc/build/reports/errors.html || \
(echo "Documentation errors found. See build/docs/reports/errors.html" && exit 1)
5 changes: 4 additions & 1 deletion composer.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,7 +36,9 @@
"laminas/laminas-httphandlerrunner": "^2.12",
"nyholm/psr7": "^1.8",
"nyholm/psr7-server": "^1.1",
"phar-io/composer-distributor": "^1.0.2",
"php-cs-fixer/shim": "^3.91",
"phpdocumentor/shim": "^3",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^10.5",
"psr/simple-cache": "^2.0 || ^3.0",
Expand DownExpand Up@@ -69,7 +71,8 @@
},
"config": {
"allow-plugins": {
"php-http/discovery": false
"php-http/discovery": false,
"phpdocumentor/shim": true
},
"sort-packages": true
}
Expand Down
7 changes: 7 additions & 0 deletions docs/index.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# MCP PHP SDK Guides

- [MCP Elements](mcp-elements.md) — Core capabilities (Tools, Resources, Resource Templates, and Prompts) with registration methods.
- [Server Builder](server-builder.md) — Fluent builder class for creating and configuring MCP server instances.
- [Transports](transports.md) — STDIO and HTTP transport implementations with guidance on choosing between them.
- [Server-Client Communication](server-client-communication.md) — Methods for servers to communicate back to clients: sampling, logging, progress, and notifications.
- [Examples](examples.md) — Example projects demonstrating attribute-based discovery, dependency injection, HTTP transport, and more.
File renamed without changes.
44 changes: 44 additions & 0 deletions phpdoc.dist.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="https://docs.phpdoc.org/latest/phpdoc.xsd"
>
<title>MCP PHP SDK</title>
<paths>
<output>.phpdoc/build</output>
</paths>
<version number="latest">
<folder>latest</folder>
<api ignore-packages="true">
<source dsn=".">
<path>src</path>
</source>
<output>api</output>
<ignore>
<path>vendor/**/*</path>
<path>tests/**/*</path>
</ignore>
<ignore-tags>
<ignore-tag>phpstan-type</ignore-tag>
<ignore-tag>phpstan-type-import</ignore-tag>
<ignore-tag>template</ignore-tag>
<ignore-tag>template-covariant</ignore-tag>
<ignore-tag>template-extends</ignore-tag>
<ignore-tag>template-implements</ignore-tag>
<ignore-tag>extends</ignore-tag>
<ignore-tag>implements</ignore-tag>
</ignore-tags>
</api>
<guide format="md">
<source dsn=".">
<path>docs</path>
</source>
<output>/</output>
</guide>
</version>
<setting name="guides.enabled" value="true"/>
<setting name="graphs.enabled" value="false"/>
<setting name="template.color" value="black"/>
</phpdocumentor>
6 changes: 3 additions & 3 deletions src/JsonRpc/MessageFactory.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ final class MessageFactory
/**
* Registry of all known message classes that have methods.
*
* @var array<int, class-string<Request|Notification>>
* @var list<class-string<Request>|class-string<Notification>>
*/
private const REGISTERED_MESSAGES = [
Schema\Notification\CancelledNotification::class,
Expand DownExpand Up@@ -68,7 +68,7 @@ final class MessageFactory
];

/**
* @param array<int, class-string<Request|Notification>> $registeredMessages
* @param list<class-string<Request>|class-string<Notification>> $registeredMessages
*/
public function __construct(
private readonly array $registeredMessages,
Expand DownExpand Up@@ -151,7 +151,7 @@ private function createMessage(array $data): MessageInterface
/**
* Finds the registered message class for a given method name.
*
* @return class-string<Request|Notification>
* @return class-string<Request>|class-string<Notification>
*
* @throws InvalidInputMessageException
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Session/Psr16StoreSession.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,12 +17,12 @@
use Symfony\Component\Uid\Uuid;

/**
* @author luoyue <1569097443@qq.com>
*
* PSR-16 compliant cache-based session store.
*
* This implementation uses any PSR-16 compliant cache as the storage backend
* for session data. Each session is stored with a prefixed key using the session ID.
*
* @author luoyue <1569097443@qq.com>
*/
class Psr16StoreSession implements SessionStoreInterface
{
Expand Down