MCP Tutorial – Build Your First MCP Server
Step-by-step tutorial for building your first MCP server from scratch, with code examples in TypeScript and Python.
This tutorial walks you through building your first MCP server, covering the core concepts and implementation patterns you need to know.
Prerequisites
Before we start, ensure you have Node.js 18+ or Python 3.10+ installed, and basic familiarity with TypeScript or Python syntax.
The Three Building Blocks
Before writing code, it helps to know what an MCP server actually exposes. There are three primitives: Tools, Resources, and Prompts.
Part 1: TypeScript Server
Step 1: Set Up Your Project - Create a new directory and initialize a Node.js project.
mkdir my-mcp-server
cd my-mcp-server
npm init -y
npm install @modelcontextprotocol/sdk
Part 2: Python Server
If you prefer Python, the official SDK uses a decorator-based API.
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("my-server")
@mcp.tool()
def greet(name: str) -> str:
return "Hello, " + name + "!"
if __name__ == "__main__":
mcp.run()
Next Steps
From here, explore adding resources, prompts, and more complex tool implementations.
Join the Discussion
Code Snippets (0)
No code snippets shared yet. Be the first to contribute!