Skip to content

Commit 5efdd93

Browse files
feat: Overhaul package for php-mcp/server v2.x compatibility and improved DX
1 parent 44b8217 commit 5efdd93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2913
-760
lines changed

.github/workflows/changelog.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "Update Changelog"
2+
3+
on:
4+
release:
5+
types: [released]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
update:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
ref: main
19+
20+
- name: Update Changelog
21+
uses: stefanzweifel/changelog-updater-action@v1
22+
with:
23+
latest-version: ${{ github.event.release.name }}
24+
release-notes: ${{ github.event.release.body }}
25+
26+
- name: Commit updated CHANGELOG
27+
uses: stefanzweifel/git-auto-commit-action@v5
28+
with:
29+
branch: main
30+
commit_message: Update CHANGELOG
31+
file_pattern: CHANGELOG.md

.github/workflows/tests.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Tests
2+
3+
on: ['push', 'pull_request']
4+
5+
jobs:
6+
ci:
7+
runs-on: ubuntu-latest
8+
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
php: [8.1, 8.2, 8.3, 8.4]
13+
max-parallel: 4
14+
15+
name: Tests PHP${{ matrix.php }}
16+
17+
steps:
18+
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Cache dependencies
23+
uses: actions/cache@v4
24+
with:
25+
path: ~/.composer/cache/files
26+
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
27+
28+
- name: Setup PHP
29+
uses: shivammathur/setup-php@v2
30+
with:
31+
php-version: ${{ matrix.php }}
32+
coverage: none
33+
34+
- name: Install Composer dependencies
35+
run: composer update --no-interaction --prefer-dist
36+
37+
- name: Run Tests
38+
run: composer test

