# 📮 Postman Testing Guide for Trackex MCP Server

## 🚀 Setup Instructions

### 1. **Import the Collection**
1. Open Postman
2. Click "Import" 
3. Upload `Trackex-MCP-Postman-Collection.json`
4. Set environment variables:
   - `mcp_base_url`: `http://localhost:3002`
   - `api_key`: Your actual 64-character API key

### 2. **Start Both Servers**
```bash
npm run dev:both
```
Make sure both servers are running:
- Main API: `http://localhost:3000`
- MCP Server: `http://localhost:3002`

## ✅ **What You CAN Test with Postman**

### **1. Health Check**
```
GET http://localhost:3002/health
```
**Expected Response:**
```json
{
  "status": "healthy",
  "message": "MCP HTTP Test Wrapper is running",
  "config": {
    "apiBaseUrl": "http://localhost:3000/api/v1",
    "debug": false,
    "requireApiKey": true
  }
}
```

### **2. Get Today's Tasks**
```
GET http://localhost:3002/mcp/get_today_tasks
Headers: X-API-Key: your-api-key
```
**Expected Response:**
```json
{
  "success": true,
  "message": "Tasks retrieved successfully",
  "tasks": [...],
  "total": 5
}
```

### **3. Create Task**
```
POST http://localhost:3002/mcp/create_task
Content-Type: application/json

{
  "api_key": "your-api-key",
  "title": "Test Task from Postman",
  "description": "Testing MCP endpoint",
  "task_type": "adhoc",
  "priority": "medium"
}
```

### **4. Get Pending Tasks**
```
GET http://localhost:3002/mcp/get_pending_tasks
Headers: X-API-Key: your-api-key
```

### **5. Get Adhoc Tasks**
```
GET http://localhost:3002/mcp/get_adhoc_tasks
Headers: X-API-Key: your-api-key
```

## ❌ **What You CANNOT Test with Postman**

### **Natural Language Queries:**
```
❌ "Show me my tasks for today"
❌ "Create a task to fix the login bug"
❌ "How many tasks are pending?"
❌ "Mark task 123 as completed"
```

**Why?** Because natural language processing happens at the AI level (Claude, ChatGPT), not at the HTTP API level.

## 🧪 **Step-by-Step Testing Process**

### **Step 1: Test Health**
1. Send GET to `/health`
2. Verify MCP server is running
3. Check configuration

### **Step 2: Test Authentication**
1. Try request without API key → Should get 400 error
2. Try with invalid API key → Should get authentication error
3. Try with valid API key → Should succeed

### **Step 3: Test Data Retrieval**
1. Test `/mcp/get_today_tasks`
2. Test with different `limit` parameters
3. Verify data structure matches expected format

### **Step 4: Test Task Creation**
1. Create task with minimal data
2. Create task with full data
3. Test validation errors (missing title, etc.)

### **Step 5: Test Error Handling**
1. Send malformed JSON
2. Send invalid parameters
3. Test API key validation

## 🔧 **Common Issues & Solutions**

### **Issue: "Unable to connect"**
**Solution:** 
- Ensure MCP server is running: `npm run dev:both`
- Check port 3002 is not blocked

### **Issue: "Invalid API key format"**
**Solution:**
- API key must be exactly 64 characters
- Use a valid API key from your Trackex system

### **Issue: "API key is required"**
**Solution:**
- Include `X-API-Key` header OR
- Include `Authorization: Bearer` header OR
- Include `api_key` in request body (for POST)

## 📊 **Testing Natural Language (Alternative Methods)**

Since Postman can't test natural language, here are alternatives:

### **Method 1: Claude AI Integration**
1. Set up Claude with your MCP server
2. Chat naturally: "Show me today's tasks"
3. Claude converts to MCP calls automatically

### **Method 2: Build a Test Chat Interface**
```html
<!DOCTYPE html>
<html>
<head>
    <title>Trackex AI Chat Test</title>
</head>
<body>
    <div id="chat"></div>
    <input type="text" id="userInput" placeholder="Ask about your tasks...">
    <button onclick="sendMessage()">Send</button>

    <script>
        async function sendMessage() {
            const input = document.getElementById('userInput').value;
            
            // This would need to connect to an AI service
            // that can process natural language and convert to MCP calls
            
            // For now, you can manually map common phrases:
            if (input.includes('today') && input.includes('task')) {
                // Call MCP endpoint
                const response = await fetch('/mcp/get_today_tasks', {
                    headers: {'X-API-Key': 'your-key'}
                });
                const data = await response.json();
                displayResponse(data);
            }
        }
    </script>
</body>
</html>
```

### **Method 3: Use Claude Desktop App**
1. Install Claude Desktop
2. Configure it to use your MCP server
3. Chat naturally and see real MCP calls

## 📋 **Testing Checklist**

- [ ] ✅ Health check passes
- [ ] ✅ Authentication works with valid API key
- [ ] ✅ Authentication fails with invalid API key
- [ ] ✅ Get today's tasks returns data
- [ ] ✅ Create task works with valid data
- [ ] ✅ Create task fails with invalid data
- [ ] ✅ Pending tasks endpoint works
- [ ] ✅ Adhoc tasks endpoint works
- [ ] ✅ Error responses are properly formatted
- [ ] ❌ Natural language (requires AI integration)

## 🎯 **Summary**

**Postman is perfect for:**
- ✅ Testing HTTP endpoints
- ✅ Validating API responses
- ✅ Testing authentication
- ✅ Debugging API issues

**Postman cannot test:**
- ❌ Natural language processing
- ❌ AI conversation flows
- ❌ Dynamic language interpretation

**For natural language testing, you need an actual AI interface that can:**
1. Understand human language
2. Convert it to structured API calls
3. Call your MCP endpoints
4. Format responses back to human language 