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
+5-57Lines changed: 5 additions & 57 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,10 @@
1
-
# Laravel MCP
1
+
# Laravel MCP Server SDK
2
2
3
3
> [!IMPORTANT]
4
-
> We don't recommend using this package yet. This package is only for [Boost](https://github.com/laravel/boost) use currently. A full release of the Laravel MCP server package will be released soon.
5
-
6
-
4
+
> This package is still in development and not recommended for public usage. This package is currently only intended to power [Boost](https://github.com/laravel/boost).
7
5
8
6
---
9
7
10
-
11
-
12
8
## Introduction
13
9
14
10
Laravel MCP makes it easy to add MCP servers to your project and let AI talk to your apps.
This will create two files: `app/Mcp/Servers/DemoServer.php` and `app/Mcp/Tools/HelloTool.php`.
51
45
52
-
53
-
54
-
**Add the tool to the server**
46
+
**Add the Tool to the Server**
55
47
56
48
Open `app/Mcp/Servers/DemoServer.php` and add your new tool to the `$tools` property:
57
49
@@ -71,8 +63,6 @@ class DemoServer extends Server
71
63
}
72
64
```
73
65
74
-
75
-
76
66
Next, register your server in `routes/ai.php`:
77
67
78
68
```php
@@ -82,16 +72,12 @@ use Laravel\Mcp\Server\Facades\Mcp;
82
72
Mcp::local('demo', DemoServer::class);
83
73
```
84
74
85
-
86
-
87
75
Finally, you can test it with the MCP Inspector tool:
88
76
89
77
```bash
90
78
php artisan mcp:inspector demo
91
79
```
92
80
93
-
94
-
95
81
## Creating Servers
96
82
97
83
A server is the central point that handles communication and exposes MCP methods, like tools and resources. Create a server with the `make:mcp-server` Artisan command:
@@ -100,22 +86,16 @@ A server is the central point that handles communication and exposes MCP methods
100
86
php artisan make:mcp-server ExampleServer
101
87
```
102
88
103
-
104
-
105
89
## Creating Tools
106
90
107
91
[Tools](https://modelcontextprotocol.io/docs/concepts/tools) let your server expose functionality that clients can call, and that language models can use to perform actions, run code, or interact with external systems.
108
92
109
-
110
-
111
93
Use the `mcp:tool` Artisan command to generate a tool class:
112
94
113
95
```bash
114
96
php artisan make:mcp-tool ExampleTool
115
97
```
116
98
117
-
118
-
119
99
### Tool Inputs
120
100
121
101
Your tools can request arguments from the MCP client using a tool input schema:
@@ -131,8 +111,6 @@ public function schema(ToolInputSchema $schema): ToolInputSchema
131
111
}
132
112
```
133
113
134
-
135
-
136
114
### Annotating Tools
137
115
138
116
You can add annotations to your tools to provide hints to the MCP client about their behavior. This is done using PHP attributes on your tool class. Adding annotations to your tools is optional.
@@ -164,8 +142,6 @@ class ExampleTool extends Tool
164
142
}
165
143
```
166
144
167
-
168
-
169
145
### Tool Results
170
146
171
147
The `handle` method of a tool must return an instance of `Laravel\Mcp\Server\Tools\ToolResult`. This class provides a few convenient methods for creating responses.
For tools that send multiple updates or stream large amounts of data, you can return a generator from the `handle()` method. For web-based servers, this automatically opens an SSE stream and sends an event for each message the generator yields.
@@ -239,55 +211,37 @@ class ChatStreamingTool extends Tool
239
211
}
240
212
```
241
213
242
-
243
-
244
-
245
-
246
214
## Creating Resources
247
215
248
216
[Resources](https://modelcontextprotocol.io/docs/concepts/resources) let your server expose data and content that clients can read and use as context when interacting with language models.
249
217
250
-
251
-
252
218
Use the `make:mcp-resource` Artisan command to generate a resource class:
253
219
254
220
```bash
255
221
php artisan make:mcp-resource ExampleResource
256
222
```
257
223
258
-
259
-
260
224
To make a resource available to clients, you must register it in your server class in the `$resources` property.
261
225
262
-
263
-
264
-
265
-
266
226
## Creating Prompts
267
227
268
228
[Prompts](https://modelcontextprotocol.io/docs/concepts/prompts) let your server share reusable prompts that clients can use to prompt the LLM.
269
229
270
-
271
-
272
230
Use the `make:mcp-prompt` Artisan command to generate a prompt class:
273
231
274
232
```bash
275
233
php artisan make:mcp-prompt ExamplePrompt
276
234
```
277
235
278
-
279
-
280
236
To make a prompt available to clients, you must register it in your server class in the `$prompts` property.
281
237
282
-
283
-
284
238
## Registering Servers
285
239
286
240
The easiest way to register MCP servers is by publishing the `routes/ai.php` file included with the package. If this file exists, the package will automatically load any servers registered via the `Mcp` facade. You can expose a server over HTTP or make it available locally as an Artisan command.
287
241
288
242
### Web Servers
289
243
290
-
To register a web-based MCP server that can be accessed via HTTP POST requests:
244
+
To register a web-based MCP server that can be accessed via HTTP POST requests, you should use the `web` method:
291
245
292
246
```php
293
247
use App\Mcp\Servers\ExampleServer;
@@ -317,8 +271,6 @@ This makes the server available via the `mcp:start` Artisan command:
317
271
php artisan mcp:start demo
318
272
```
319
273
320
-
321
-
322
274
## Authentication
323
275
324
276
Web-based MCP servers can be protected using [Laravel Passport](laravel.com/docs/passport), turning your MCP server into an OAuth2 protected resource.
@@ -347,8 +299,6 @@ Your MCP server is now protected using OAuth.
347
299
348
300
The [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector) is an interactive tool for testing and debugging your MCP servers. You can use it to connect to your server, verify authentication, and try out tools, resources, and other parts of the protocol.
0 commit comments