The Model Context Protocol, or MCP, is changing how large language models interact with data and tools.
Instead of treating the AI model like a black box, MCP gives it structured access to information and functions.
It’s like a USB-C port for AI, creating a standard way for models to communicate with servers that hold real-world data or perform useful tasks.
Fast MCP MCP is the easiest and fastest framework to build servers with Python. It hides all the complicated protocol details and lets you focus on your logic.
In this guide, you’ll learn what MCP is, how FastMCP works, and how to get your first MCP server up and running from scratch.
Table of Contents
What is MCP?
MCP is a standard protocol that allows language models to communicate with external systems in a secure and consistent manner. MCP is like an APIbut designed for large language models rather than humans.
An MCP server can perform three main functions:
It can expose data as resources (similar to accessing endpoints).
It can provide actions via tools (like post requests).
And it can define cues that guide how the model interacts with data or users.
For example, a resource may return a list of subjects, a tool may analyze those subjects, and a pointer may specify how the model summarizes them. By connecting LLM to such an MCP server, you empower it to consume your data and logic in real time.
Why use Fast MCP?
While you can create an MCP server using it Official SDKFast MCP takes things much further. It is a production-ready framework with enterprise validation, client libraries, testing tools, and automated API generation.
You can use FastMCP to build secure, scalable MCP applications that integrate with providers such as Google, GitHub, and Azure. It also supports deployment in the cloud or your own infrastructure.
Most importantly, the framework is extremely developer friendly. You can create a working MCP server in just a few lines of Python code.
Creating Your First MCP Server
Before starting the build, install FastMCP in your Python environment. You can use PIP or UV. The UV tool is recommended because it handles environments and dependencies efficiently.
uv pip install fastmcp
Once installed, you’re ready to write your first server.
Every MCP server starts FastMCP Class This class represents your application and manages your tools, resources, and pointers. Let’s start by creating a simple server that adds two numbers together.
Create a file named server.py and add the following code:
from fastmcp import FastMCP
mcp = FastMCP("Demo Server 🚀")
@mcp.tool
def add(a: int, b: int) -> int:
"""Add two numbers and return the result"""
return a + b
if __name__ == "__main__":
mcp.run()
That’s all you need. You have just created a fully working MCP server with a tool called add. When a client calls this tool, the server adds the two numbers and returns the result.
The server is running
To run your server locally, open your terminal and type:
fastmcp run server.py
This command starts the MCP server. You can also use HTTP or SSE Transport for web-based deployments. For example, to run your server over HTTP, use:
mcp.run(transport="http", host="127.0.0.1", port=8000, path="/mcp")
Once the server is running, clients can connect and make calls add From the Toll era.
Fast MCP tools are simple Python functions that you decorate with @mcp.tool. You can add as many as you want. Let’s add a multiplier tool next:
@mcp.tool
def multiply(a: float, b: float) -> float:
"""Multiply two numbers"""
return a * b
Now you can restart the server, and the clients will have access to both add And multiply tools
FastMCP automatically generates schemas based on your function signatures and documentation, making it easier for clients to understand your API.
Adding resources
Resources in MCP represent read-only data that clients can access. You can create static resources or dynamic templates that take parameters. For example, you can expose the version number or user profile.
@mcp.resource("config://version")
def get_version():
return "1.0.0"
@mcp.resource("user://{user_id}/profile")
def get_profile(user_id: int):
return {"name": f"User {user_id}", "status": "active"}
In this example, the first resource always returns the version number, while the second resource fetches the user profile based on the dynamically provided ID.
Using context in tools
Fast MCP allows you to access session context in any tool, resource or indicator. ctx: Context The parameter context gives you powerful capabilities like logging, LLM Samplingtracking progress, and accessing resources.
Here’s an example that shows how to use context:
from fastmcp import Context
@mcp.tool
async def summarize(uri: str, ctx: Context):
await ctx.info(f"Reading resource from {uri}")
data = await ctx.read_resource(uri)
summary = await ctx.sample(f"Summarize this: {data.content(:500)}")
return summary.text
This tool logs a message, reads a resource, and then asks the client’s language model to summarize it. Context makes your MCP tools better and more interactive.
Connecting with the MCP client
Once your server is up and running, you can connect to it fastmcp.Client The class client can communicate via STDIO, HTTP, or SSE, and even run in memory for testing.
Here is a simple example of how to connect and call your local server add Tool:
from fastmcp import Client
import asyncio
async def main():
async with Client("server.py") as client:
tools = await client.list_tools()
print("Available tools:", tools)
result = await client.call_tool("add", {"a": 5, "b": 7})
print("Result:", result.content(0).text)
asyncio.run(main())
You can also connect to multiple servers using a standard MCP configuration file, making it easy to build complex systems that interact with multiple services simultaneously.
Authentication and Security
When you move from development to production, validation becomes critical.
FastMCP has built-in support for enterprise-grade authentication providers such as Google, GitHub, Microsoft Azure, Auth0, and Verkos. You can enable OAUTH-based secure access with just a few lines of code:
from fastmcp.server.auth.providers.google import GoogleProvider
from fastmcp import FastMCP
auth = GoogleProvider(client_id="...", client_secret="...", base_url="https://myserver.com")
mcp = FastMCP("Secure Server", auth=auth)
Now only authenticated users can access your server. On the client side, you can connect using the OAUTH flow like this:
async with Client("https://secure-server.com/mcp", auth="oauth") as client:
result = await client.call_tool("protected_tool")
Fast MCP handles token, refresh, and error handling automatically.
Deploying Your MCP Server
You can deploy a Fast MCP server anywhere.
For testing, fastmcp run The command is sufficient. For production, you can deploy Fast MCP Cloudwhich provides instant HTTPS endpoints and built-in authentication.
If you prefer to self-host, use HTTP or SSE transport to serve your MCP endpoints from your own infrastructure. A simple deploy command might look like this:
mcp.run(transport="http", host="0.0.0.0", port=8080)
Once deployed, your MCP server is ready to connect to language models, web clients, or automation workflows.
Using MCP Server with LLM Application
Once you have your MCP server running, the next step is to connect it to a larger language model. This allows LLM to securely call your server functions, read resources, and perform actions as part of a conversation.
To integrate an LLM application, you first define your MCP configuration file. This file lists the available servers, their connection methods, and any authentication requirements.
Once configured, LLM can automatically discover your MCP tools and call them when needed.
For example, if your server exposes a add or summarize tool, the model can use them directly as if they were built-in capabilities. In a chat-based environment, when a user asks the model to perform a task such as “summarize the latest article”, LLM will call you summarize tool, process the result, and respond with output.
If you’re building a custom LLM application with OpenAI’s Helper API or a framework like LangChain, you can register your MCP server as an external tool. LLM then communicates with it via the MCP client library.
Here is a simple example:
from fastmcp import Client
from openai import OpenAI
import asyncio
async def main():
async with Client("http://localhost:8000/mcp") as client:
result = await client.call_tool("add", {"a": 10, "b": 5})
print("MCP Result:", result.content(0).text)
llm = OpenAI(api_key="YOUR_KEY")
response = llm.chat.completions.create(
model="gpt-4",
messages=(
{"role": "system", "content": "You are an AI assistant using MCP tools."},
{"role": "user", "content": f"The sum of 10 and 5 is {result.content(0).text}. Explain how MCP helps with this integration."}
)
)
print(response.choices(0).message.content)
asyncio.run(main())
In this setup, LLM can seamlessly integrate its logic with your server logic. It uses the MCP client to fetch data or perform computations and then incorporates the output into its conversation or workflow.
This approach allows you to create intelligent systems that go beyond static indicators. You can connect your LLM to real databases, APIs, or automation tools, turning it into an active agent that can read, write, and process real-world context.
The result
The Fast MCP model makes it easy to bring your data, APIs and tools into the AI world through context protocols. With just a few lines of Python, you can create powerful MCP servers that connect to language models, automate workflows, and securely handle real-world logic.
Whether you’re building a quick demo or an enterprise-grade system, FastMCP gives you the shortest path from idea to production. Install it today, start your first server, and discover how MCP can unlock the next level of AI integration.
If you want to learn more about general MCP concepts and how to build an MCP server with Python, I wrote another article about it that you can check out here.
Hope you enjoyed this article. Sign up for my free newsletter turingtalks.ai For more tutorials on AI. You can too Visit my website.