Skip to main content
This guide will walk you through creating a simple MCP server with FastMCP. You’ll learn how to define tools, run your server, and test it with the CLI.

Build your first server

1

Create a new file

Create a new TypeScript file for your server:
2

Import FastMCP and define your server

Import FastMCP and create a new server instance:
server.ts
The server configuration accepts:
  • name - Your server’s name (shown to clients)
  • version - Semantic version number
  • Optional settings for authentication, logging, health checks, and more
3

Add a tool

Tools are executable functions that clients and LLMs can call. Let’s add a simple addition tool:
server.ts
What’s happening here:
  • name - Unique identifier for the tool
  • description - Tells LLMs when to use this tool
  • parameters - Zod schema defining expected inputs (FastMCP also supports ArkType and Valibot)
  • execute - Async function that performs the action and returns a string result
4

Start the server

Add the start command to run your server:
server.ts
The stdio transport is perfect for local development and integrates with MCP clients like Claude Desktop.

Complete example

Here’s the complete server code:
server.ts

Test your server

FastMCP includes a CLI for testing servers without setting up a full MCP client.
Run your server with the interactive CLI:
You’ll see a prompt where you can test calling your tool:
Select “Call a tool”, choose add, and enter parameters:

Use MCP Inspector

For a visual debugging experience, use the MCP Inspector:
This opens a web UI where you can:
  • Browse available tools, resources, and prompts
  • Test tool execution with a visual interface
  • Inspect request/response payloads
  • Debug errors in real-time

Add more features

Add a resource

Resources make data available to clients:

Add a prompt

Prompts define reusable templates for LLM interactions:

Add streaming output

For long-running operations, stream partial results:

Use different schema libraries

FastMCP supports multiple schema validation libraries:

Deploy to production

For production deployments, use HTTP streaming:
Your server will be available at http://localhost:8080/mcp.
FastMCP also supports edge runtimes like Cloudflare Workers. See the deployment guide for details.

Next steps

Tools

Learn about tool parameters, error handling, and progress reporting

Resources

Discover how to expose files, images, and dynamic data

Prompts

Create reusable prompt templates with auto-completion

Authentication

Secure your server with OAuth 2.1 or custom authentication