@moorchehai/mcp 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Moorcheh MCP Client Test
3
+ *
4
+ * This script tests the MCP server by sending a tools/list request
5
+ */
6
+
7
+ import { spawn } from 'child_process';
8
+ import { fileURLToPath } from 'url';
9
+ import { dirname, join } from 'path';
10
+
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = dirname(__filename);
13
+ const projectRoot = join(__dirname, '..');
14
+
15
+ console.log('Moorcheh MCP Client Test');
16
+ console.log('============================\n');
17
+
18
+ // Test the server by sending a tools/list request
19
+ async function testMCPConnection() {
20
+ console.log('Testing MCP server connection...');
21
+
22
+ return new Promise((resolve, reject) => {
23
+ const serverProcess = spawn('node', ['server/index.js'], {
24
+ cwd: projectRoot,
25
+ stdio: ['pipe', 'pipe', 'pipe'],
26
+ env: {
27
+ ...process.env,
28
+ NODE_ENV: 'test'
29
+ }
30
+ });
31
+
32
+ let output = '';
33
+ let errorOutput = '';
34
+ let toolsList = [];
35
+ let toolsReceived = false;
36
+
37
+ serverProcess.stdout.on('data', (data) => {
38
+ const dataStr = data.toString();
39
+ output += dataStr;
40
+
41
+ // Try to parse JSON responses
42
+ try {
43
+ const lines = dataStr.split('\n').filter(line => line.trim());
44
+ for (const line of lines) {
45
+ const response = JSON.parse(line);
46
+ if (response.result && response.result.tools) {
47
+ toolsList = response.result.tools;
48
+ toolsReceived = true;
49
+ console.log('āœ… Received tools list from server');
50
+ console.log(' Available tools:');
51
+ toolsList.forEach(tool => {
52
+ console.log(` - ${tool.name}: ${tool.description}`);
53
+ });
54
+ }
55
+ }
56
+ } catch (e) {
57
+ // Not JSON, continue
58
+ }
59
+ });
60
+
61
+ serverProcess.stderr.on('data', (data) => {
62
+ // Only show error output if it's not just "Server started"
63
+ const errorStr = data.toString();
64
+ if (!errorStr.includes('Server started')) {
65
+ errorOutput += errorStr;
66
+ }
67
+ });
68
+
69
+ serverProcess.on('close', (code) => {
70
+ if (toolsReceived) {
71
+ console.log('āœ… MCP server test completed successfully');
72
+
73
+ // Only show actual errors, not warnings
74
+ if (errorOutput.trim() && !errorOutput.includes('Server started')) {
75
+ console.log('āš ļø Server warnings:', errorOutput.trim());
76
+ }
77
+
78
+ console.log(`\nšŸŽ‰ Successfully found ${toolsList.length} tools!`);
79
+ resolve(true);
80
+ } else if (code === 0) {
81
+ console.log('āœ… MCP server started successfully');
82
+
83
+ if (errorOutput.trim() && !errorOutput.includes('Server started')) {
84
+ console.log('āš ļø Server warnings:', errorOutput.trim());
85
+ }
86
+
87
+ console.log('\nāš ļø No tools found in response');
88
+ resolve(false);
89
+ } else {
90
+ console.log('āŒ MCP server failed to start');
91
+ if (errorOutput.trim()) {
92
+ console.log('Error output:', errorOutput.trim());
93
+ }
94
+ reject(new Error(`Server exited with code ${code}`));
95
+ }
96
+ });
97
+
98
+ serverProcess.on('error', (error) => {
99
+ console.log('āŒ Failed to start MCP server:', error.message);
100
+ reject(error);
101
+ });
102
+
103
+ // Send tools/list request after a short delay
104
+ setTimeout(() => {
105
+ try {
106
+ const toolsListRequest = {
107
+ jsonrpc: "2.0",
108
+ id: 1,
109
+ method: "tools/list"
110
+ };
111
+
112
+ console.log('Sending tools/list request to server...');
113
+ serverProcess.stdin.write(JSON.stringify(toolsListRequest) + '\n');
114
+ } catch (error) {
115
+ console.log('āŒ Failed to send tools/list request:', error.message);
116
+ }
117
+ }, 2000);
118
+
119
+ // Kill the process after 10 seconds
120
+ setTimeout(() => {
121
+ try {
122
+ serverProcess.kill();
123
+ console.log('šŸ›‘ Test completed, shutting down server...');
124
+ } catch (error) {
125
+ console.log('āš ļø Could not kill server process:', error.message);
126
+ }
127
+ }, 10000);
128
+ });
129
+ }
130
+
131
+ // Run the test
132
+ testMCPConnection()
133
+ .then((success) => {
134
+ if (success) {
135
+ console.log('\nšŸŽ‰ MCP server test completed successfully!');
136
+ console.log('\nThe server is ready to use with MCP clients.');
137
+ console.log('\nNext steps:');
138
+ console.log('1. Set up your .env file with MOORCHEH_API_KEY');
139
+ console.log('2. Configure your MCP client (Claude Desktop or Cursor)');
140
+ console.log('3. Start the server with: npm start');
141
+ } else {
142
+ console.log('\nāš ļø MCP server started but no tools were found');
143
+ console.log('This might indicate an issue with tool registration');
144
+ }
145
+ })
146
+ .catch((error) => {
147
+ console.log('\nāŒ MCP server test failed:', error.message);
148
+ console.log('\nTroubleshooting:');
149
+ console.log('1. Make sure all dependencies are installed: npm install');
150
+ console.log('2. Check that src/server/index.js exists');
151
+ console.log('3. Verify your Node.js version is >= 18.0.0');
152
+ console.log('4. Ensure your .env file has MOORCHEH_API_KEY set');
153
+ process.exit(1);
154
+ });