aicode8
AI AgentsUpdated: 2026-09-10

MCP in practice: build an MCP Server for your docs or API

From zero to a working MCP server for your docs and API: stdio and SSE transport, least-privilege scopes, and auth.

On this page

Quick answer

How is MCP different from a regular API?

MCP is a standardized protocol — agents discover and call tools through one set of primitives. A regular API needs per-endpoint adaptation.

Machine-readable page data: /data/mcp-practical.json

In-depth analysis

MCP (Model Context Protocol) is an open standard released in 2024 that lets large models connect to tools and data sources through a single protocol. Three steps to a working setup: (1) choose a transport — stdio locally, SSE/HTTP with Bearer auth remotely; (2) build a least-privilege Server with read-only scope; (3) register the endpoint in llms.txt. Bottom line up front: an Agent can read your docs without crawling the entire site, provided the endpoint is read-only and properly authenticated. Common pitfalls are mixing stdio and SSE, and over-broad scopes that get misused.

MCP · Config example
// mcp-server.ts — @modelcontextprotocol/sdk ^1.0 stdio read-only Server
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new McpServer({ name: 'docs-readonly', version: '1.0.0' });
server.tool('read_doc', { path: schema.string() }, async ({ path }) => {
  // scope is minimized to read-only — never expose write or full filesystem access
  return { content: [{ type: 'text', text: readAllowed(path) }] };
});

const transport = new StdioServerTransport();
await server.connect(transport);

// Client registration in claude_desktop_config.json:
// "mcpServers": { "docs": { "command": "node", "args": ["mcp-server.ts"] } }
Best practices:Before cross-environment deployment, smoke-test dependency versions and build cache to prevent implicit version conflicts from leaking to production.
Pitfalls:stdio and SSE/HTTP transports cannot be mixed on the same Server. Remote endpoints must use Bearer auth with the scope minimized to read-only — otherwise you are effectively shipping your source code naked. Declare the tool list explicitly rather than exposing blanket file-read permissions. Before cross-environment deployment, smoke-test dependency versions and build cache to prevent implicit version conflicts.

MCP Overview · Key takeaways

  • Tech choice and boundaries confirmed
  • Core config in place
  • Locally verified
  • Postmortem notes recorded

FAQ & pitfalls

Is it safe to expose MCP on the public internet?

Only with Bearer auth and a scope minimized to read-only — otherwise you are effectively shipping your source code naked.

Share & save

My shelf0
← Back to homeTopic: MCP in practice

What readers are asking

Questions that keep coming back in reader feedback, already answered.

  1. 01
    Can one MCP server speak both stdio and HTTP?

    No — a server picks a single transport. A remote endpoint must carry Bearer auth and scope its tools to read-only, otherwise you are exposing source execution to the public internet.

    See the full guide →
  2. 02
    How should auth work when an MCP server runs at the edge?

    Remote MCP goes over SSE or HTTP with a Bearer token, and tools get read-only scope; local stdio is never network-exposed. Do not put both transports behind the same server.

    See the full guide →
  3. 03
    Why is my Astro component's interactivity not working?

    Components ship as zero-JS HTML by default, so an interactive one needs a client:* directive (client:load, client:visible, …). Without it the script is never bundled into the page.

    See the full guide →
All questions →

Follow along as I build with AI

Get the honest, real-time record: what I build, what breaks, and what I learn — from a non-technical founder. No jargon, no fluff.

We respect your inbox. One click to unsubscribe, anytime.