Spaces:
Sleeping
Sleeping
Update server.js
Browse files123456778910111213141516171819202122232425262728293031323334353637383940414243444546const express = require('express');const { exec } = require('child_process');const httpProxy = require('http-proxy-middleware');
const app = express();
// Run the MCP server as a CLI commandconst mcpCommand = `npx @rashidazarang/airtable-mcp --token ${process.env.AIRTABLE_API_TOKEN} --base ${process.env.AIRTABLE_BASE_ID}`;const mcpCommand = `npx @rashidazarang/airtable-mcp --token ${process.env.AIRTABLE_API_TOKEN} --base ${process.env.AIRTABLE_BASE_ID} --port 7861`;console.log(`Starting MCP server with command: ${mcpCommand}`);exec(mcpCommand, (error, stdout, stderr) => { if (error) { console.error(`Error running MCP server: ${error.message}`); console.error(`stderr: ${stderr}`); return; } console.log(`MCP server started successfully`); console.log(`MCP server stdout: ${stdout}`); console.error(`MCP server stderr: ${stderr}`);});
// Proxy requests to /airtable/mcp to the MCP server running on port 7861app.use('/airtable/mcp', httpProxy.createProxyMiddleware({ target: 'http://localhost:7861', changeOrigin: true, ws: true, // Enable WebSocket (SSE) proxying pathRewrite: { '^/airtable/mcp': '/airtable/mcp' // Ensure the path matches what the MCP server expects }, onError: (err, req, res) => { console.error(`Proxy error: ${err.message}`); res.status(500).send('Proxy error'); }}));
app.get('/health', (req, res) => { res.json({ status: 'healthy' });});
// Add a root endpoint for debuggingapp.get('/', (req, res) => { res.send('Airtable Node MCP Server is running. Use /airtable/mcp for the MCP endpoint.');});
const port = process.env.PORT || 7860;app.listen(port, () => { console.log(`Server running on port ${port}`);server.js+23-1