URL: https://gofastmcp.com/getting-started/quickstart
Title: Quickstart - FastMCP

Documentation Index
Fetch the complete documentation index at:
/llms.txt
Use this file to discover all available pages before exploring further.
Skip to main content
Meet
Prefect Horizon
, the enterprise MCP gateway built by the team behind FastMCP
FastMCP
home page
v3
Prefect Horizon
PrefectHQ/fastmcp
25,596
PrefectHQ/fastmcp
25,596
Search...
Navigation
Get Started
Quickstart
Search the docs...
Ctrl
K
Documentation
Get Started
Welcome!
Installation
Quickstart
Servers
Overview
Core Components
Working with Tools
MCP Providers
Interactivity
Extensibility
Auth
Deployment
Apps
Overview
Quickstart
NEW
FastMCPApp
NEW
Interactive Tools
NEW
Generative UI
NEW
Custom HTML
Reference
Clients
Overview
Client-Only Package
Transports
fastmcp-remote
Operations
UPDATED
Authentication
UPDATED
Integrations
Auth
Web Frameworks
AI Assistants
AI SDKs
MCP.json
More
Settings
CLI
Upgrading
Development
What's New
FAQ
On this page
Create a FastMCP Server
Add a Tool
Run the Server
Using the FastMCP CLI
Call Your Server
Give Your Tool a UI
Deploy to Prefect Horizon
Get Started
Quickstart
Copy page
Copy page
Welcome! This guide will help you quickly set up FastMCP, run your first MCP server, give it a visual UI, and deploy it to Prefect Horizon.
If you haven’t already installed FastMCP, follow the
installation instructions
.
​
Create a FastMCP Server
A FastMCP server is a collection of tools, resources, and other MCP components. To create a server, start by instantiating the
FastMCP
class.
Create a new file called
my_server.py
and add the following code:
my_server.py
from
fastmcp
import
FastMCP
mcp
=
FastMCP
(
"
My MCP Server
"
)
That’s it! You’ve created a FastMCP server, albeit a very boring one. Let’s add a tool to make it more interesting.
​
Add a Tool
To add a tool that returns a simple greeting, write a function and decorate it with
@mcp.tool
to register it with the server:
my_server.py
from
fastmcp
import
FastMCP
mcp
=
FastMCP
(
"
My MCP Server
"
)
@
mcp
.
tool
def
greet
(
name
:
str
)
->
str
:
return
f
"Hello,
{
name
}
!"
​
Run the Server
The simplest way to run your FastMCP server is to call its
run()
method. You can choose between different transports, like
stdio
for local servers, or
http
for remote access:
my_server.py (stdio)
my_server.py (HTTP)
from
fastmcp
import
FastMCP
mcp
=
FastMCP
(
"
My MCP Server
"
)
@
mcp
.
tool
def
greet
(
name
:
str
)
->
str
:
return
f
"Hello,
{
name
}
!"
if
__name__
==
"
__main__
"
:
mcp
.
run
()
This lets us run the server with
python my_server.py
. The stdio transport is the traditional way to connect MCP servers to clients, while the HTTP transport enables remote connections.
Why do we need the
if __name__ == "__main__":
block?
The
__main__
block is recommended for consistency and compatibility, ensuring your server works with all MCP clients that execute your server file as a script. Users who will exclusively run their server with the FastMCP CLI can omit it, as the CLI imports the server object directly.
​
Using the FastMCP CLI
You can also use the
fastmcp run
command to start your server. Note that the FastMCP CLI
does not
execute the
__main__
block of your server file. Instead, it imports your server object and runs it with whatever transport and options you provide.
For example, to run this server with the default stdio transport (no matter how you called
mcp.run()
), you can use the following command:
fastmcp
run
my_server.py:mcp
To run this server with the HTTP transport, you can use the following command:
fastmcp
run
my_server.py:mcp
--transport
http
--port
8000
​
Call Your Server
Once your server is running with HTTP transport, you can connect to it with a FastMCP client or any LLM client that supports the MCP protocol:
my_client.py
import
asyncio
from
fastmcp
import
Client
client
=
Client
(
"
http://localhost:8000/mcp
"
)
async
def
call_tool
(
name
:
str
):
async
with
client
:
result
=
await
client
.
call_tool
(
"
greet
"
,
{
"
name
"
:
name
})
print
(
result
)
asyncio
.
run
(
call_tool
(
"
Ford
"
))
Note that:
FastMCP clients are asynchronous, so we need to use
asyncio.run
to run the client
We must enter a client context (
async with client:
) before using the client
You can make multiple client calls within the same context
​
Give Your Tool a UI
Tools normally return text, but any tool can return an interactive UI instead. Add
app=True
to your tool decorator and return a
Prefab
component — the host renders it as a chart, table, form, or any other visual element right in the conversation. This requires the
apps
extra (
pip install "fastmcp[apps]"
).
The
app=True
flag tells FastMCP to wire up the renderer and protocol metadata automatically. The tool still works like any other MCP tool — it receives arguments and returns a result — but the result is a component tree that the host displays visually instead of as plain text.
my_server.py
from
prefab_ui
.
app
import
PrefabApp
from
prefab_ui
.
components
import
Column
,
Heading
,
Text
,
Badge
,
Row
from
fastmcp
import
FastMCP
mcp
=
FastMCP
(
"
My MCP Server
"
)
@
mcp
.
tool
(
app
=
True
)
def
greet
(
name
:
str
)
->
PrefabApp
:
"""
Greet someone with a visual card.
"""
with
Column
(
gap
=
4
,
css_class
=
"
p-6
"
)
as
view
:
Heading
(
f
"Hello,
{
name
}
!"
)
with
Row
(
gap
=
2
,
align
=
"
center
"
):
Text
(
"
Status
"
)
Badge
(
"
Greeted
"
,
variant
=
"
success
"
)
return
PrefabApp
(
view
=
view
)
You can preview app tools locally with
fastmcp dev apps my_server.py
— no MCP host required. See the
Apps overview
for the full guide, including state management, forms, charts, and server-connected interactivity.
​
Deploy to Prefect Horizon
Prefect Horizon
is the enterprise MCP platform built by the FastMCP team at
Prefect
. It provides managed hosting, authentication, access control, and observability for MCP servers.
Horizon is
free for personal projects
and offers enterprise governance for teams.
To deploy your server, you’ll need a
GitHub account
. Once you have one, you can deploy your server in three steps:
Push your
my_server.py
file to a GitHub repository
Sign in to
Prefect Horizon
with your GitHub account
Create a new project from your repository and enter
my_server.py:mcp
as the server entrypoint
That’s it! Horizon will build and deploy your server, making it available at a URL like
https://your-project.fastmcp.app/mcp
. You can chat with it to test its functionality, or connect to it from any LLM client that supports the MCP protocol.
For more details, see the
Prefect Horizon guide
.
Installation
Previous
The FastMCP Server
Next
Ctrl
+I
discord
github
website
x
Powered by
This documentation is built and hosted on Mintlify, a developer documentation platform
Assistant
Responses are generated using AI and may contain mistakes.
\n\n
\n
\n \n
\n
