Skip to main content
Keep the tool from the stdio tutorial. Replace the transport to own a Node HTTP listener:
src/server.ts
The listener binds to 127.0.0.1 by default. The route is /mcp. A managed listener’s default allowed hosts match loopback authorities on its actual bound port; binding and host validation are separate settings.

Call it

Compile and start the server from your project directory:
In a second terminal, use Inspector as described in client setup, or send a direct modern protocol call:
The response contains the greeting as a tool result. Modern requests include protocol metadata and capabilities on each call; this example declares an empty capability set. Tools with additional required parameter headers need those headers too.

Existing applications

If your framework owns the listener, use createHttpHandler() from @toolgrain/http for Web Request/Response, or createNodeHttpHandler() from @toolgrain/node for Node middleware. The combined handlers own MCP and auth metadata routing; mount them at the application root before body parsing. See HTTP behavior and framework recipes.

Before exposing the endpoint

Configure exact public allowedHosts, handle trusted proxy normalization in the application, and add authorization when the tools require it. allowedOrigins is a separate browser-origin check and does not emit CORS response headers. Applications own CORS, TLS, listener limits, and public URL normalization. The current HTTP implementation uses independent POST requests and JSON responses; it does not provide sessions, SSE streams, or resumability.