News / Learn / MCP & tool integrations
How do you build your first MCP server?
You'll be able to build a small MCP server that exposes a tool an AI app can call.
In plain English
An MCP server is a small program that offers tools, data, or prompts to an AI app. The app connects to the server and reads a list of what it can do. When the model needs something, it asks the server to run a tool and gets a result back.
Why it matters
Building an MCP server lets you connect your product's own data and actions to any MCP-aware AI client without writing custom glue for each one. It keeps the integration in one place, so you can change or secure it without touching every app that uses it. Starting small with one tool teaches you the parts that carry over to any larger server.
How it works
An MCP server does three jobs: it announces what it offers, it accepts requests, and it returns results. Each tool has a name, a plain-language description, and an input schema that describes its arguments. The description matters because the model reads it to decide when to use the tool.
The transport is how the client and server exchange messages. The common local option is stdio, where the client starts your server as a child process and talks to it through standard input and output. Remote servers use HTTP-based transports instead. Pick the transport your client supports, and keep your tool logic separate from the transport code so you can switch later.
When the model decides to call a tool, the client sends a request with the tool name and arguments. Your server validates the arguments against the schema, runs the function, and returns content, usually text. If something fails, return a clear error message the model can read, rather than crashing the process.
Most teams use an official MCP SDK for their language, since it handles the message format and handshake. Your job is to register tools, write their handlers, and run the server. Test each tool directly before you connect it to a model, so you know bugs come from your code and not from the prompt.
A concrete example
A minimal server in Python using the official SDK's FastMCP helper. It exposes one tool that adds two numbers. Install the SDK first, then run this file.
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("demo-server")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two integers and return the sum."""
return a + b
if __name__ == "__main__":
mcp.run() # defaults to stdio transportA short sketch to show the idea. Check the official docs of the tool you use.
What goes wrong
- Vague tool descriptions Write the docstring as if you are explaining the tool to a new teammate. Say what it does, what inputs mean, and when to use it. The model relies on this text to choose tools.
- Writing to stdout in stdio servers On stdio transport, stdout carries protocol messages. Send logs to stderr or a file. A stray print statement can corrupt the connection.
- Trusting tool arguments blindly Validate inputs and limit what the tool can touch, such as file paths or database queries. The model can pass unexpected values, and the server must treat them as untrusted.
- Testing only through the model Call each tool function directly with normal and bad inputs first. Then connect the server to a client and check how the model uses it.
Going deeper
Learn how resources and prompts differ from tools in MCP. Then study how to handle authentication for remote servers and how to log tool calls for debugging.
FAQ
Do I need to write the protocol myself?
No. Use an official MCP SDK for your language. It handles message formats and the startup handshake, so you focus on your tool logic.
What is the difference between a tool and a resource?
A tool is an action the model asks the server to perform, with arguments. A resource is data the client can read by identifier. Start with tools, since they cover most product integrations.
Can one server offer many tools?
Yes. Register as many tools as you need on one server. Keep each tool focused on one clear task so the model can choose correctly.
How do I know my server works before using a model?
Call your tool functions directly in a test script with normal and invalid inputs. Confirm the outputs and error messages are what you expect.
Written with AI by CapyLaunch. Spotted a mistake? Email hello@capylaunch.com.