forked from domdomegg/airtable-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-connection-mcp.js
More file actions
160 lines (132 loc) Β· 3.72 KB
/
Copy pathtest-connection-mcp.js
File metadata and controls
160 lines (132 loc) Β· 3.72 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
#!/usr/bin/env node
// This script directly tests the MCP protocol communication with the AITable MCP server
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, `mcp-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 protocol 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
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()}`);
// Check for responses
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 JSON-RPC response: ${JSON.stringify(response)}`);
if (response.id === 'list-bases') {
log('β
Got response to list_bases request');
// Try list_tables next
setTimeout(() => {
sendListTablesRequest();
}, 1000);
}
if (response.id === 'list-tables') {
log('β
Got response to list_tables request');
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 client hello...');
// First, send a client hello
const clientHello = {
jsonrpc: '2.0',
id: 'client-hello',
method: 'hello',
params: {
version: '0.1.0',
description: 'MCP Protocol Test Client'
}
};
serverProcess.stdin.write(JSON.stringify(clientHello) + '\n');
// After a short delay, send the actual request
setTimeout(() => {
sendListBasesRequest();
}, 500);
}, 2000);
// Function to send list_bases request
function sendListBasesRequest() {
log('Sending list_bases request...');
const listBasesRequest = {
jsonrpc: '2.0',
id: 'list-bases',
method: 'mcp/tool',
params: {
name: 'list_bases',
input: {}
}
};
serverProcess.stdin.write(JSON.stringify(listBasesRequest) + '\n');
}
// Function to send list_tables request
function sendListTablesRequest() {
log('Sending list_tables request...');
const listTablesRequest = {
jsonrpc: '2.0',
id: 'list-tables',
method: 'mcp/tool',
params: {
name: 'list_tables',
input: {
baseId: 'spc12q5HY4ay5'
}
}
};
serverProcess.stdin.write(JSON.stringify(listTablesRequest) + '\n');
}
// Set a timeout
setTimeout(() => {
log('β Test timed out');
serverProcess.kill();
process.exit(1);
}, 30000);