# คู่มือการทดสอบ MCP Server
คู่มือนี้จะอธิบายวิธีการทดสอบ MCP Server กับ Claude Desktop, ChatGPT และเครื่องมืออื่นๆ
## ขั้นตอนการเตรียม
1. ติดตั้ง dependencies:
```bash
npm install
```
2. Build โปรเจค:
```bash
npm run build
```
3. ทดสอบว่า server ทำงานได้:
```bash
npm start
```
(คุณควรเห็น "CMMS MCP Server running on stdio" ใน stderr)
## การทดสอบกับ Claude Desktop (แนะนำ)
Claude Desktop เป็นวิธีที่ง่ายที่สุดในการใช้ MCP Server
### 1. หาไฟล์ Config ของ Claude Desktop
**macOS:**
```bash
~/Library/Application Support/Claude/claude_desktop_config.json
```
**Windows:**
```
%APPDATA%\Claude\claude_desktop_config.json
```
**Linux:**
```bash
~/.config/Claude/claude_desktop_config.json
```
### 2. เพิ่มการตั้งค่า Server
เปิดไฟล์ config และเพิ่ม:
```json
{
"mcpServers": {
"cmms-mcp-server": {
"command": "node",
"args": ["/Users/anuwatthisuka/Documents/Developer/CodeSandbox/cmms-mcp-server/dist/index.js"],
"env": {}
}
}
}
```
**สำคัญ:** แทนที่ path ด้วย path จริงของโปรเจคของคุณ (ใช้ absolute path)
### 3. Restart Claude Desktop
ปิดและเปิด Claude Desktop ใหม่ทั้งหมด
### 4. ตรวจสอบการเชื่อมต่อ
ใน Claude Desktop คุณควรเห็น:
- Tools ต่างๆ ในเมนู tools
- Resources ต่างๆ ในเมนู resources
- คุณสามารถถาม Claude ให้ใช้ tools เช่น "Get all production orders" หรือ "Show me maintenance tasks"
## ตัวอย่างคำถามสำหรับทดสอบ
เมื่อเชื่อมต่อกับ Claude Desktop แล้ว ลองคำถามเหล่านี้:
### MES Queries:
- "Get all production orders"
- "Show me equipment that's currently running"
- "What work orders are in progress?"
- "Get production order po-001"
### CMMS Queries:
- "List all maintenance tasks"
- "Show me overdue maintenance tasks"
- "Get maintenance tasks with critical priority"
- "Create a new preventive maintenance task for asset-001 scheduled for tomorrow"
- "Get maintenance history for asset-002"
### IoT Queries:
- "Show me all active sensors"
- "Get temperature sensor readings"
- "What alerts are currently unacknowledged?"
- "Show me critical alerts"
- "Acknowledge alert alert-001"
## การทดสอบด้วย Command Line
### วิธีที่ 1: ใช้ Test Script
```bash
npm test
```
### วิธีที่ 2: ทดสอบด้วย JSON-RPC โดยตรง
```bash
# List tools
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | node dist/index.js
# Call a tool
echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_production_orders","arguments":{"status":"in-progress"}}}' | node dist/index.js
```
## การทดสอบกับ MCP Inspector
MCP Inspector เป็นเครื่องมือสำหรับทดสอบ MCP Server
### 1. ติดตั้ง MCP Inspector
```bash
npm install -g @modelcontextprotocol/inspector
```
### 2. รัน Inspector
```bash
mcp-inspector node dist/index.js
```
จะเปิด web interface ที่คุณสามารถ:
- ดู tools ทั้งหมด
- ทดสอบการเรียกใช้ tools
- ดู resources
- ดู server capabilities
## การแก้ปัญหา (Troubleshooting)
### Server ไม่ทำงาน
- ตรวจสอบว่า `dist/index.js` มีอยู่ (รัน `npm run build`)
- ตรวจสอบ Node.js version (ควรเป็น 18+)
- ดู errors ใน console
### Tools ไม่แสดง
- ตรวจสอบว่า path ใน config file ถูกต้อง (ใช้ absolute path)
- Restart Claude Desktop ใหม่ทั้งหมด
- ดู logs ของ Claude Desktop สำหรับ errors
### ปัญหาการเชื่อมต่อ
- ตรวจสอบว่า server path ใน config เป็น absolute path
- ตรวจสอบ file permissions
- ตรวจสอบว่า dependencies ทั้งหมดติดตั้งแล้ว
## Debug Mode
รันในโหมด development เพื่อดู logs แบบละเอียด:
```bash
npm run dev
```
จะแสดง JSON-RPC messages ทั้งหมดที่ถูกส่ง
## หมายเหตุ
- ChatGPT ยังไม่รองรับ MCP โดยตรง แต่คุณสามารถใช้กับ Claude Desktop, Cline, หรือ Continue ได้
- สำหรับ ChatGPT คุณอาจต้องสร้าง custom integration หรือใช้ API wrapper