-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathcleanup-test-tags.js
More file actions
74 lines (60 loc) · 1.89 KB
/
cleanup-test-tags.js
File metadata and controls
74 lines (60 loc) · 1.89 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
#!/usr/bin/env node
/**
* Cleanup script for test tags
* Removes all tags with prefix "TagTest_"
*/
const axios = require('axios');
const mcpServerUrl = 'http://localhost:3456/mcp';
let requestId = 1;
async function sendMcpRequest(method, params = {}) {
const response = await axios.post(mcpServerUrl, {
jsonrpc: '2.0',
id: requestId++,
method,
params
});
return response.data.result;
}
async function callTool(name, args = {}) {
const result = await sendMcpRequest('tools/call', { name, arguments: args });
if (result.isError) {
const errorMessage = result.content && result.content[0] && result.content[0].text
? result.content[0].text
: 'Unknown error';
throw new Error(errorMessage);
}
return result;
}
async function cleanup() {
try {
console.error('[INFO] Fetching all tags...');
// Get all tags
const result = await callTool('get_tags', { limit: 100 });
const data = JSON.parse(result.content[0].text);
const tags = data.data || [];
console.error(`[INFO] Found ${tags.length} total tags`);
// Filter test tags
const testTags = tags.filter(tag => tag.name.startsWith('TagTest_'));
console.error(`[INFO] Found ${testTags.length} test tags to delete`);
if (testTags.length === 0) {
console.error('[INFO] No test tags to clean up');
return;
}
// Delete each test tag
let deleted = 0;
for (const tag of testTags) {
try {
await callTool('delete_tag', { id: tag.id });
deleted++;
console.error(`[SUCCESS] Deleted tag: ${tag.name} (${tag.id})`);
} catch (error) {
console.error(`[ERROR] Failed to delete tag ${tag.name}: ${error.message}`);
}
}
console.error(`[SUCCESS] Cleaned up ${deleted}/${testTags.length} test tags`);
} catch (error) {
console.error(`[ERROR] Cleanup failed: ${error.message}`);
process.exit(1);
}
}
cleanup();