MCP & Architecture

How to Build an MCP Server (and When a Remote MCP Gateway Wins)

Building a custom MCP server takes an afternoon for one internal database, but maintaining OAuth, credential vaults, rate limits, and billing across external APIs quickly turns into an infrastructure project. Here is when to build and when to connect a gateway.

Build a thin custom MCP server for proprietary internal business logic; use a remote MCP gateway for external data APIs and shared SaaS credentials.

The minimal anatomy of a custom MCP server

An MCP server exposes tools, resources, or prompts over stdio (local subprocess) or Streamable HTTP (remote endpoint). For an internal read-only database or custom domain workflow, keeping the server small—three to five focused tools with strict JSON Schema validation—yields the highest agent reliability.

  • Prefer Streamable HTTP over stdio whenever more than one developer shares the server.
  • Validate inputs strictly and return concise structured JSON rather than raw megabyte dumps.
  • Never accept raw third-party API keys as tool parameters from the LLM.

Where DIY MCP servers become a maintenance tax

Teams rarely regret writing the first 100 lines of an MCP server; they regret maintaining twenty of them. Token refresh, per-teammate revocation, SSRF protection on user-supplied URLs, schema changes from upstream vendors, and scattered .env files consume weeks of engineering time.

Hybrid pattern: custom internal MCP + Duang for external APIs

Keep your custom MCP server focused strictly on proprietary internal state, and offload external live data (search, scraping, SEO, enrichment, social) plus shared team SaaS connections to Duang's remote MCP gateway.

Pair your custom MCP with Duang Remote MCP
set up https://duang.ai/SKILL.md

Try live capabilities right now.

Connect to your AI agent in 60 seconds.

Chat promptPaste into Claude Code, OpenClaw, OpenCode, Grok Bot, Antigravity, Hermes, or Pi

Read https://duang.ai/SKILL.md and use duang to run web.page.read.

Frequently asked questions

Should I use stdio or Streamable HTTP for a team MCP server?

Use Streamable HTTP for team use. Stdio requires installing runtimes and distributing API keys to every developer laptop, whereas a remote HTTP MCP centralizes OAuth, audit logs, and instant access revocation.

Can I self-host Duang's MCP engine instead of building from scratch?

Yes. Duang's core engine is source-available on GitHub, so you can audit the credential boundary or self-host the entire MCP server and provider catalog on your own infrastructure.

How do I prevent prompt injection from exfiltrating API keys in an MCP server?

Keep credentials out of the agent process completely. Inject vendor secrets only inside a server-side boundary after validating destination hosts, and issue short-lived or revocable tokens to the agent.