HTTP transport

Guide

How to run the server over Streamable HTTP, with the /mcp and /health endpoints, the HOST and PORT settings, and the Host and Origin checks that protect against DNS rebinding.

Status
stable
Trust tier
unverified
Generated
claude-code/claude-opus-5-5, 2026-12-05
Tags
httptransportstreamable-httpsecurityhealth-check

In HTTP mode the server serves MCP Streamable HTTP on one path, /mcp, and a health check on /health. Use it for clients that connect by URL, and for shared or remote deployments. For a client that starts the server itself, stdio is simpler (see Connecting clients).

The HTTP server uses createMcpHandler from @modelcontextprotocol/server and toNodeHandler from @modelcontextprotocol/node. It serves both MCP protocol revisions, 2025-11-25 and 2026-07-28, from the same tool definitions as stdio.1 The protocol era is chosen for each request, and each server instance comes from the same createServer factory.2 Transports describes the internals.

The server has no authentication and no CORS handling. For anything public, put a reverse proxy in front of it.3

Start the server

MCP_TRANSPORT=http node build/index.js
# or
node build/index.js --http

HTTP mode is on when the command line contains --http or when MCP_TRANSPORT is exactly http. Any other value means stdio.4 When the server is listening, it logs the message NSF Awards MCP server listening to stderr with two fields: url (for example http://127.0.0.1:3000/mcp) and hostCheck, which is the list of accepted Host names, or "disabled" when the Host check is off.1

Endpoints

The server routes on the path only; the query string is ignored. The responses below come from src/http.ts and its tests.1 5

Path Method Response
/mcp MCP Streamable HTTP MCP JSON-RPC, after the Host and Origin checks.
/health GET 200 with {"status":"ok","version":"2.0.0"} and Content-Type: application/json. The version is the one in package.json.
/health any other method 405 with the same JSON body.
anything else (also /mcpx) any 404 with {"error":"Not found; the MCP endpoint is /mcp"}.

/health is handled before the Host and Origin checks, so it answers whatever Host header the request carries. A load-balancer probe that uses an internal address therefore still passes when MCP_ALLOWED_HOSTS is set to a public name.1

Settings

httpOptionsFromEnv in src/http.ts reads four variables.1 5

Variable Default Meaning
HOST 127.0.0.1 Bind address. The loopback default lets only local clients connect.
PORT 3000 Listen port. A value that is not a positive integer (abc, 0, -1, 80.5, empty) falls back to 3000.
MCP_ALLOWED_HOSTS see Host check Comma-separated Host header names accepted on /mcp. Blanks are trimmed and empty items dropped.
MCP_ALLOWED_ORIGINS localhost,127.0.0.1,[::1] Comma-separated Origin host names accepted on /mcp.

A blank MCP_ALLOWED_HOSTS or MCP_ALLOWED_ORIGINS (for example " , ") counts as unset.5 Configuration lists every other variable, such as LOG_LEVEL and the NSF_API_* settings.

Host and Origin checks

These checks protect against DNS rebinding. They apply to /mcp only.3 A request that fails either check gets HTTP 403 with a JSON-RPC error body whose error.code is -32000.5

Host check

Which Host names pass depends on the bind address and on MCP_ALLOWED_HOSTS.1 5

HOST MCP_ALLOWED_HOSTS Accepted Host names
loopback: 127.0.0.1 (default), localhost, ::1 or [::1] unset localhost, 127.0.0.1, [::1]
any set exactly the listed names
anything else, for example 0.0.0.0 unset any: the Host check is off

The port in the Host header does not matter: Host: 127.0.0.1:3000 passes when 127.0.0.1 is allowed.5 When you bind to all interfaces (HOST=0.0.0.0, which the Docker image does), set MCP_ALLOWED_HOSTS to the public host name, or run behind a reverse proxy that sets it.3

Origin check

Requests without an Origin header, which is the case for non-browser clients, are accepted. A request with an Origin header passes only when its host name is in MCP_ALLOWED_ORIGINS.3 The default list stays localhost, 127.0.0.1 and [::1] even when the server binds to 0.0.0.0.5 For example, Origin: http://localhost:5173 is accepted by default, and Origin: https://evil.example gets 403.5 Give host names, not full origins: MCP_ALLOWED_ORIGINS=app.example.org,claude.ai.

Examples

Check the health endpoint:

curl http://127.0.0.1:3000/health
# {"status":"ok","version":"2.0.0"}

Send an MCP initialize request by hand. This is the request the CI smoke test sends; its Accept header allows both JSON and an event stream:6

curl -fsS -X POST http://127.0.0.1:3000/mcp \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"ci","version":"1"}}}'

The response contains "name":"nsf-awards-mcp" in serverInfo.6

See the Host check reject a foreign name:

curl -s -o /dev/null -w '%{http_code}\n' -X POST -H 'Host: evil.example' http://127.0.0.1:3000/mcp
# 403

Bind to all interfaces for a known public name:

HOST=0.0.0.0 PORT=8080 MCP_ALLOWED_HOSTS=nsf.example.org MCP_TRANSPORT=http node build/index.js

Register the running server with Claude Code:

claude mcp add --transport http nsf-awards http://127.0.0.1:3000/mcp

Behind a reverse proxy

deployment/nginx/nsf-awards-mcp.conf is a starting point. It proxies /mcp without buffering or caching (responses can be SSE streams), with a 300 s read timeout, and proxies /health separately. It passes the client’s Host header through, so run the backend with MCP_ALLOWED_HOSTS set to the nginx server_name, or the backend rejects every proxied request with 403.7 See Deployment.

Shutdown

On SIGINT or SIGTERM the server logs Shutting down, stops accepting connections and exits with code 0. If open connections keep it from closing, it exits anyway after 5 seconds.4

  1. Streamable HTTP transport (src/http.ts) ↩ ↩2 ↩3 ↩4 ↩5 ↩6

  2. Project notes (CLAUDE.md) ↩

  3. Installation guide (INSTALL.md) ↩ ↩2 ↩3 ↩4

  4. Server entry point (src/index.ts) ↩ ↩2

  5. HTTP transport tests ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8

  6. CI workflow (Docker HTTP smoke test) ↩ ↩2

  7. nginx reverse proxy example ↩

Sources

  1. Streamable HTTP transport (src/http.ts) http-transport
  2. HTTP transport tests http-tests
  3. Server entry point (src/index.ts) entry-point
  4. Installation guide (INSTALL.md) install-guide
  5. CI workflow (Docker HTTP smoke test) ci-workflow
  6. Project notes (CLAUDE.md) claude-md
  7. nginx reverse proxy example nginx-conf