From 7fb85a732a31e1b9487f3a1de872777ab4fea294 Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Thu, 11 Dec 2025 10:06:53 -0600 Subject: [PATCH 1/3] Add API documentation generation with phpDocumentor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add phpDocumentor configuration and `docs` Makefile target - Generate docs during CI to catch errors before releases - Set up GitHub Pages with Jekyll for hosting generated docs - Add GitHub Actions workflow to deploy docs to GitHub Pages on releases 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .github/workflows/docs.yml | 38 +++++++++++++++++++++++++++++++++ .github/workflows/pipeline.yaml | 3 +++ .gitignore | 5 +++++ Makefile | 7 +++++- composer.json | 12 ++++++----- docs/_config.yml | 2 ++ docs/index.html | 12 +++++++++++ phpdoc.dist.xml | 25 ++++++++++++++++++++++ 8 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/docs.yml create mode 100644 docs/_config.yml create mode 100644 docs/index.html create mode 100644 phpdoc.dist.xml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 00000000..28a6f5f7 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,38 @@ +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 API Documentation + run: make docs + + - name: Copy API docs into docs directory + run: cp -r build/docs docs/api + + - name: Deploy to gh-pages branch + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs + enable_jekyll: true diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index 38926177..e98e285c 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -76,3 +76,6 @@ jobs: - name: PHPStan run: vendor/bin/phpstan analyse + + - name: Documentation + run: make docs diff --git a/.gitignore b/.gitignore index 8f118b26..ebde686f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,8 @@ vendor examples/**/dev.log examples/**/cache examples/**/sessions + +# phpDocumentor +build/ +.phpdoc/ +phpDocumentor.phar diff --git a/Makefile b/Makefile index 119e9d40..a96f4c61 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: deps-stable deps-low cs rector phpstan tests coverage run-examples ci ci-stable ci-lowest +.PHONY: deps-stable deps-low cs rector phpstan tests coverage run-examples ci ci-stable ci-lowest docs deps-stable: composer update --prefer-stable @@ -29,3 +29,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' build/docs/reports/errors.html || \ + (echo "Documentation errors found. See build/docs/reports/errors.html" && exit 1) diff --git a/composer.json b/composer.json index 411fe45a..4a47e0b9 100644 --- a/composer.json +++ b/composer.json @@ -33,17 +33,18 @@ "symfony/uid": "^6.4 || ^7.3 || ^8.0" }, "require-dev": { + "laminas/laminas-httphandlerrunner": "^2.12", + "nyholm/psr7": "^1.8", + "nyholm/psr7-server": "^1.1", "php-cs-fixer/shim": "^3.91", + "phpdocumentor/shim": "^3", "phpstan/phpstan": "^2.1", "phpunit/phpunit": "^10.5", "psr/cache": "^3.0", "psr/simple-cache": "^3.0", "symfony/cache": "^6.4 || ^7.3 || ^8.0", "symfony/console": "^6.4 || ^7.3 || ^8.0", - "symfony/process": "^6.4 || ^7.3 || ^8.0", - "nyholm/psr7": "^1.8", - "nyholm/psr7-server": "^1.1", - "laminas/laminas-httphandlerrunner": "^2.12" + "symfony/process": "^6.4 || ^7.3 || ^8.0" }, "autoload": { "psr-4": { @@ -69,7 +70,8 @@ "config": { "sort-packages": true, "allow-plugins": { - "php-http/discovery": false + "php-http/discovery": false, + "phpdocumentor/shim": true } } } diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 00000000..b3611564 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1,2 @@ +include: + - _* diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 00000000..c6cf2f25 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,12 @@ + + + + + + + MCP PHP SDK Documentation + + +

Redirecting to API Documentation...

+ + diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml new file mode 100644 index 00000000..c9d7920d --- /dev/null +++ b/phpdoc.dist.xml @@ -0,0 +1,25 @@ + + + MCP PHP SDK + + build/docs + + + + + src + + api + + vendor/**/* + tests/**/* + + + + + From a97a5dc69e61f9ac79f3b3688b48b5010fed398b Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Thu, 11 Dec 2025 10:18:12 -0600 Subject: [PATCH 2/3] Fix phpDocumentor errors in type annotations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change class-string union types to use phpDocumentor-compatible syntax and reorder docblock tags so class descriptions precede `@author` tags. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/JsonRpc/MessageFactory.php | 6 +++--- src/Server/Session/Psr16StoreSession.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/JsonRpc/MessageFactory.php b/src/JsonRpc/MessageFactory.php index 2ca446c2..1bb82db8 100644 --- a/src/JsonRpc/MessageFactory.php +++ b/src/JsonRpc/MessageFactory.php @@ -37,7 +37,7 @@ final class MessageFactory /** * Registry of all known message classes that have methods. * - * @var array> + * @var list|class-string> */ private const REGISTERED_MESSAGES = [ Schema\Notification\CancelledNotification::class, @@ -68,7 +68,7 @@ final class MessageFactory ]; /** - * @param array> $registeredMessages + * @param list|class-string> $registeredMessages */ public function __construct( private readonly array $registeredMessages, @@ -151,7 +151,7 @@ private function createMessage(array $data): MessageInterface /** * Finds the registered message class for a given method name. * - * @return class-string + * @return class-string|class-string * * @throws InvalidInputMessageException */ diff --git a/src/Server/Session/Psr16StoreSession.php b/src/Server/Session/Psr16StoreSession.php index aacf0ffc..2f403f1a 100644 --- a/src/Server/Session/Psr16StoreSession.php +++ b/src/Server/Session/Psr16StoreSession.php @@ -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 { From b55e15dbe5ab10b5b47237c491ef4f1d62eb7eac Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Thu, 11 Dec 2025 10:47:21 -0600 Subject: [PATCH 3/3] Fix CI: pin phar-io/composer-distributor ^1.0.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit phar-io/composer-distributor 1.0.0 has a bug where it uses the wrong package version when determining the phpDocumentor download URL, causing CI to fail with 404 errors when using --prefer-lowest. Version 1.0.2 fixes this issue. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 4a47e0b9..53f92793 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,7 @@ "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",