CloudCodeTree LogoCloudCodeTree
AI NewsTutorialsAbout
CloudCodeTree Logo
CloudCodeTree
  • AI News
  • Tutorials
  • About
← Back to AI News
Build Your First MCP Server: Tools, Resources, and Prompts in 30 Lines of Python

Photo: Daniil Komov / Pexels

Build Your First MCP Server: Tools, Resources, and Prompts in 30 Lines of Python

Chris Harper

2 min read

Jul 28, 2026 · 20:12 UTC

AI
Tutorial
MCP
Agents

FastMCP turns any Python function into a Claude-callable tool, resource, or prompt in under 30 lines — and Anthropic's free Intro to MCP course walks you through all three primitives.

What you'll be able to do after this:

  • Write and run a working MCP server that exposes tools to Claude Desktop or Cursor
  • Understand when to use a tool (action), resource (read-only data), or prompt (template) — and why the distinction matters at runtime
  • Test your server locally with Claude Desktop before deploying it anywhere

The three MCP primitives

FastMCP (the official Python SDK's high-level API) gives you three decorator types:

DecoratorWhat it exposesWhen to use it
@mcp.tool()Callable action with argumentsAPI calls, DB queries, computations
@mcp.resource()Read-only URI-addressable dataConfig, file content, live status
@mcp.prompt()Parameterised templateSlash commands the host surfaces

Quickstart (~25 lines)

pip install mcp fastmcp httpx
import httpx
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("weather-server")

@mcp.tool()
async def get_weather(city: str) -> str:
    """Return current weather for a city."""
    r = await httpx.AsyncClient().get(f"https://wttr.in/{city}?format=3")
    return r.text

@mcp.resource("config://server-info")
def server_info() -> str:
    """Return server metadata."""
    return "weather-server v0.1 — powered by wttr.in"

@mcp.prompt()
def weather_report(city: str) -> str:
    """Slash-command template: /weather-report <city>."""
    return f"Give a brief weather summary for {city} right now."

if __name__ == "__main__":
    mcp.run()

Add to Claude Desktop (Settings → MCP Servers → Add):

{
  "mcpServers": {
    "weather": {
      "command": "python",
      "args": ["/path/to/weather_server.py"]
    }
  }
}

Restart Claude Desktop. Ask: "What's the weather in Tokyo?" — Claude calls get_weather and returns a live answer.

Next step

Anthropic's free Introduction to Model Context Protocol course on Skilljar covers the full spec (tools, resources, prompts, authentication, and sampling), includes hands-on exercises, and ends with a certificate. No cost, only a Skilljar account required. For production patterns — streaming, auth, OpenTelemetry, and multi-provider setups — the FastMCP docs are the reference.

Sources: Introduction to Model Context Protocol — Anthropic Courses · FastMCP documentation — gofastmcp.com · Building a Simple MCP Server in Python — MachineLearningMastery · MCP Specification — modelcontextprotocol.io