# Add Streamable HTTP to a stdio MCP Server

Yes. An agent adds a Streamable HTTP entry point to a stdio MCP server from the same tool factory, with Host and Origin checks, tests it and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-streamable-http-transport/mcp-server/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads how the server starts today before it adds a second way in. In a stdio server like the TypeScript weather server in modelcontextprotocol/quickstart-resources, `src/index.ts` defines `buildServer()`, which returns a new `McpServer` with `get-alerts` and `get-forecast` registered, and ends with `serveStdio(buildServer, …)`. The `bin` entry in `package.json` points `weather` at `build/index.js`, and every log line goes through `console.error` because stdout carries the protocol. The package depends on `@modelcontextprotocol/server` and `zod` and nothing else, and its lockfile resolves the SDK to 2.4.0.

That factory is what makes the change small. The SDK's `createMcpHandler(factory)` takes the same kind of function `serveStdio` does and returns a handler whose `fetch(request)` answers one HTTP request with a server built for it. So the agent does not copy the tool registrations. It moves `buildServer` into `src/server.ts`, keeps `src/index.ts` as the stdio entry, and adds `src/http.ts`, which wraps `createMcpHandler(buildServer)` with `toNodeHandler` from `@modelcontextprotocol/node` and mounts it at `/mcp` on a `node:http` server. Any other path answers 404. A second `bin` entry, `weather-http`, starts it, and the stdio command behaves exactly as before.

Then it deals with what stdio never had to: who can reach the port. The SDK's own documentation says the handler performs no Origin or Host validation and no token verification, so the agent puts `hostHeaderValidationResponse` and `originValidationResponse` in front of it with the localhost allowlists the SDK exports, binds `127.0.0.1` unless `HOST` is set, and reads the port from `PORT`. It leaves the default fallback on, which serves clients that still open with the 2025 handshake as well as 2026-07-28 ones, and notes that `legacy: 'reject'` makes the endpoint strict. Authentication is left as a clearly marked seam: where `requireBearerAuth` would go and what a deployment behind a public hostname has to add to the allowlists.

To prove it works the agent builds, starts `weather-http` on a free port and connects with the SDK's `Client` over `StreamableHTTPClientTransport`, lists the tools and calls both. It repeats the checks `tests/helpers/mcp-test-client.ts` makes over stdio, so the two transports are held to one standard, and adds a test that a request with a foreign `Host` header and one with a foreign `Origin` are refused before any tool runs. It runs `npx tsc --noEmit`, `make lint` and `make test`, and confirms the stdio smoke test for this server still passes.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add a Streamable HTTP transport to this stdio MCP server without changing what its tools do. Read package.json, the lockfile for the resolved @modelcontextprotocol/server version, tsconfig.json, the server entry file, the README, AGENTS.md, the Makefile and the tests first. Reuse the existing server factory: move it to its own module, keep the stdio entry working under the same command, and add a second entry that serves the factory with createMcpHandler, adapted to node:http with toNodeHandler from @modelcontextprotocol/node at a version whose peer range matches the installed server package. Mount it at /mcp and answer 404 elsewhere. Bind 127.0.0.1 by default, read HOST and PORT from the environment, and put the SDK's Host and Origin validation with the localhost allowlists in front of the handler. Keep the default legacy fallback and say in the README what legacy: 'reject' changes. Do not add authentication; mark where requireBearerAuth would go and document that the endpoint must not be exposed publicly without it. Add a bin entry and an npm script for the HTTP server and a README section with the command and an example client configuration. Test it: start the server on a free port, connect with the SDK Client over StreamableHTTPClientTransport, list tools, call each tool, and check that a foreign Host header and a foreign Origin are refused. Run the type check, the linters and the existing stdio tests, and open a pull request with the commands and their output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request has one moved function and one new file doing the work. `src/server.ts` holds `buildServer` unchanged, `src/index.ts` shrinks to the stdio call, and `src/http.ts` is the HTTP entry with its validation in front. `package.json` gains `@modelcontextprotocol/node`, the second `bin` entry and a start script, with the lockfile change. The README gets a section with the command, the two environment variables, the URL a client connects to and the warning about public exposure. The HTTP test sits beside the existing helpers and is wired into `make test`.

