|  | 
|  | 1 | +# Laravel Loop HTTP Streaming | 
|  | 2 | + | 
|  | 3 | +Laravel Loop provides a streamable HTTP transport for the Model Context Protocol (MCP) that supports client-initiated requests (POST). The MCP HTTP transport is able to process JSON and SSE streaming responses on a single endpoint. | 
|  | 4 | + | 
|  | 5 | +## Configuration | 
|  | 6 | + | 
|  | 7 | +To enable and configure the HTTP MCP endpoint, update your `.env` file and/or `config/loop.php`: | 
|  | 8 | + | 
|  | 9 | +```php | 
|  | 10 | +# Enable the HTTP MCP endpoint | 
|  | 11 | +LOOP_STREAMABLE_HTTP_ENABLED=true | 
|  | 12 | + | 
|  | 13 | +# Set the endpoint path (default: /mcp) | 
|  | 14 | +LOOP_STREAMABLE_HTTP_PATH=/mcp | 
|  | 15 | +``` | 
|  | 16 | + | 
|  | 17 | +### Security Considerations | 
|  | 18 | + | 
|  | 19 | +The MCP HTTP endpoint should be protected with proper authentication. By default, it uses Laravel Sanctum, but you can configure the middleware stack in `config/loop.php`: | 
|  | 20 | + | 
|  | 21 | +```php | 
|  | 22 | +'middleware' => ['auth:sanctum'], | 
|  | 23 | +``` | 
|  | 24 | + | 
|  | 25 | +## Client-Initiated Messages (POST) | 
|  | 26 | + | 
|  | 27 | +Clients can send JSON-RPC 2.0 messages to the MCP server by making HTTP POST requests to the configured endpoint. | 
|  | 28 | + | 
|  | 29 | +### Single Request | 
|  | 30 | + | 
|  | 31 | +```bash | 
|  | 32 | +curl -X POST http://your-app.test/mcp \ | 
|  | 33 | +  -H "Content-Type: application/json" \ | 
|  | 34 | +  -H "Accept: application/json" \ | 
|  | 35 | +  -H "Authorization: Bearer YOUR_TOKEN" \ | 
|  | 36 | +  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"clientInfo":{"name":"Test Client"},"capabilities":{},"protocolVersion":"2024-11-05"}}' | 
|  | 37 | +``` | 
|  | 38 | + | 
|  | 39 | +### Batch Requests | 
|  | 40 | + | 
|  | 41 | +```bash | 
|  | 42 | +curl -X POST http://your-app.test/mcp \ | 
|  | 43 | +  -H "Content-Type: application/json" \ | 
|  | 44 | +  -H "Accept: application/json" \ | 
|  | 45 | +  -H "Authorization: Bearer YOUR_TOKEN" \ | 
|  | 46 | +  -d '[{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"clientInfo":{"name":"Test Client"},"capabilities":{},"protocolVersion":"2024-11-05"}},{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}]' | 
|  | 47 | +``` | 
|  | 48 | + | 
|  | 49 | +### SSE Streaming Responses | 
|  | 50 | + | 
|  | 51 | +Clients can request SSE responses for batch processing by setting the `Accept` header to include `text/event-stream`: | 
|  | 52 | + | 
|  | 53 | +```bash | 
|  | 54 | +curl -X POST http://your-app.test/mcp \ | 
|  | 55 | +  -H "Content-Type: application/json" \ | 
|  | 56 | +  -H "Accept: text/event-stream" \ | 
|  | 57 | +  -H "Authorization: Bearer YOUR_TOKEN" \ | 
|  | 58 | +  -d '[{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"clientInfo":{"name":"Test Client"},"capabilities":{},"protocolVersion":"2024-11-05"}},{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}]' | 
|  | 59 | +``` | 
|  | 60 | + | 
|  | 61 | +The server will respond with an SSE stream containing each response as a separate event. | 
0 commit comments