forked from domdomegg/airtable-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-mcp-cursor.js
More file actions
executable file
Β·224 lines (184 loc) Β· 5.61 KB
/
Copy pathtest-mcp-cursor.js
File metadata and controls
executable file
Β·224 lines (184 loc) Β· 5.61 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
#!/usr/bin/env node
// Test script that simulates how Cursor might try to communicate with the MCP server
import { spawn } from 'child_process';
import fs from 'fs';
import path from 'path';
// Create logs directory if it doesn't exist
const logDir = path.join(process.cwd(), 'logs');
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir, { recursive: true });
}
const logFile = path.join(logDir, `cursor-simulation-${Date.now()}.log`);
const logger = fs.createWriteStream(logFile, { flags: 'a' });
function log(msg) {
const timestamp = new Date().toISOString();
const message = `[${timestamp}] ${msg}`;
console.log(message);
logger.write(message + '\n');
}
log('Starting Cursor MCP Simulation');
// Start the MCP server process
const serverProcess = spawn('node', ['dist/index.js'], {
env: {
...process.env,
AITABLE_API_KEY: 'REMOVED_TOKEN',
SPACE: 'spc12q5HY4ay5',
},
stdio: ['pipe', 'pipe', 'pipe']
});
// Listen for process events
serverProcess.on('error', (err) => {
log(`Process error: ${err}`);
});
serverProcess.on('exit', (code) => {
log(`Process exited with code ${code}`);
});
// Collect stderr output
serverProcess.stderr.on('data', (data) => {
const text = data.toString();
log(`STDERR: ${text.trim()}`);
});
// Collect stdout output
serverProcess.stdout.on('data', (data) => {
const text = data.toString();
log(`STDOUT: ${text.trim()}`);
try {
// Sometimes multiple responses might be in one data chunk
const lines = text.trim().split('\n');
for (const line of lines) {
if (!line) continue;
try {
const response = JSON.parse(line);
log(`Got response: ${JSON.stringify(response, null, 2)}`);
if (response.id === 'init') {
log('β
Got response to initialize request');
// Send initialized notification
sendInitializedNotification();
// Try tools list next
setTimeout(() => {
sendToolsListRequest();
}, 1000);
}
if (response.id === 'tools-list') {
log('β
Got response to tools list request');
// Try tool execute next
setTimeout(() => {
sendToolExecuteRequest();
}, 1000);
}
// Check for tool-execute responses with different indices
if (response.id && response.id.startsWith('tool-execute-')) {
const index = parseInt(response.id.split('-')[2]);
log(`β
Got response to tool execute request with method ${index}`);
// If the response doesn't have an error, we found the right method!
if (!response.error) {
log(`π Found working method: ${['tools/execute', 'mcp/tools/execute', 'tooling/execute_tool', 'mcp/tooling/execute_tool'][index]}`);
log('Test completed successfully!');
// Exit with success
setTimeout(() => {
serverProcess.kill();
process.exit(0);
}, 1000);
}
}
} catch (e) {
log(`Error parsing JSON response: ${e.message}`);
}
}
} catch (err) {
log(`Error processing response: ${err.message}`);
}
});
// Wait for server to start
setTimeout(() => {
log('Sending initialize request...');
// First, send initialize request
const initializeRequest = {
jsonrpc: '2.0',
id: 'init',
method: 'initialize',
params: {
protocolVersion: '0.1.0',
clientInfo: {
name: 'Cursor Simulation',
version: '1.0.0'
},
capabilities: {
tools: {},
resources: {}
}
}
};
serverProcess.stdin.write(JSON.stringify(initializeRequest) + '\n');
}, 2000);
// Function to send initialized notification
function sendInitializedNotification() {
log('Sending initialized notification...');
const initializedNotification = {
jsonrpc: '2.0',
method: 'initialized',
params: {}
};
serverProcess.stdin.write(JSON.stringify(initializedNotification) + '\n');
}
// Function to send tools list request
function sendToolsListRequest() {
log('Sending tools list request...');
// Try several method formats
const methods = [
'tools/list',
'mcp/tools/list',
'tooling/list_tools',
'mcp/tooling/list_tools'
];
const method = methods[0]; // Try the first one
const toolsListRequest = {
jsonrpc: '2.0',
id: 'tools-list',
method: method,
params: {}
};
log(`Using method: ${method}`);
serverProcess.stdin.write(JSON.stringify(toolsListRequest) + '\n');
}
// Function to send tool execute request
function sendToolExecuteRequest() {
log('Sending tool execute request...');
// Try several method formats
const methods = [
'tools/execute',
'mcp/tools/execute',
'tooling/execute_tool',
'mcp/tooling/execute_tool'
];
// Try testing each method one at a time
tryMethod(0);
function tryMethod(index) {
if (index >= methods.length) {
log('β All method formats failed');
return;
}
const method = methods[index];
log(`Trying method: ${method}`);
const toolExecuteRequest = {
jsonrpc: '2.0',
id: `tool-execute-${index}`,
method: method,
params: {
name: 'list_bases',
input: {}
}
};
serverProcess.stdin.write(JSON.stringify(toolExecuteRequest) + '\n');
// Set a timeout to try the next method if we don't get a response
setTimeout(() => {
tryMethod(index + 1);
}, 1000);
}
}
// Set a timeout
setTimeout(() => {
log('β Test timed out');
serverProcess.kill();
process.exit(1);
}, 30000);