Creating an MCP server step by step

developer2026-12-01

On this page

Creating an MCP server means writing a small program. The program uses an official MCP SDK and registers one or more tools, each with a name, a description and an input schema. It starts the server over a transport such as stdio. An MCP client launches that program and calls its tools over JSON-RPC, as described at https://modelcontextprotocol.io. A first server fits in a single file.

What an MCP server does

An MCP server exposes tools, resources and prompts to a client. The client is usually an AI assistant or an IDE that speaks the Model Context Protocol. The protocol is documented at https://modelcontextprotocol.io. Most first servers expose only tools.

A tool is a named function. It has a description that tells the model when to call it. It also has an input schema that describes its arguments. The model reads these fields and decides whether to call the tool.

Pick a language and an SDK

Use the official SDK for your language. The official SDKs include Python and TypeScript packages, listed at https://modelcontextprotocol.io. Install the package with your package manager, then create a project folder with one entry file.

Keep dependencies small. The client starts your server as a process, so a light install keeps startup fast and makes failures easier to read.

Define a tool with a schema

Create a server object. Then register a function with a name and a description. The schema comes from the function's type hints. Write the description for the model, not for a human reader. Say what the tool does and when to use it.

from mcp.server.fastmcp import FastMCP\n\nmcp = FastMCP('math-demo')\n\n@mcp.tool()\ndef add_numbers(a: int, b: int) -> int:\n    'Return the sum of two integers.'\n    return a + b\n\nif __name__ == '__main__':\n    mcp.run()\n

This server registers one tool. The client sees the name, the description and the two integer arguments. The call returns the sum as its result.

Choose a transport

The stdio transport runs the server as a child process. The client writes JSON-RPC messages to standard input and reads replies from standard output. Stdio suits servers that run on the same machine as the client.

Use an HTTP transport when the server runs on another machine. The server then listens on a network port, and the client connects to its address.

Never print debugging text to standard output in a stdio server. The client reads that stream as protocol data. Write logs to standard error instead.

Connect the server to a client

Add an entry to the client configuration. The entry names the command and arguments that start the server. Most clients read a JSON configuration file, and the entry points to the absolute path of your script.

Restart the client after you save the file. The client starts the server again and lists its tools in the session.

Test and debug the server

Run the server directly first and confirm it starts without errors. Then run the MCP Inspector, which the protocol project publishes at https://modelcontextprotocol.io. The Inspector lists your tools and lets you call them by hand.

Check the input schema in the Inspector before you change the description. A wrong argument type often explains a failed call better than the model's wording does.

Common mistakes

  • Writing to standard output in a stdio server. The client reads that stream as protocol data, so stray log lines break the session.
  • Writing vague descriptions. The model picks tools from their descriptions, so a vague description leads to wrong calls.
  • Loosening schemas. Type every argument. A tight schema rejects bad input before your code runs.

Where a gateway fits

A server you write yourself serves one set of tools. A gateway routes calls from one client to many upstream tools, so you do not wire each API by hand.

Search the tool catalog before you build a server for a common API. Hosted tools for popular services often remove the need for a custom server. Give your agent MCP tools for common work, then write a custom server only for logic that no catalog entry covers.

Live pricing — developer

Price per call, developer tools Horizontal bar chart of the price per call and the cache-hit price, in US dollars, for 8 developer tools. The same values are in the table below the chart. Price per call Cache-hit price $0.0 $0.5 $1.0 Usage Time SeriesUsage Time Series $0.0 $0.0 Per-Tool Usage BreakdownPer-Tool Usage Breakdown $0.0 $0.0 Usage SummaryUsage Summary $0.0 $0.0 Call ToolCall Tool $0.0 $0.0 List Tool CategoriesList Tool Categories $0.0 $0.0 Describe ToolDescribe Tool $0.0 $0.0 Discover ToolsDiscover Tools $0.0 $0.0 Global VIN DecodeGlobal VIN Decode $0.0 $0.0 US dollars per call
Price per call for developer tools, cheapest first.

Data source: live tool catalog snapshot, fetched 2026-12-01.

Chart data as a table
ToolPrice per callCache-hit price
Usage Time Series$0.0$0.0
Per-Tool Usage Breakdown$0.0$0.0
Usage Summary$0.0$0.0
Call Tool$0.0$0.0
List Tool Categories$0.0$0.0
Describe Tool$0.0$0.0
Discover Tools$0.0$0.0
Global VIN Decode$0.0$0.0
ToolProviderPrice/callCache-hit
Usage Time Series$None$None
Per-Tool Usage Breakdown$None$None
Usage Summary$None$None
Call Tool$None$None
List Tool Categories$None$None
Describe Tool$None$None
Discover Tools$None$None
Global VIN Decode$None$None

Connect via MCP

How a tool call worksAn AI agent sends a tool call to the APIbase gateway. The gateway checks payment, calls the provider API, and returns the JSON result to the agent.Your agentAPIbase gatewayProvider API1. tool call2. paid call3. JSON result flows back to the agent
Diagram: the path of one tool call.

Data source: gateway design, no measured values.

$ curl -X POST https://apibase.pro/api/v1/tools/account.timeseries/call \
  -H "Content-Type: application/json" -d '{"params": {}}'

FAQ

Do I need a special language to create an MCP server?

No. The official SDKs cover Python and TypeScript, and the protocol does not depend on one language. Pick the language your team already runs. The current SDK list appears at https://modelcontextprotocol.io.

Does an MCP server need an API key?

Only if a tool calls an API that requires one. A local stdio server does not need a key of its own. Store any secret in an environment variable, not in source code.

How is an MCP server different from a REST API?

A REST API answers HTTP requests from any caller. An MCP server answers JSON-RPC requests from an MCP client, and it describes its tools so a model can choose them. A REST API often sits behind an MCP server as its backend.

Can an MCP server call paid APIs?

Yes. The tool function makes the upstream call, so the upstream provider charges for it. Check that provider's pricing before you give a model access. No public pricing is implied by this guide.

  1. STEP 1/2 Connect your MCP client
  2. STEP 2/2 Browse the full catalog

Written with AI assistance from APIbase's published documentation and public data; checked automatically against them. Corrections: https://apibase.pro/

Published: 2026-12-01Source: live apibase.pro catalog snapshot