MCP AI Chat Server

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.

Category
访问服务器

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 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

  1. Clone and install dependencies:

    git clone <repository-url>
    cd mcp-server
    composer install
    npm install
    
  2. Environment setup:

    cp .env.example .env
    php artisan key:generate
    
  3. 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
    
  4. Database setup:

    php artisan migrate
    php artisan db:seed  # Optional: seed sample data
    
  5. Build assets:

    npm run build
    
  6. Start the server:

    php artisan serve
    
  7. 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

  1. User sends message via API or web interface
  2. AgentService analyzes intent using AI or rule-based logic
  3. Appropriate tool is selected and executed
  4. Results are formatted into human-readable response
  5. 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. 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_logs table for interaction details
  • Ensure API keys are properly configured

📚 Additional Resources

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选