跳到正文
DEV Community· 李峰·· 41 分鐘前AI 評分54

如何在 256MB 容器中建置 11 個無需代理伺服器的遠端 MCP 伺服器:架構與免費設定生成器

Building 11 Zero-Proxy Remote MCP Servers in 256MB Containers (Architecture + Free Config Generator)

AI 導讀

作者在過去一週建置並部署 11 個託管式 Streamable HTTP Remote MCP 伺服器,每個均運行於 256 MB Node.js 22 容器,且不使用無頭瀏覽器或代理伺服器。

正文

李峰

Most tutorials for Model Context Protocol (MCP) servers assume two things:

  1. Users want to install Node/Python locally and babysit stdio processes.
  2. Web-data tools need heavyweight Playwright containers and residential proxies.

In practice, neither scales well for real AI agents in Claude Desktop, Cursor, Windsurf, or n8n.

Over the past week I built and deployed 11 hosted Streamable HTTP Remote MCP servers (/mcp), every single one running in a 256 MB Node.js 22 container with zero headless browsers and zero proxies.

Here are the architectural lessons that actually mattered in production—plus the open-source STDIO/HTTP bridge and a free 1-click JSON config generator.


1. Stateless Streamable HTTP (/mcp) Beats Long-Lived Sessions

For hosted remote MCP servers behind serverless/standby autoscalers, sticky in-memory sessions break on cold restarts. Using @modelcontextprotocol/sdk's StreamableHTTPServerTransport in stateless JSON-response mode (sessionIdGenerator: undefined, enableJsonResponse: true) creates a clean server + transport per request and tears it down cleanly on res.on('close').

Result: Zero memory leaks, sub-200ms warm tool execution, and 256 MB RAM ceiling.

2. Two-Stage Docker Builds Cut Image Size & Avoid NODE_ENV=production Traps

Base Node production images often run with NODE_ENV=production, causing npm install to silently skip TypeScript (tsc). Using a clean 2-stage Dockerfile (npm install --include=dev && npm run build in builder, copying only dist/ to the runtime stage with --omit=dev) keeps deployments fast and deterministic.

3. Real-World Public API Gotchas We Hit (So You Don't Have To)

  • Substack: /api/v1/archive migrated from offset= (now returns HTTP 400) to cursor=<nextCursor>.
  • Kalshi v2: Live prices now live in dollar-denominated fields (yes_bid_dollars, yes_ask_dollars) and querying /trade-api/v2/events?status=open&with_nested_markets=true avoids noisy combo-parlay clutter.
  • SEC EDGAR XBRL (companyfacts): Always merge across multiple US-GAAP revenue tags (Revenues, RevenueFromContractWithCustomerExcludingAssessedTax, SalesRevenueNet) and filter duration length (300+ days for annual 10-K) so prior-year comparative rows never overwrite current fiscal years.
  • Empty-Input QA Hardening: Always provide real default values in schemas and runtime fallbacks when {} is passed so automated health checks never fail.

Try Them Live or Generate Your MCP Config in 1 Click

If you are building automated workflows on top of these endpoints, I also bundled 5 ready-to-run self-hosted n8n workflows + Docker Compose here: https://fengyetnot.gumroad.com/l/skuqx

Curious what remote MCP data sources developers here still struggle to find without paying $200/mo in proxies—drop them below!

來源:DEV Community · dev.to