Skip to content
Back to search

laravel-loop

Laravel Loop is a powerful Model Context Protocol (MCP) server designed specifically for Laravel applications. It connects your Laravel application with AI assistants using the MCP protocol.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/kirschbaum-development--laravel-loop/badge.svg)](/listings/kirschbaum-development--laravel-loop)

HTML

<a href="/listings/kirschbaum-development--laravel-loop"><img src="/api/listings/kirschbaum-development--laravel-loop/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

You can install the package via composer:

composer require kirschbaum-development/laravel-loop

Publish the configuration file:

php artisan vendor:publish --tag="loop-config"

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 314 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # Laravel Loop
  2. ![](images/laravel-loop.png)
  3. ![Laravel Supported Versions](https://img.shields.io/badge/laravel-10.x/11.x/12.x-green.svg)
  4. [![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
  5. [![Latest Version on Packagist](https://img.shields.io/packagist/v/kirschbaum-development/laravel-loop.svg?style=flat-square)](https://packagist.org/packages/kirschbaum-development/laravel-loop)
  6. Laravel Loop is a powerful Model Context Protocol (MCP) server designed specifically for Laravel applications. It connects your Laravel application with AI assistants using the MCP protocol.
  7. Laravel Loop uses [Prism](https://github.com/prism-php/prism) behind the scenes to build the tools.
  8. > [!IMPORTANT]
  9. > Laravel Loop and its pre-built tools are still in development and this is a beta version.
  10. ![](images/claude-desktop.png)
  11. ## What It Does
  12. Laravel Loop allows you to:
  13. - Create and expose your own tools directly integrated with your Laravel application
  14. - Connect with MCP clients like Claude Code, Cursor, Windsurf, and more
  15. **Pre-built tools:**
  16. * [Filament MCP Server](https://github.com/kirschbaum-development/laravel-loop-filament).
  17. * Laravel Model Tools (Interact with your models data): `Kirschbaum\Loop\Toolkits\LaravelModelToolkit` (Write operations to come)
  18. * Laravel Factories Tools (Create test data from your MCP Client): `Kirschbaum\Loop\Toolkits\LaravelFactoriesToolkit`
  19. * Stripe Tool (Interact with the Stripe API): `Kirschbaum\Loop\Tools\StripeTool`
  20. ## Installation
  21. You can install the package via composer:
  22. ```bash
  23. composer require kirschbaum-development/laravel-loop
  24. ```
  25. Publish the configuration file:
  26. ```bash
  27. php artisan vendor:publish --tag="loop-config"
  28. ```
  29. ## Usage
  30. First, you must register your tools (If you don't know where to put, put in `app/Providers/AppServiceProvider`).
  31. ```php
  32. use Illuminate\Support\ServiceProvider;
  33. use Kirschbaum\Loop\Facades\Loop;
  34. use Kirschbaum\Loop\Toolkits;
  35. use Kirschbaum\Loop\Tools;
  36. Loop::toolkit(Kirschbaum\Loop\Filament\FilamentToolkit::make());
  37. ```
  38. ### Custom Tools
  39. To build your own tools, you can use the `Loop::tool` method.
  40. ```php
  41. use Kirschbaum\Loop\Facades\Loop;
  42. use Kirschbaum\Loop\Tools\CustomTool;
  43. Loop::tool(
  44. CustomTool::make(
  45. name: 'custom_tool',
  46. description: 'This is a custom tool',
  47. )
  48. ->withStringParameter(name: 'name', description: 'The name of the user', required: true)
  49. ->withNumberParameter(name: 'age', description: 'The age of the user')
  50. ->using(function (string $name, ?int $age = null) {
  51. return sprintf('Hello, %s! You are %d years old.', $name, $age ?? 'unknown');
  52. }),
  53. );
  54. );
  55. ```
  56. The available parameters types can be found in the [Prism Tool Documentation](https://prismphp.com/core-concepts/tools-function-calling.html#parameter-definition).
  57. ### Custom Tool Objects
  58. You can also build your own tool classes. Each tool must implement the `Tool` contract, and return a `Prism\Prism\Tool` instance in the `build` method.
  59. ```php
  60. use Kirschbaum\Loop\Contracts\Tool;
  61. class HelloTool implements Tool
  62. {
  63. use \Kirschbaum\Loop\Concerns\Makeable;
  64. public function build(): \Prism\Prism\Tool
  65. {
  66. return app(\Prism\Prism\Tool::class)
  67. ->as($this->getName())
  68. ->for('Says hello to the user')
  69. ->withStringParameter('name', 'The name of the user to say hello to.', required: true)
  70. ->using(fn (string $name) => "Hello, $name!");
  71. }
  72. public function getName(): string
  73. {
  74. return 'hello';
  75. }
  76. }
  77. ```
  78. If you want to provide multiple similar tools, you can build a toolkit which returns a collection of tools.
  79. ```php
  80. use Kirschbaum\Loop\Collections\ToolCollection;
  81. use Kirschbaum\Loop\Contracts\Toolkit;
  82. class LaravelFactoriesToolkit implements Toolkit
  83. {
  84. use \Kirschbaum\Loop\Concerns\Makeable;
  85. public function getTools(): ToolCollection
  86. {
  87. return new ToolCollection([
  88. HelloTool::make(),
  89. GoodbyeTool::make(),
  90. ]);
  91. }
  92. }
  93. ```
  94. ***
  95. ## Connecting to the MCP server
  96. For this to be really useful, you need to connect your MCP client (Claude Code, Claude Desktop, Cursor, Windsurf, etc) to the Laravel LoopMCP server.
  97. The MCP protocol has two main transports to connect: STDIO and Streamable HTTP, and the deprecated HTTP+SSE transport. Laravel Loop supports all of them.
  98. The easiest way to configure your MCP client is to use the `php artisan loop:mcp:config` command. This will guide you through the process of configuring your MCP client.
  99. ```bash
  100. php artisan loop:mcp:generate-config
  101. ```
  102. ### STDIO
  103. To run the MCP server using STDIO, we provide the following artisan command:
  104. ```bash
  105. php artisan loop:mcp:start [--user-id=1 [--user-model=] [--auth-guard=] [--debug]
  106. ```
  107. To connect Laravel Loop MCP server to Claude Code, for example, you can use the following command:
  108. ```bash
  109. claude mcp add laravel-loop-mcp php /your/full/path/to/laravel/artisan loop:mcp:start
  110. # with an authenticated user
  111. claude mcp add laravel-loop-mcp php /your/full/path/to/laravel/artisan loop:mcp:start --user-id=1 --user-model=App\Models\User
  112. # with debug mode
  113. claude mcp add laravel-loop-mcp php /your/full/path/to/laravel/artisan loop:mcp:start --debug
  114. ```
  115. To configure Laravel Loop in Cursor, Claude or any MCP clients with a JSON config file:
  116. ```json
  117. {
  118. "mcpServers": {
  119. "laravel-loop-mcp": {
  120. "command": "php",
  121. "args": [
  122. "/your/full/path/to/laravel/artisan",
  123. "loop:mcp:start",
  124. "--user-id=1"
  125. ]
  126. }
  127. }
  128. }
  129. ```
  130. ### Streamable HTTP & SSE
  131. Having to run PHP or Node to run the MCP server can be annoying. To avoid this, you can use the Streamable HTTP or SSE transport, which connects the MCP client directly to your application via HTTP.
  132. Laravel Loop also supports the [streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports) and the deprecated [HTTP+SSE transport](https://modelcontextprotocol.io/specification/2024-11-05/basic/transports#http-with-sse).
  133. > [!IMPORTANT]
  134. > NOTE: The Streamable HTTP transport is new and not yet supported by all MCP clients, while the SSE (supported by most MCP clients) is deprecated.
  135. The following docs are for both transports. Please note you only need to enable one of them.
  136. #### 1. Enable and configure the transport
  137. To enable the Streamable HTTP transport, update your `.env` file:
  138. ```bash
  139. # streamable http
  140. LOOP_STREAMABLE_HTTP_ENABLED=true
  141. # sse
  142. LOOP_SSE_ENABLED=true
  143. ```
  144. **Note:** When using SSE, the default driver is `file`, which is the simplest and most convenient for local development. However, for production, we recommend using `redis` to avoid issues with file locking. You can change the driver and additional options in the `config/loop.php` file.
  145. This will expose two MCP endpoints:
  146. - `/mcp` that supports the new Streamable HTTP transport.
  147. - `/mcp/sse` that supports the deprecated HTTP+SSE transport.
  148. **Note:** If you are running your application locally with **https**, most clients will fail due to the self-signed certificates. To avoid this, use the STDIO transport or use the **http** protocol locally.
  149. #### 2. Configure authentication (optional)
  150. Be aware that if you are exposing your endpoint publicly, you are exposing your data to the world. To ensure your MCP endpoints are secure, make sure to configure the `streamable_http.middleware` or `sse.middleware` config options. We recommend using something like Sanctum (configured by default) to protected the endpoint.
  151. ```php
  152. [
  153. 'streamable_http' => [
  154. 'middleware' => ['auth:sanctum'],
  155. ],
  156. 'sse' => [
  157. 'middleware' => ['auth:sanctum'],
  158. ],
  159. ]
  160. ```
  161. #### 3. Add the MCP server to your client
  162. Then, you just need to configure the MCP server endpoint in your client:
  163. **Claude Code**
  164. ```bash
  165. claude mcp add laravel-loop-mcp http://your-url.test/mcp/sse -t sse
  166. ```
  167. **From JSON config file**
  168. ```json
  169. {
  170. "mcpServers": {
  171. "laravel-loop-mcp": {
  172. "url": "http://your-url.test/mcp/sse",
  173. }
  174. }
  175. }
  176. ```
  177. Please note that not all clients support direct SSE connections. For those situations, you can proxy it through the `mcp-remote` package. This requires you to have Node.js (> 20) installed. Below an example using the [mcp-remote](https://github.com/geelen/mcp-remote) package.
  178. ```json
  179. {
  180. "mcpServers": {
  181. "laravel-loop-mcp": {
  182. "command": "npx",
  183. "args": [
  184. "mcp-remote",
  185. "https://your-remote-url.com/mcp",
  186. "--header",
  187. "Authorization: Bearer ${AUTH_TOKEN}"
  188. ]
  189. }
  190. }
  191. }
  192. ```
  193. ***
  194. ## Troubleshooting
  195. **Connection failed: MCP error -32000: Connection closed**
  196. If you get this error, it likely means there's some error happening in your application. Check your applicationlogs for more details.
  197. **Error: spawn php ENOENT**
  198. This can happen when your "php" binary is not in the PATH. This can be solved in a few ways:
  199. - Add the path to your `.bashrc` or `.zshrc` file. Sometimes it can be only in the `.zshrc` file but applications like Claude use `.bashrc`.
  200. - Use the full path of the PHP binary. You can get it by running `which php` in your terminal.
  201. * This can be a good option to ensure you always use the proper version of PHP for a given project. If you use Herd, for example, your `php` will change depending on the selected version.
  202. **Manually call tools and verify output**
  203. Sometimes when building tools, you may be getting unexpected results and debugging from the MCP client can be difficult. You can manually call tools and verify the output by running the following command:
  204. ```bash
  205. php artisan loop:mcp:call
  206. ```
  207. **Make sure to check your application logs**
  208. If you are getting an unkown error, check your application logs for more details.
  209. ***
  210. ## Roadmap
  211. - [ ] Add a chat component to the package, so you can use the tools inside the application without an MCP client.
  212. - [ ] Refine the existing tools
  213. - [ ] Add write capabilities to the existing tools
  214. ## Security
  215. If you discover any security related issues, please email security@kirschbaumdevelopment.com instead of using the issue tracker.
  216. ## Sponsorship
  217. Development of this package is sponsored by Kirschbaum Development Group, a developer driven company focused on problem solving, team building, and community. Learn more [about us](https://kirschbaumdevelopment.com?utm_source=github) or [join us](https://careers.kirschbaumdevelopment.com?utm_source=github)!
  218. ## License
  219. The MIT License (MIT). Please see [License File](LICENSE) for more information.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.