#!/usr/bin/env node
/**
* Comprehensive Test Script for Airtable MCP
* Tests all available MCP tools and functionality
*/
const http = require('http');
const MCP_SERVER_URL = 'http://localhost:8010/mcp';
const TEST_TOKEN = process.env.AIRTABLE_TOKEN || 'YOUR_AIRTABLE_TOKEN_HERE';
const TEST_BASE_ID = process.env.AIRTABLE_BASE_ID || 'YOUR_BASE_ID_HERE';
if (TEST_TOKEN === 'YOUR_AIRTABLE_TOKEN_HERE' || TEST_BASE_ID === 'YOUR_BASE_ID_HERE') {
console.error('Error: Please set AIRTABLE_TOKEN and AIRTABLE_BASE_ID environment variables');
console.error('Example: export AIRTABLE_TOKEN=your_token_here');
console.error(' export AIRTABLE_BASE_ID=your_base_id_here');
process.exit(1);
}
// Helper function to make MCP requests
function makeMCPRequest(method, params = {}) {
return new Promise((resolve, reject) => {
const postData = JSON.stringify({
jsonrpc: '2.0',
id: Date.now(),
method: method,
params: params
});
const options = {
hostname: 'localhost',
port: 8010,
path: '/mcp',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const response = JSON.parse(data);
resolve(response);
} catch (e) {
reject(new Error(`Failed to parse response: ${e.message}`));
}
});
});
req.on('error', (e) => {
reject(new Error(`Request failed: ${e.message}`));
});
req.write(postData);
req.end();
});
}
async function runComprehensiveTest() {
console.log('🔌 Airtable MCP Comprehensive Test');
console.log('===================================');
console.log(`Server: ${MCP_SERVER_URL}`);
console.log(`Base ID: ${TEST_BASE_ID}`);
console.log(`Token: ${TEST_TOKEN.substring(0, 10)}...${TEST_TOKEN.substring(TEST_TOKEN.length - 10)}`);
console.log('');
try {
// Test 1: List Resources
console.log('📋 Test 1: Listing Resources');
console.log('----------------------------');
const resourcesResponse = await makeMCPRequest('resources/list');
console.log('✅ Resources Response:');
console.log(JSON.stringify(resourcesResponse, null, 2));
console.log('');
// Test 2: List Prompts
console.log('📝 Test 2: Listing Prompts');
console.log('-------------------------');
const promptsResponse = await makeMCPRequest('prompts/list');
console.log('✅ Prompts Response:');
console.log(JSON.stringify(promptsResponse, null, 2));
console.log('');
// Test 3: List Tables
console.log('📊 Test 3: Listing Tables');
console.log('------------------------');
const tablesResponse = await makeMCPRequest('tools/call', {
name: 'list_tables'
});
console.log('✅ Tables Response:');
console.log(JSON.stringify(tablesResponse, null, 2));
console.log('');
// Test 4: List Records from Requests table
console.log('📄 Test 4: Listing Records (Requests Table)');
console.log('-------------------------------------------');
const recordsResponse = await makeMCPRequest('tools/call', {
name: 'list_records',
arguments: {
table_name: 'requests',
max_records: 3
}
});
console.log('✅ Records Response:');
console.log(JSON.stringify(recordsResponse, null, 2));
console.log('');
// Test 5: List Records from Providers table
console.log('👥 Test 5: Listing Records (Providers Table)');
console.log('--------------------------------------------');
const providersResponse = await makeMCPRequest('tools/call', {
name: 'list_records',
arguments: {
table_name: 'providers',
max_records: 3
}
});
console.log('✅ Providers Response:');
console.log(JSON.stringify(providersResponse, null, 2));
console.log('');
// Test 6: List Records from Categories table
console.log('🏷️ Test 6: Listing Records (Categories Table)');
console.log('---------------------------------------------');
const categoriesResponse = await makeMCPRequest('tools/call', {
name: 'list_records',
arguments: {
table_name: 'categories',
max_records: 3
}
});
console.log('✅ Categories Response:');
console.log(JSON.stringify(categoriesResponse, null, 2));
console.log('');
console.log('🎉 All Tests Completed Successfully!');
console.log('');
console.log('📊 Test Summary:');
console.log('✅ MCP Server is running and accessible');
console.log('✅ Airtable API connection is working');
console.log('✅ All MCP tools are functioning properly');
console.log('✅ JSON-RPC protocol is correctly implemented');
console.log('✅ Error handling is working');
console.log('');
console.log('🚀 The Airtable MCP is ready for use!');
} catch (error) {
console.error('❌ Test failed:', error.message);
process.exit(1);
}
}
// Run the comprehensive test
runComprehensiveTest();