MCP AI Chat Server
A Laravel-based AI-powered chat interface for business management operations, enabling users to execute tasks like creating customers and updating task statuses through natural language conversations.
README
MCP AI Chat Server
A Laravel-based AI-powered chat interface for business management operations using natural language processing and tool calling.
๐ฏ Overview
The MCP AI Chat Server enables users to interact with business data through natural language conversations. It leverages OpenAI's function calling capabilities to:
- Analyze user intent from natural language input
- Extract parameters automatically
- Execute appropriate business operations via MCP tools
- Return human-friendly responses
โจ Features
- Natural Language Processing: Understands Indonesian and English business queries
- AI-Powered Tool Calling: Uses OpenAI GPT models for intelligent function selection
- Rule-Based Fallback: Graceful degradation when AI services are unavailable
- Real-time Chat Interface: Web-based chat UI with session management
- Comprehensive Logging: Tracks all interactions and tool executions
- RESTful API: Programmatic access to chat functionality
- Multi-Provider Support: OpenAI and OpenRouter integration
๐ ๏ธ Available Tools
| Tool | Description | Parameters |
|---|---|---|
create_customer |
Create new customer records | name, email, phone |
get_user |
Retrieve user by email | |
search_tasks |
Find tasks by status/user | status, assigned_to |
update_task_status |
Change task status | task_id, status |
get_overdue_customers |
Find inactive customers | days |
๐ Quick Start
Prerequisites
- PHP 8.1+
- Composer
- Node.js & npm (for frontend assets)
- Database (MySQL/PostgreSQL/SQLite)
Installation
-
Clone and install dependencies:
git clone <repository-url> cd mcp-server composer install npm install -
Environment setup:
cp .env.example .env php artisan key:generate -
Configure environment variables:
# Database DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=mcp_chat DB_USERNAME=your_username DB_PASSWORD=your_password # AI Providers AI_PROVIDER=openai # or 'openrouter' OPENAI_API_KEY=your-openai-api-key OPENROUTER_API_KEY=your-openrouter-api-key # MCP Authentication MCP_VALID_KEYS=your-secret-key-here -
Database setup:
php artisan migrate php artisan db:seed # Optional: seed sample data -
Build assets:
npm run build -
Start the server:
php artisan serve -
Access the application:
- Chat Interface: http://localhost:8000/chat
- API Documentation: http://localhost:8000/api/documentation
๐ฌ Usage Examples
Web Interface
Visit /chat to use the interactive chat interface with example message buttons.
API Usage
Send Chat Message
curl -X POST "http://localhost:8000/api/mcp/chat" \
-H "Content-Type: application/json" \
-H "X-MCP-Key: your-mcp-key" \
-d '{
"message": "Buatkan customer baru dengan nama John Doe, email john@example.com",
"session_id": "optional-session-id"
}'
Response
{
"reply": "Customer 'John Doe' berhasil dibuat dengan ID 1.",
"executed_tool": "create_customer",
"arguments": {
"name": "John Doe",
"email": "john@example.com"
},
"result": {
"id": 1,
"name": "John Doe",
"email": "john@example.com"
},
"status": "success"
}
Example Conversations
Creating a customer:
User: Buatkan user baru dengan nama Andi, email andi@gmail.com
AI: Customer 'Andi' berhasil dibuat dengan ID 5.
Updating task status:
User: Update status task nomor 1 menjadi completed
AI: Status task ID 1 berhasil diubah menjadi 'completed'.
Finding overdue customers:
User: Tampilkan customer yang belum dihubungi lebih dari 30 hari
AI: Ditemukan 3 customer yang belum dihubungi lebih dari 30 hari.
๐ก API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/mcp/chat |
Send chat message |
| GET | /api/mcp/chat/history |
Get conversation history |
| DELETE | /api/mcp/chat/history |
Clear conversation history |
Authentication
All API endpoints require the X-MCP-Key header with a valid key from MCP_VALID_KEYS.
๐ง Configuration
AI Providers
Choose between OpenAI and OpenRouter by setting AI_PROVIDER:
- OpenAI: More reliable, requires API key
- OpenRouter: Alternative provider, supports multiple models
Environment Variables
| Variable | Description | Default |
|---|---|---|
AI_PROVIDER |
AI service provider | openai |
OPENAI_API_KEY |
OpenAI API key | - |
OPENROUTER_API_KEY |
OpenRouter API key | - |
MCP_VALID_KEYS |
Comma-separated API keys | - |
DB_CONNECTION |
Database connection | mysql |
๐๏ธ Architecture
Core Components
- AgentService: Main AI processing logic
- ToolRegistry: Manages available MCP tools
- MCP Tools: Individual business operation handlers
- ChatController: Web interface and API endpoints
- Logging: Comprehensive interaction tracking
Data Flow
- User sends message via API or web interface
- AgentService analyzes intent using AI or rule-based logic
- Appropriate tool is selected and executed
- Results are formatted into human-readable response
- Interaction is logged for analytics
๐ Security
- API key authentication for all endpoints
- Input validation and sanitization
- Rate limiting on chat endpoints
- Comprehensive error handling
- No sensitive data exposure in responses
๐ Monitoring
All interactions are logged in the mcp_command_logs table including:
- User messages and AI responses
- Executed tools and parameters
- Success/failure status
- Session tracking
- IP addresses and metadata
๐งช Testing
Run the test suite:
php artisan test
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Support
For issues and questions:
- Check the logs in
storage/logs/laravel.log - Review
mcp_command_logstable for interaction details - Ensure API keys are properly configured
๐ Additional Resources
- Laravel Documentation
- OpenAI Function Calling
- OpenRouter API</content> <filePath>README.md
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.