Overview
Chatbot Platform is built on Laravel MCP, making it easy to create custom MCP servers that expose tools to AI models. This guide walks you through building your own MCP server from scratch.Prerequisites
- Laravel 12+ application
laravel/mcppackage installed- Basic understanding of Laravel controllers and services
- Familiarity with JSON schemas
Installation
Laravel MCP is already included in Chatbot Platform. For standalone Laravel applications:Project Structure
Creating a Server
Step 1: Generate the Server Class
app/Mcp/Servers/WeatherServer/WeatherServer.php:
Step 2: Create Tools
Generate a tool:app/Mcp/Servers/WeatherServer/Tools/GetWeather.php:
Step 3: Register Tools in Server
UpdateWeatherServer.php to include your tools:
Step 4: Register the Server
Add your server toroutes/ai.php:
routes/ai.php is loaded in bootstrap/app.php:
Schema Definition
UseJsonSchema to define tool parameters:
String Fields
Enum Fields
Integer Fields
Number Fields
Boolean Fields
Array Fields
Chainable Methods
Not Available: Laravel’s JsonSchema does not support
->minimum(), ->maximum(), or enum classes. Document numeric limits in the description instead.Authentication Patterns
Public (No Auth Required)
Custom Header
Bearer Token
Conversation-Scoped Auth
Best Practices
Tool Design
Do:- Keep tools focused on a single responsibility
- Provide clear, detailed descriptions for AI context
- Return structured output (markdown tables, lists)
- Validate input parameters
- Handle errors gracefully with clear messages
- Create tools that do too many things
- Return unstructured text blobs
- Throw exceptions without handling them
- Expose sensitive data without authorization
Return Format
Return markdown-formatted strings for best LLM consumption:Error Handling
Service Classes
Extract complex logic into service classes:Testing MCP Servers
Unit Tests
Integration Testing with MCP Inspector
Use the MCP Inspector to test your server interactively:http://localhost:8000/mcp/weather (Streamable HTTP transport)
Example: Complete CRUD Server
Here’s a simple CRUD server for managing notes:Official Documentation
For complete Laravel MCP documentation:Laravel MCP Documentation
Official Laravel documentation for the MCP package
Current Platform Version: 1.79.0