6 MCP Server Patterns That Turn JavaScript APIs Into AI-Callable Tools
MCP made AI tools call your code directly. Not your UI. Not your REST client. Your functions. Here are 6 patterns that convert existing JavaScript services into MCP servers you can ship this week. ...

Source: DEV Community
MCP made AI tools call your code directly. Not your UI. Not your REST client. Your functions. Here are 6 patterns that convert existing JavaScript services into MCP servers you can ship this week. 1. Wrap a REST API as an MCP tool Most teams already have REST APIs. MCP sits on top of them. Before (Express route) // routes/jobs.ts app.get("/jobs", async (req, res) => { const { tech, location } = req.query; const jobs = await db.jobs.findMany({ where: { tech, location } }); res.json(jobs); }); After (MCP tool wrapper) import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { z } from "zod"; const server = new McpServer({ name: "jobs", version: "1.0.0" }); server.tool( "search_jobs", "Search jobs by tech and location", { tech: z.string().optional(), location: z.string().optional() }, async ({ tech, location }) => { const res = await fetch( `https://api.myapp.com/jobs?tech=${tech}&location=${location}` ); const data = await res.json(); return { content: [{ typ