poc-mcp-server

bosznrt/poc-mcp-server

3.2

If you are the rightful owner of poc-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The MCP Server is a robust and scalable server built using TypeScript and Express.js, designed to handle JSON-RPC 2.0 protocol requests efficiently.

Tools
7
Resources
0
Prompts
0

MCP Server

Model Context Protocol (MCP) Server ที่สร้างด้วย TypeScript และ Express.js

🚀 คุณสมบัติ

  • JSON-RPC 2.0 Protocol: รองรับ MCP protocol มาตรฐาน
  • TypeScript: Type-safe development
  • Express.js: Fast, unopinionated web framework
  • ClickHouse Integration: รองรับ ClickHouse database สำหรับ real-time analytics
  • Security: Helmet, CORS, input validation
  • Logging: Winston logger with file and console output
  • Error Handling: Comprehensive error handling and graceful shutdown
  • Scalable Architecture: Modular design for easy maintenance and scaling

📋 ความต้องการของระบบ

  • Node.js 22+
  • pnpm (แนะนำ) หรือ npm

🛠️ การติดตั้ง

  1. Clone โปรเจค

    git clone <repository-url>
    cd mcp-server
    
  2. ติดตั้ง dependencies

    pnpm install
    
  3. ตั้งค่า environment variables

    cp env.example .env
    # แก้ไขไฟล์ .env ตามความต้องการ
    
  4. รันในโหมด development

    pnpm run dev
    

🏃‍♂️ การใช้งาน

Development Mode

pnpm run dev

Production Mode

pnpm run build
pnpm start

Testing

pnpm test

Linting

pnpm run lint
pnpm run format

📡 API Endpoints

Health Check

GET /api/v1/health

Server Info

GET /api/v1/info

MCP JSON-RPC

POST /api/v1/rpc
Content-Type: application/json

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/list"
}

Batch Requests

POST /api/v1/rpc/batch
Content-Type: application/json

[
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/list"
  },
  {
    "jsonrpc": "2.0",
    "id": 2,
    "method": "tools/call",
    "params": {
      "name": "calculate",
      "arguments": {
        "expression": "2 + 2 * 3"
      }
    }
  }
]

🛠️ Available Tools

calculate

คำนวณผลลัพธ์ทางคณิตศาสตร์

Parameters:

  • expression (string): นิพจน์ทางคณิตศาสตร์

Example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "calculate",
    "arguments": {
      "expression": "2 + 2 * 3"
    }
  }
}

convert_unit

แปลงหน่วยต่างๆ

Parameters:

  • value (number): ค่าที่ต้องการแปลง
  • from (string): หน่วยต้นทาง
  • to (string): หน่วยปลายทาง

Example:

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/call",
  "params": {
    "name": "convert_unit",
    "arguments": {
      "value": 25,
      "from": "celsius",
      "to": "fahrenheit"
    }
  }
}

ClickHouse Tools

clickhouse_test_connection

ทดสอบการเชื่อมต่อ ClickHouse database

clickhouse_execute_query

รัน SQL query บน ClickHouse database

Parameters:

  • query (string): SQL query ที่ต้องการรัน
  • params (object): Parameters สำหรับ query (optional)
clickhouse_get_tables

ดึงรายการ tables ทั้งหมดใน database

clickhouse_insert_data

เพิ่มข้อมูลลงใน table

Parameters:

  • tableName (string): ชื่อ table
  • data (array): ข้อมูลที่ต้องการเพิ่ม
clickhouse_create_table

สร้าง table ใหม่

Parameters:

  • tableName (string): ชื่อ table
  • schema (string): Schema ของ table (column definitions)

📖 ดูรายละเอียดเพิ่มเติมได้ที่

📚 Available Resources

API Documentation

  • URI: file:///docs/api.md
  • Description: เอกสาร API สำหรับ MCP Server

User Guide

  • URI: file:///docs/guide.md
  • Description: คู่มือการใช้งาน MCP Server

🏗️ โครงสร้างโปรเจค

src/
├── types/
│   └── mcp.ts              # TypeScript type definitions
├── services/
│   ├── logger.ts           # Winston logger service
│   └── mcpHandler.ts       # MCP request handler
├── middleware/
│   └── validation.ts       # Request validation middleware
├── routes/
│   └── mcp.ts              # API routes
├── app.ts                  # Express app configuration
└── index.ts                # Application entry point

🔧 การเพิ่ม Tools ใหม่

  1. สร้าง tool handler ใน src/services/mcpHandler.ts

    this.registerTool({
      name: 'your_tool_name',
      description: 'คำอธิบาย tool',
      inputSchema: {
        type: 'object',
        properties: {
          // define your parameters
        },
        required: ['required_param']
      },
      handler: async (params) => {
        // implement your tool logic
        return { result: 'your result' };
      }
    });
    
  2. เพิ่ม validation ใน src/middleware/validation.ts (ถ้าจำเป็น)

🔧 การเพิ่ม Resources ใหม่

this.registerResource({
  uri: 'file:///your/resource.md',
  name: 'Resource Name',
  description: 'Resource description',
  mimeType: 'text/markdown',
  content: 'Your content here'
});

🚀 การ Deploy

Docker (แนะนำ)

FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY dist ./dist
EXPOSE 3000
CMD ["npm", "start"]

PM2

pnpm install -g pm2
pm2 start dist/index.js --name "mcp-server"

📊 Monitoring

  • Logs: ไฟล์ logs จะถูกเก็บในโฟลเดอร์ logs/
  • Health Check: ใช้ endpoint /api/v1/health สำหรับ monitoring
  • Metrics: สามารถเพิ่ม Prometheus metrics ได้ในอนาคต

🔒 Security

  • Helmet: Security headers
  • CORS: Cross-origin resource sharing
  • Input Validation: Joi schema validation
  • Rate Limiting: สามารถเพิ่มได้ในอนาคต
  • Authentication: สามารถเพิ่ม JWT authentication ได้

🤝 การมีส่วนร่วม

  1. Fork โปรเจค
  2. สร้าง feature branch (git checkout -b feature/amazing-feature)
  3. Commit การเปลี่ยนแปลง (git commit -m 'Add amazing feature')
  4. Push ไปยัง branch (git push origin feature/amazing-feature)
  5. เปิด Pull Request

📄 License

MIT License - ดูไฟล์ สำหรับรายละเอียด

🆘 การแก้ไขปัญหา

Port ถูกใช้งานแล้ว

# เปลี่ยน port ใน .env file
PORT=3001

Permission denied

# สร้างโฟลเดอร์ logs
mkdir logs

TypeScript compilation errors

# ลบไฟล์ dist และ build ใหม่
rm -rf dist
pnpm run build

📞 การติดต่อ

หากมีคำถามหรือปัญหา กรุณาเปิด issue ใน GitHub repository