aeonshift commited on
Commit
b7bfba5
·
verified ·
1 Parent(s): e96e0bf

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +23 -1
server.js CHANGED
@@ -1,24 +1,46 @@
1
  const express = require('express');
2
  const { exec } = require('child_process');
 
3
 
4
  const app = express();
5
 
6
  // Run the MCP server as a CLI command
7
- const mcpCommand = `npx @rashidazarang/airtable-mcp --token ${process.env.AIRTABLE_API_TOKEN} --base ${process.env.AIRTABLE_BASE_ID}`;
 
8
  exec(mcpCommand, (error, stdout, stderr) => {
9
  if (error) {
10
  console.error(`Error running MCP server: ${error.message}`);
11
  console.error(`stderr: ${stderr}`);
12
  return;
13
  }
 
14
  console.log(`MCP server stdout: ${stdout}`);
15
  console.error(`MCP server stderr: ${stderr}`);
16
  });
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  app.get('/health', (req, res) => {
19
  res.json({ status: 'healthy' });
20
  });
21
 
 
 
 
 
 
22
  const port = process.env.PORT || 7860;
23
  app.listen(port, () => {
24
  console.log(`Server running on port ${port}`);
 
1
  const express = require('express');
2
  const { exec } = require('child_process');
3
+ const httpProxy = require('http-proxy-middleware');
4
 
5
  const app = express();
6
 
7
  // Run the MCP server as a CLI command
8
+ const mcpCommand = `npx @rashidazarang/airtable-mcp --token ${process.env.AIRTABLE_API_TOKEN} --base ${process.env.AIRTABLE_BASE_ID} --port 7861`;
9
+ console.log(`Starting MCP server with command: ${mcpCommand}`);
10
  exec(mcpCommand, (error, stdout, stderr) => {
11
  if (error) {
12
  console.error(`Error running MCP server: ${error.message}`);
13
  console.error(`stderr: ${stderr}`);
14
  return;
15
  }
16
+ console.log(`MCP server started successfully`);
17
  console.log(`MCP server stdout: ${stdout}`);
18
  console.error(`MCP server stderr: ${stderr}`);
19
  });
20
 
21
+ // Proxy requests to /airtable/mcp to the MCP server running on port 7861
22
+ app.use('/airtable/mcp', httpProxy.createProxyMiddleware({
23
+ target: 'http://localhost:7861',
24
+ changeOrigin: true,
25
+ ws: true, // Enable WebSocket (SSE) proxying
26
+ pathRewrite: {
27
+ '^/airtable/mcp': '/airtable/mcp' // Ensure the path matches what the MCP server expects
28
+ },
29
+ onError: (err, req, res) => {
30
+ console.error(`Proxy error: ${err.message}`);
31
+ res.status(500).send('Proxy error');
32
+ }
33
+ }));
34
+
35
  app.get('/health', (req, res) => {
36
  res.json({ status: 'healthy' });
37
  });
38
 
39
+ // Add a root endpoint for debugging
40
+ app.get('/', (req, res) => {
41
+ res.send('Airtable Node MCP Server is running. Use /airtable/mcp for the MCP endpoint.');
42
+ });
43
+
44
  const port = process.env.PORT || 7860;
45
  app.listen(port, () => {
46
  console.log(`Server running on port ${port}`);