-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-mcp-server.js
More file actions
executable file
·247 lines (211 loc) · 7.79 KB
/
test-mcp-server.js
File metadata and controls
executable file
·247 lines (211 loc) · 7.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/env node
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
console.log('🧪 Testing SimpleCheckList MCP Server...\n');
// Test the MCP server by spawning it and sending test messages
const mcpServerPath = join(__dirname, 'mcp-server', 'index.js');
const mcp = spawn('node', [mcpServerPath], {
stdio: ['pipe', 'pipe', 'pipe'],
env: {
...process.env,
API_BASE_URL: 'http://localhost:8355/api'
}
});
let testsPassed = 0;
let totalTests = 0;
// Helper function to send JSON-RPC message
function sendMessage(method, params = {}) {
return new Promise((resolve, reject) => {
const id = ++totalTests;
const message = {
jsonrpc: '2.0',
id,
method,
params
};
console.log(`📤 Test ${id}: ${method}`);
let responseData = '';
let timeout;
const onData = (data) => {
responseData += data.toString();
// Try to parse JSON response
try {
const lines = responseData.split('\n').filter(line => line.trim());
for (const line of lines) {
if (line.trim()) {
const response = JSON.parse(line);
if (response.id === id) {
clearTimeout(timeout);
mcp.stdout.off('data', onData);
if (response.error) {
console.log(`❌ Test ${id} failed:`, response.error.message);
reject(response.error);
} else {
console.log(`✅ Test ${id} passed`);
testsPassed++;
resolve(response.result);
}
return;
}
}
}
} catch (e) {
// Continue waiting for complete JSON
}
};
mcp.stdout.on('data', onData);
// Set timeout
timeout = setTimeout(() => {
mcp.stdout.off('data', onData);
console.log(`⏱️ Test ${id} timed out`);
reject(new Error('Timeout'));
}, 10000);
// Send the message
mcp.stdin.write(JSON.stringify(message) + '\n');
});
}
// Run tests
async function runTests() {
try {
// Wait for server to initialize
await new Promise(resolve => setTimeout(resolve, 2000));
console.log('🔍 Testing MCP server tools...\n');
// Test 1: List available tools
console.log('1. Testing list_tools...');
const tools = await sendMessage('tools/list');
console.log(` Found ${tools.tools?.length || 0} tools\n`);
// Test 2: Create a project
console.log('2. Testing create_project...');
const createProjectResult = await sendMessage('tools/call', {
name: 'create_project',
arguments: {
name: 'MCP Test Project',
description: 'A test project created via MCP',
color: '#FF5722'
}
});
console.log(' Project created successfully\n');
// Test 3: List projects
console.log('3. Testing list_projects...');
const listProjectsResult = await sendMessage('tools/call', {
name: 'list_projects',
arguments: {}
});
console.log(' Projects listed successfully\n');
// Test 4: Create a group
console.log('4. Testing create_group...');
// Extract project ID from create result (assuming it's in the content)
const projectContent = createProjectResult.content?.[0]?.text || '';
const projectMatch = projectContent.match(/"id":\s*"([^"]+)"/);
const projectId = projectMatch ? projectMatch[1] : null;
if (projectId) {
const createGroupResult = await sendMessage('tools/call', {
name: 'create_group',
arguments: {
project_id: projectId,
name: 'MCP Test Group',
description: 'A test group created via MCP'
}
});
console.log(' Group created successfully\n');
// Test 5: Create a task list
console.log('5. Testing create_task_list...');
const groupContent = createGroupResult.content?.[0]?.text || '';
const groupMatch = groupContent.match(/"id":\s*"([^"]+)"/);
const groupId = groupMatch ? groupMatch[1] : null;
if (groupId) {
const createTaskListResult = await sendMessage('tools/call', {
name: 'create_task_list',
arguments: {
group_id: groupId,
name: 'MCP Test Task List',
description: 'A test task list created via MCP'
}
});
console.log(' Task list created successfully\n');
// Test 6: Create a task
console.log('6. Testing create_task...');
const taskListContent = createTaskListResult.content?.[0]?.text || '';
const taskListMatch = taskListContent.match(/"id":\s*"([^"]+)"/);
const taskListId = taskListMatch ? taskListMatch[1] : null;
if (taskListId) {
const createTaskResult = await sendMessage('tools/call', {
name: 'create_task',
arguments: {
task_list_id: taskListId,
title: 'MCP Test Task',
description: 'A test task created via MCP',
priority: 'high'
}
});
console.log(' Task created successfully\n');
// Test 7: Toggle task completion
console.log('7. Testing toggle_task_completion...');
const taskContent = createTaskResult.content?.[0]?.text || '';
const taskMatch = taskContent.match(/"id":\s*"([^"]+)"/);
const taskId = taskMatch ? taskMatch[1] : null;
if (taskId) {
await sendMessage('tools/call', {
name: 'toggle_task_completion',
arguments: {
task_id: taskId
}
});
console.log(' Task completion toggled successfully\n');
}
}
}
// Test 8: Get project stats
console.log('8. Testing get_project_stats...');
await sendMessage('tools/call', {
name: 'get_project_stats',
arguments: {
project_id: projectId
}
});
console.log(' Project stats retrieved successfully\n');
}
// Test 9: Get all tasks
console.log('9. Testing get_all_tasks...');
await sendMessage('tools/call', {
name: 'get_all_tasks',
arguments: {}
});
console.log(' All tasks retrieved successfully\n');
console.log(`🎉 MCP Server Test Results:`);
console.log(` ✅ Passed: ${testsPassed}/${totalTests} tests`);
console.log(` 📊 Success Rate: ${Math.round((testsPassed/totalTests) * 100)}%\n`);
if (testsPassed === totalTests) {
console.log('🚀 All MCP server tests passed! The server is working correctly.');
console.log('\nThe MCP server provides the following capabilities:');
console.log('• Project management (create, read, update, delete)');
console.log('• Group and task list organization');
console.log('• Task management with priorities and completion tracking');
console.log('• Statistics and reporting');
console.log('• Full CRUD operations for all entities');
console.log('\nAI applications can now connect to this MCP server to manage tasks programmatically!');
} else {
console.log('⚠️ Some tests failed. Check the MCP server configuration.');
}
} catch (error) {
console.error('❌ Test suite failed:', error.message);
} finally {
// Clean up
mcp.kill();
process.exit(testsPassed === totalTests ? 0 : 1);
}
}
// Handle MCP server errors
mcp.stderr.on('data', (data) => {
console.error('MCP Server Error:', data.toString());
});
mcp.on('close', (code) => {
if (code !== 0 && code !== null) {
console.error(`MCP server exited with code ${code}`);
}
});
// Start tests
runTests();