-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest-list-plugins.js
More file actions
74 lines (63 loc) · 2.22 KB
/
test-list-plugins.js
File metadata and controls
74 lines (63 loc) · 2.22 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
const { Server } = require('@modelcontextprotocol/sdk/server');
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio');
const { SiteManager } = require('./wordpress-mcp/wordpress/client');
// Set up logging
const log = (message) => console.error(`[Test] ${message}`);
async function main() {
log('Starting test for list_plugins tool');
// Get site ID from command line arguments or use a default
const siteId = process.argv[2] || '7e4add2f-3e1a-4faa-9a60-90de2ee11cbd';
log(`Using site ID: ${siteId}`);
try {
// Initialize the site manager
const siteManager = new SiteManager();
await siteManager.initialize();
log('Site manager initialized');
// Get the site
const site = await siteManager.getSite(siteId);
if (!site) {
log(`Site with ID ${siteId} not found`);
process.exit(1);
}
log(`Found site: ${site.name} (${site.url})`);
// Test list_plugins with detailed logging
log('Testing list_plugins tool...');
try {
log('Creating WordPress client...');
const client = await site.getClient();
log('WordPress client created');
log('Fetching plugins...');
// Add detailed logging to see what's happening
const response = await client.plugins().list();
log('Raw API response:');
console.log(JSON.stringify(response, null, 2));
// Process the response
if (response && Array.isArray(response)) {
log(`Found ${response.length} plugins:`);
response.forEach((plugin, index) => {
console.log(`${index + 1}. ${plugin.name} (${plugin.status})`);
});
} else {
log('Response is not an array as expected:');
console.log(typeof response, response);
}
} catch (error) {
log('Error fetching plugins:');
console.error(error);
// Try to get more detailed error information
if (error.response) {
log('API response error:');
console.error(JSON.stringify(error.response.data, null, 2));
}
}
} catch (error) {
log('Test failed:');
console.error(error);
}
}
main().catch(error => {
log('Unhandled error:');
console.error(error);
process.exit(1);
});