The description quotes the build, the lint and the test output, the tool list read over HTTP, and the refused requests with their status codes. A reviewer checks three things before merging. The tool handlers must be byte for byte what they were, which the moved-file diff shows. Nothing may write to stdout in the stdio path, since the new module is imported there too. And the listening address must default to loopback, because an MCP server on `0.0.0.0` with no token is an open tool endpoint. In a tutorial repository like this one the agent also reports, without acting on it, that the same change would be owed in the other four languages.

## Run it on every Linear issue labelled remote-mcp

Create an automation in the Project that holds the server's repository with a `linear` trigger on `linear.issue.labeled` and `remote-mcp` in its `labels`. It needs a Linear connection for whoever runs the automation, made in the console under Settings → Connections, and it fires only when the person who added the label is in your Rush org. The trigger adds the issue after the saved prompt and fills nothing in, so the prompt is this page's request plus a line telling the agent to take the port, path and hostnames from the issue when it names them.

A platform team moving a set of local servers behind one gateway labels one issue per server. Each label starts its own run in its own sandbox, and the automation's max runs per hour decides how many start before the rest wait as `queued`. The prompt asks each pull request to mention its issue, so the board shows which servers are done.

## Why run it on Rush?

The code for this is short and the checking is not. Someone has to start the server, connect a real client over HTTP, call the tools, and then try the requests that should fail. On a laptop that usually means one happy-path call from an editor and a note to test the rest later. The agent has a sandbox with a free port and nothing else running, so it does all of it, and the run's record keeps each command and response for the pull request to quote.

It also keeps the change honest about scope. A transport is a place where a quick copy of the tool definitions or a permissive default slips in unnoticed. The agent reuses the one factory, leaves authentication out on purpose and says so, and reports what it did not do. When five servers need the same move, five runs start from the same prompt and each reads its own entry file, package manager and SDK version.

## Frequently asked questions

### Does the stdio transport keep working?

Yes. The stdio entry file keeps its command and its `serveStdio` call, and it imports the same factory the HTTP entry uses. The existing smoke test for the stdio server runs again before the pull request opens, and its output is in the description.

### Will older MCP clients still connect over HTTP?

With the default settings, yes. `createMcpHandler` serves the 2026-07-28 revision and falls back to stateless serving for clients that open with the 2025 handshake. Passing `legacy: 'reject'` turns that off, and the README section the agent writes says when you would want to.

### Why is there no authentication in the pull request?

Because it depends on your identity provider, and a guessed scheme is worse than none. The entry binds to loopback and checks `Host` and `Origin`, which is what a local HTTP server needs. For a public deployment the SDK has `requireBearerAuth` and helpers for OAuth protected-resource metadata; say which issuer and scopes to use and the agent wires them in as a follow-up.

### Does it work with Express, Hono or a Worker?

Yes. The handler's `fetch` is the web-standard form, so on Cloudflare Workers, Deno, Bun or Hono it is mounted directly, and Express or Fastify use `toNodeHandler`. If your repository already has a web framework, the agent mounts the handler as a route there and adds no second HTTP server.

### Can I use this for a Python server instead?

The job is the same and the calls differ. The agent reads which SDK and version the project pins and uses that SDK's HTTP serving, then runs the same client-side checks. Name the language in the prompt if the repository holds more than one server.

## More MCP server jobs

- [Review Pull Requests on an MCP Server](https://getrush.ai/run/review-pull-requests/mcp-server/)
- [Write Unit Tests for an MCP Server](https://getrush.ai/run/write-unit-tests/mcp-server/)

## More jobs like this: Turn a Linear label into a PR

- [Add Structured Data to a Pelican Blog](https://getrush.ai/run/add-structured-data/pelican/)
- [Add JSON-LD Structured Data to a Zola Site](https://getrush.ai/run/add-structured-data/zola/)
- [Add Structured Logging to a Gin API from a Linear Issue](https://getrush.ai/run/add-structured-logging/gin/)
- [Add Structured Logging to a Node.js App from a Linear Issue](https://getrush.ai/run/add-structured-logging/nodejs/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
