Building LLM Tools with FastMCP

FastMCP is a powerful, minimalist framework for exposing Python functions as callable tools that can be integrated into AI agents, automation systems, or any machine-to-machine interface. In this post, you’ll learn how FastMCP works, how to define tools, and how to run them using the stdio transport — no HTTP server required.

🧠 What is FastMCP?

FastMCP (Machine-Callable Python) is designed to make your Python code accessible to language models and agents with minimal setup. It allows you to register tools — simple Python functions — that can be called over various transports.

It supports:

  • http – for web APIs
  • socket – for persistent connections
  • stdio – for standard input/output communication, ideal for CLI or subprocess use

🛠 Defining Tools

To create a callable tool, just decorate a function with @mcp.tool():

from fastmcp import FastMCP

mcp = FastMCP("mytools")

@mcp.tool()
def echo(text: str) -> str:
    return f"You said: {text}"

You can define as many tools as needed. Each tool becomes discoverable and invocable by agent runtimes that interface with FastMCP.

🚀 Running the Tool Server

Once your tools are defined, you launch the server using:

if __name__ == "__main__":
    mcp.run(transport='stdio')

This sets up a listener that communicates via standard input and output — ideal for scenarios where low-latency and no HTTP overhead are desired.

📦 Example Use Cases

FastMCP is transport-agnostic and extremely versatile. Some ideas for tools you might define:

  • Text processing (summarization, translation, formatting)
  • File operations (read/write/convert)
  • Database access (queries, metrics, aggregations)
  • External API wrappers (financial data, messaging, scheduling)

🧩 Why stdio?

Using stdio as a transport allows you to:

  • Integrate directly with AI models via subprocess
  • Avoid running a web server
  • Build lightweight, scriptable tools
  • Maintain full compatibility with sandboxed or serverless runtimes

📚 Explore Code Examples

Check out real-world examples and templates in the GitHub repository:

👉 Browse the FastMCP Archetypes on GitHub

✅ Summary

FastMCP makes it easy to turn your Python functions into machine-callable tools. With a simple decorator, multi-transport support, and a focus on speed and portability, it’s ideal for building modular, intelligent systems. Whether you’re automating workflows or enabling LLMs to call your logic, FastMCP is the bridge.

Ready to build? Start with the GitHub repo.