modelcontextprotocol / modelcontextprotocol/typescript-sdk
SDK makes HTTPS fetches through an HTTP proxy
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 13.4k
- Fork
- 2.2k
- Merge medio
- 3g 15h
- PR unite (30g)
- 4
Descrizione
We have a corporate proxy, running on a localhost port, for third-party applications to be able to talk to internal services over HTTP. We can't complete connections over this proxy with the Typescript SDK (via the inspector) because, as far as I can tell, Node's fetch implementation ends up trying to run an HTTPS connection through the proxy and fails as the initial CONNECT to set up a tunnel gets early-terminated in a situation where the SDK is expecting the result of a plain HTTP call. In particular, here:
we get Unexpected content type: null, which our logs show is in response to that CONNECT request. (at the JSON-RPC layer, this is from the initialize request)
Ideally, when we have an HTTP_PROXY env var and no HTTPS_PROXY, we wouldn't be trying to use HTTPS at all.
As a reproduction of the CONNECT request being made, I had Claude write me a little fake version of an HTTP proxy:
st-ajgray1:mcp-repro ajgray$ cat proxy-server.js
const http = require('http');
const net = require('net');
const server = http.createServer((req, res) => {
console.log(`Regular HTTP request: ${req.method} ${req.url}`);
// Handle normal HTTP requests
res.writeHead(200);
res.end('HTTP request handled');
});
server.on('connect', (req, clientSocket, head) => {
console.log(`CONNECT request detected for: ${req.url}`);
// Log but reject the CONNECT request
clientSocket.write('HTTP/1.1 400 Bad Request\r\n\r\n');
clientSocket.end();
});
server.listen(8888, () => {
console.log('Proxy server running on port 8888');
});
Running the inspector while pointing at that proxy:
st-ajgray1:inspector ajgray$ HTTP_PROXY=http://127.0.0.1:8888 npm run start
And then trying to connect to a Streamable HTTP server fails:
because this CONNECT request is detected:
st-ajgray1:mcp-repro ajgray$ node proxy-server.js
Proxy server running on port 8888
CONNECT request detected for: fake-mcp-server.com:80
AIUI, this is consistent with the underlying fetch library, undici, trying to make this an HTTPS request. Due to limitations of our proxy, only HTTP would play nice with our systems; we would prefer that the SDK here make undici stay in HTTP-land here.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in src/client/streamableHttp.ts intorno alle righe 455-458 e riproduci il problema tramite l’inspector con HTTP_PROXY e il proxy-server.js fornito. Traccia il modo in cui l’SDK e Node fetch scelgono il proxy per la richiesta initialize; il lavoro è completo quando un proxy solo HTTP non attiva CONNECT e l’inizializzazione di Streamable HTTP ha successo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- nodejs, typescript
- Ambito
- networking
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 52/100