You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-15Lines changed: 18 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -63,7 +63,7 @@ The primary way to configure the MCP server in Laravel is through the `config/mc
63
63
64
64
## Usage
65
65
66
-
### 1. Defining MCP Elements
66
+
### Defining MCP Elements
67
67
68
68
Define your MCP Tools, Resources, and Prompts as methods within PHP classes, decorated with attributes from the `php-mcp/server` package (`#[McpTool]`, `#[McpResource]`, `#[McpPrompt]`, etc.).
69
69
@@ -102,25 +102,28 @@ class MyTools
102
102
***Dependency Injection:** Your classes' constructors will be resolved using Laravel's service container, so you can inject any application dependencies (like the `LoggerInterface` above).
103
103
***Attribute Usage:** Refer to the [`php-mcp/server` README](https://github.com/php-mcp/server/blob/main/README.md#defining-mcp-elements-with-attributes) for detailed information on defining elements and formatting return values.
104
104
105
-
### 2. Running Discovery
105
+
### Automatic Discovery (Development) vs. Manual Discovery (Production)
106
106
107
-
Before clients can connect (especially via stdio), the server needs to discover your annotated elements.
107
+
The server needs to discover your annotated elements before clients can use them.
108
108
109
-
```bash
110
-
php artisan mcp:discover
111
-
```
112
-
This command scans the configured directories and caches the found elements using the configured Laravel cache store. It's recommended to run this during deployment or whenever your MCP elements change.
109
+
***Development:** In non-production environments (e.g., `APP_ENV=local`), the server will **automatically discover** elements the first time the MCP server is needed (like on the first relevant HTTP request or Artisan command). You generally **do not** need to run the command manually during development after adding or changing elements.
110
+
111
+
***Production:** For performance reasons, automatic discovery is **disabled**in production environments (`APP_ENV=production`). You **must run the discovery command manually** as part of your deployment process:
112
+
113
+
```bash
114
+
php artisan mcp:discover
115
+
```
113
116
114
-
### 3. Running the Server
117
+
This command scans the configured directories and caches the found elements using the configured Laravel cache store. Running it during deployment ensures your production environment uses the pre-discovered, cached elements for optimal performance.
118
+
119
+
*(You can still run `mcp:discover` manually in development if you wish, for example, to pre-populate the cache.)*
120
+
121
+
### Running the Server
115
122
116
123
You can expose your MCP server using either the stdio or HTTP+SSE transport.
117
124
118
125
**Stdio Transport:**
119
126
120
-
* Run the server using the Artisan command:
121
-
```bash
122
-
php artisan mcp:serve
123
-
```
124
127
* Configure your MCP client (Cursor, Claude Desktop) to connect via command. **Important:** Ensure you provide the **full path** to your project's `artisan` file.
@@ -142,7 +145,7 @@ You can expose your MCP server using either the stdio or HTTP+SSE transport.
142
145
**HTTP+SSE Transport:**
143
146
144
147
* **Enable:** Ensure `transports.http.enabled` is `true` in `config/mcp.php`.
145
-
***Routes:** The package automatically registers two routes (by default `/mcp/sse` [GET] and `/mcp` [POST]) using the configured prefix and middleware (`web` by default).
148
+
* **Routes:** The package automatically registers two routes (by default `/mcp/sse` [GET] and `/mcp/message` [POST]) using the configured prefix and middleware (`web` by default).
146
149
*
147
150
* **Web Server Environment (CRITICAL):**
148
151
* The built-in `php artisan serve` development server **cannot reliably handle** the concurrent nature of SSE (long-running GET request) and subsequent POST requests from the MCP client. This is because it runs as a single PHP process. You will likely encounter hangs or requests not being processed.
@@ -189,7 +192,7 @@ You can expose your MCP server using either the stdio or HTTP+SSE transport.
189
192
```
190
193
The server will automatically inform the client about the correct POST endpoint URL (including a unique `?clientId=...` query parameter) via the initial `endpoint` event sent over the SSE connection.
191
194
192
-
### 4. Other Commands
195
+
### Other Commands
193
196
194
197
***List Elements:** View the discovered MCP elements.
195
198
```bash
@@ -203,7 +206,7 @@ You can expose your MCP server using either the stdio or HTTP+SSE transport.
203
206
php artisan mcp:list --json
204
207
```
205
208
206
-
### 5. Dynamic Updates (Notifications)
209
+
### Dynamic Updates (Notifications)
207
210
208
211
If the list of available tools, resources, or prompts changes while the server is running, or if a specific resource's content is updated, you can notify connected clients (primarily useful for HTTP+SSE).
0 commit comments