Originally published at https://scriptmasterlabs.com/blog/how-to-build-mcp-server-typescript .
Key takeaways
Define MCP tools once with the TypeScript SDK and Zod, then run the same handlers over stdio for local clients and streamable HTTP for remote ones.
Test locally with MCP Inspector and never log to stdout over stdio, since it corrupts the protocol stream.
Use stateless streamable HTTP mode when selling per-call tools, so 402 payment challenges and retries work without session affinity.
Publish a static tool list and an llms.txt file, because directories read your repo rather than running your server.
Keep tool input schemas limited to what the calling model can plausibly know, since schema mistakes surface as model errors.
To build an MCP server in TypeScript, define your tools with the MCP SDK, run it locally over stdio for Claude Code or Cursor, then expose the same tool handlers over streamable HTTP for remote clients, and publish static tool lists so directories can see what you sell.…