How to Give Your API an MCP Server in 10 Minutes
Source: Dev.to
What You’re Building
An MCP server is a small adapter layer that sits between your existing API and any AI agent that wants to use it. It exposes your API’s capabilities as tools — named, typed, describable actions the agent can discover and call.
You’re not rewriting your API; you’re wrapping it.
AI Agent → MCP Server → Your Existing APIThe MCP server handles the protocol translation while your API stays exactly as it is.
Step 1: Install the MCP SDK (2 minutes)
Anthropic publishes an official TypeScript SDK:
npm install @modelcontextprotocol/sdkThere’s also a Python SDK:
pip install mcpStep 2: Define Your Tools (5 minutes)
Each tool maps to one of your API endpoints. You define:
- Name – snake_case, descriptive
- Description – plain English; the agent reads this to decide when to use the tool
- Input schema – JSON Schema
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new Server(
{ name: "my-api", version: "1.0.0" },
{ capabilities: { tools: {} } }
);
server.setRequestHandler("tools/list", async () => ({
tools: [
{
name: "create_task",
description:
"Create a new task in the workspace. Use when the user wants to add a task, to‑do, or action item.",
inputSchema: {
type: "object",
properties: {
title: { type: "string", description: "Task title" },
assignee_email: { type: "string", description: "Email of assignee" },
due_date: { type: "string", description: "Due date (YYYY‑MM‑DD)" }
},
required: ["title"]
}
}
]
}));Tip: The description matters more than you think. A vague “Creates a task” is weak; a richer description gives the model context about when to use it.
Step 3: Handle Tool Calls (2 minutes)
server.setRequestHandler("tools/call", async (request) => {
const { name, arguments: args } = request.params;
if (name === "create_task") {
const response = await fetch("https://api.yourapp.com/tasks", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify(args)
});
const task = await response.json();
return {
content: [{ type: "text", text: `Task created: "${task.title}" (ID: ${task.id})` }]
};
}
throw new Error(`Unknown tool: ${name}`);
});
const transport = new StdioServerTransport();
await server.connect(transport);The response content is what the agent sees. Keep it factual — the agent will synthesize it into natural language for the user.
Step 4: Test It (1 minute)
npx @modelcontextprotocol/inspector node your-server.jsThis opens a local UI to call your tools manually before pointing any real AI at it.
Deploying It
- Option A: Expose via HTTP (SSE transport) on a
/mcproute alongside your existing server. - Option B: Deploy as a standalone service — Firebase Functions, AWS Lambda, Railway, etc.
For authentication, pass your API key via MCP’s Authorization header or environment variables. Do not expose credentials through the tool interface.
The Bigger Picture
Adding MCP support to your API is a 10‑minute investment today, but the payoff compounds. Every AI assistant, agent framework, and coding tool that adds MCP support becomes a potential distribution channel for your API. Users who never touched your docs can now use your product through an AI they already trust.
Products that are agent‑ready now will have a significant head start when AI‑driven workflows become the default. Those that aren’t will be invisible.
If you want to skip the server setup entirely, Botlington MCP Host hosts and manages MCP servers for your API — you define the tools, they handle the infrastructure, auth, and routing.