File size: 746 Bytes
eec059a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const http = require('http');
const fs = require('fs');
const path = require('path');
const { createProxyServer } = require('http-proxy');

const GATEWAY_PORT = 3100;
const PORT = 8000;

const proxy = createProxyServer({ target: `http://localhost:${GATEWAY_PORT}`, ws: true });
const serverCard = fs.readFileSync(path.join(__dirname, 'server-card.json'));

const server = http.createServer((req, res) => {
  if (req.url === '/.well-known/mcp/server-card.json') {
    res.writeHead(200, { 'Content-Type': 'application/json' });
    return res.end(serverCard);
  }
  proxy.web(req, res);
});

server.on('upgrade', (req, socket, head) => {
  proxy.ws(req, socket, head);
});

server.listen(PORT, () => console.log(`Proxy running on port ${PORT}`));