CHANGELOG.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Changelog
2+
3+
All notable changes to `php-mcp/laravel` will be documented in this file.
4+
5+
## v1.1.1 - 2025-05-12
6+
7+
### What's Changed
8+
* McpServiceProvider File And loadElements function are not found by @tsztodd in https://github.com/php-mcp/laravel/pull/2
9+
10+
### New Contributors
11+
* @tsztodd made their first contribution in https://github.com/php-mcp/laravel/pull/2
12+
13+
**Full Changelog**: https://github.com/php-mcp/laravel/compare/1.1.0...1.1.1
14+
15+
## v1.1.0 - 2025-05-01
16+
17+
This release updates the package for compatibility with `php-mcp/server` v1.1.0.
18+
19+
### What Changed
20+
21+
* Updated dependency requirement to `php-mcp/server: ^1.1.0`.
22+
* Modified `McpServiceProvider` to correctly provide `ConfigurationRepositoryInterface`, `LoggerInterface`, and `CacheInterface` bindings to the underlying `Server` instance when resolved from the Laravel container.
23+
* Updated `ServeCommand` and `McpController` to inject the `Server` instance and instantiate `TransportHandler` classes according to `php-mcp/server` v1.1.0 constructor changes.
24+
25+
### Fixed
26+
27+
* Ensures compatibility with the refactored dependency injection and transport handler instantiation logic in `php-mcp/server` v1.1.0.
28+
29+
**Full Changelog**: https://github.com/php-mcp/laravel/compare/1.0.0...1.1.0
30+
31+
# Release v1.0.0 - Initial Release
32+
33+
**Initial Release**
34+
35+
Welcome to the first release of `php-mcp/laravel`! This package provides seamless integration of the core [`php-mcp/server`](https://github.com/php-mcp/server) package with your Laravel application, allowing you to expose application functionality as Model Context Protocol (MCP) tools, resources, and prompts using simple PHP attributes.
36+
37+
## Key Features
38+
39+
* **Effortless Integration:** Automatically wires up Laravel's Cache, Logger, and Service Container for use by the MCP server.
40+
* **Attribute-Based Definition:** Define MCP tools, resources, and prompts using PHP attributes (`#[McpTool]`, `#[McpResource]`, etc.) within your Laravel application structure. Leverage Laravel's Dependency Injection within your MCP element classes.
41+
* **Configuration:** Provides a publishable configuration file (`config/mcp.php`) for fine-grained control over discovery, transports, caching, and capabilities.
42+
* **Artisan Commands:** Includes commands for element discovery (`mcp:discover`), listing discovered elements (`mcp:list`), and running the server via stdio (`mcp:serve`).
43+
* **HTTP+SSE Transport:** Sets up routes (`/mcp/message`, `/mcp/sse` by default) and a controller for handling MCP communication over HTTP, enabling browser-based clients and other HTTP consumers.
44+
* **Automatic Discovery (Dev):** Automatically discovers MCP elements in development environments on first use, improving developer experience (no need to manually run `mcp:discover` after changes).
45+
* **Manual Discovery (Prod):** Requires manual discovery (`mcp:discover`) for production environments, ensuring optimal performance via caching (integrates well with deployment workflows).
46+
* **Event Integration:** Dispatches Laravel events (`ToolsListChanged`, `ResourcesListChanged`, `PromptsListChanged`) when element lists change, allowing for custom integrations or notifications.
47+
48+
## Installation
49+
50+
Installation is straightforward using Composer. See the [README Installation Guide](https://github.com/php-mcp/laravel/blob/main/README.md#installation) for full details.
51+
52+
```bash
53+
# 1. Require the package
54+
composer require php-mcp/laravel
55+
56+
# 2. Publish the configuration file (optional but recommended)
57+
php artisan vendor:publish --provider="PhpMcp\Laravel\Server\McpServiceProvider" --tag="mcp-config"
58+
```
59+
60+
## Getting Started
61+
62+
1. **Define Elements:** Create PHP classes with methods annotated with `#[McpTool]`, `#[McpResource]`, etc., within directories specified in `config/mcp.php` (e.g., `app/Mcp`). Inject dependencies as needed. See [Defining MCP Elements](https://github.com/php-mcp/laravel/blob/main/README.md#defining-mcp-elements).
63+
2. **Discovery:**
64+
* In development, discovery runs automatically when needed.
65+
* In production, run `php artisan mcp:discover` during your deployment process. See [Automatic Discovery vs. Manual Discovery](https://github.com/php-mcp/laravel/blob/main/README.md#automatic-discovery-development-vs-manual-discovery-production).
66+
3. **Run the Server:**
67+
* For **Stdio Transport:** Use `php artisan mcp:serve` and configure your client to execute this command (using the full path to `artisan`).
68+
* For **HTTP+SSE Transport:** Ensure `transports.http.enabled` is true, run your Laravel app on a suitable web server (Nginx+FPM, Octane, etc. - **not** `php artisan serve`), exclude the MCP route from CSRF protection, and configure your client with the SSE URL (e.g., `http://your-app.test/mcp/sse`). See [Running the Server](https://github.com/php-mcp/laravel/blob/main/README.md#running-the-server) for critical details.
69+
70+
## Important Notes
71+
72+
* **HTTP Transport Server Requirement:** The standard `php artisan serve` development server is **not suitable** for the HTTP+SSE transport due to its single-process nature. Use a proper web server setup like Nginx/Apache + PHP-FPM or Laravel Octane.
73+
* **CSRF Exclusion:** If using the default `web` middleware group for the HTTP transport, you **must** exclude the MCP message route (default: `mcp` or `mcp/*`) from CSRF protection in your application to avoid `419` errors.
74+
* **Dependencies:** Requires PHP >= 8.1 and Laravel >= 10.0.
75+
76+
## Links
77+
78+
* **GitHub Repository:** https://github.com/php-mcp/laravel
79+
* **Packagist:** https://packagist.org/packages/php-mcp/laravel
80+
81+
Please report any issues or provide feedback on the GitHub repository.

0 commit comments

Comments
 (0)