forked from domdomegg/airtable-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-connection.js
More file actions
121 lines (101 loc) Β· 2.96 KB
/
test-connection.js
File metadata and controls
121 lines (101 loc) Β· 2.96 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
#!/usr/bin/env node
// This script directly tests the JSON-RPC communication with the MCP server
// by using standard input/output pipes
import { spawn } from 'child_process';
import fs from 'fs';
import path from 'path';
// Create a log file
const logDir = path.join(process.cwd(), 'logs');
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir, { recursive: true });
}
const logFile = path.join(logDir, `connection-test-${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 MCP server connection test');
// 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
let stderrBuffer = '';
serverProcess.stderr.on('data', (data) => {
const text = data.toString();
stderrBuffer += text;
log(`STDERR: ${text.trim()}`);
});
// Collect stdout output
let stdoutBuffer = '';
serverProcess.stdout.on('data', (data) => {
const text = data.toString();
stdoutBuffer += text;
log(`STDOUT: ${text.trim()}`);
// Check for response to our request
if (text.includes('"id":"test-request"')) {
log('β
Got response to our test request');
// Try one more request
setTimeout(() => {
const listTablesRequest = {
jsonrpc: '2.0',
id: 'list-tables-request',
method: 'mcp/tool',
params: {
name: 'list_tables',
input: {
baseId: 'spc12q5HY4ay5'
}
}
};
log('Sending list_tables request...');
serverProcess.stdin.write(JSON.stringify(listTablesRequest) + '\n');
}, 1000);
}
if (text.includes('"id":"list-tables-request"')) {
log('β
Got response to list_tables request');
log('Test completed successfully!');
// Wait a moment to finish writing logs, then exit
setTimeout(() => {
serverProcess.kill();
process.exit(0);
}, 1000);
}
});
// Wait a bit for server to start up
setTimeout(() => {
log('Server should be started by now, sending test request...');
// Send a JSON-RPC request to the list_bases tool
const request = {
jsonrpc: '2.0',
id: 'test-request',
method: 'mcp/tool',
params: {
name: 'list_bases',
input: {}
}
};
log(`Sending request: ${JSON.stringify(request)}`);
serverProcess.stdin.write(JSON.stringify(request) + '\n');
}, 2000);
// Set a timeout to kill the process if test takes too long
setTimeout(() => {
log('β Test timed out');
serverProcess.kill();
process.exit(1);
}, 30000);