Serving MCP and REST from the same TypeScript process
MCP is becoming a standard way agents discover and call tools. Claude Desktop, Cursor, Windsurf, and others all speak MCP. But the ecosystem has a split-brain problem: your HTTP API serves humans a...

Source: DEV Community
MCP is becoming a standard way agents discover and call tools. Claude Desktop, Cursor, Windsurf, and others all speak MCP. But the ecosystem has a split-brain problem: your HTTP API serves humans and scripts, and MCP serves agents but they call the same underlying logic. This article compares three ways to bridge that gap: Raw MCP SDK — build an MCP server from scratch Wrap your API by hand — keep your API, add an MCP layer manually Graft — define once, serve both transports from one process I'll use the same example throughout: a simple docs API with search_docs and get_doc tools. Approach 1: Raw MCP SDK The @modelcontextprotocol/sdk package gives you full control over the MCP protocol. Here's a minimal server: // mcp-server.ts import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { z } from "zod"; const server = new McpServer({ name: "docs-api", version: "1.0.0", }); server.tool( "search_docs", { q: z.string(), limit: z.number().optional() }, async ({ q, limit }