Skip to main content
This guide shows how to build a minimal MCP (Model Context Protocol) server using the Python SDK (FastMCP). It explains the three core MCP building blocks — resources, tools, and prompts — then demonstrates a compact, runnable server example and the available runtime modes and transports. Keywords: MCP server, Model Context Protocol, FastMCP, resources, tools, prompts, Python SDK, async, stateless, stateful

MCP core concepts

MCP servers expose three coordinated layers:
  • Resources: read-oriented data endpoints or accessors (e.g., airports, flight statuses, seat maps, weather, bookings, gate info, policies, loyalty programs).
  • Tools: actionable functions that modify or query systems (e.g., search_flights, get_flight_details, create_booking, check_in, select_seat, add_baggage).
  • Prompts: developer-authored templates that guide model behavior for tasks like finding a best flight, optimizing for budget, or handling disruptions.
Once you determine the desired behavior and capabilities, implement the MCP server using the SDK and the MCP specification/SDK docs. For SDK reference and implementation details, see the FastMCP docs: /docs/mcp/fastmcp (or your project’s documentation location).
An infographic with three columns labeled "Resources," "Tools," and "Prompts," listing various flight- and booking-related items (like airports, search_flights, create_booking, and plan_multi_city) alongside small icons. It looks like a UI or API feature map for airline/travel services.

Implementation approach (high level)

  1. Import the FastMCP library and create an MCP server instance.
  2. Define resources with @mcp.resource(...) (async functions that return typed data).
  3. Define tools with @mcp.tool() (async functions performing actions).
  4. Define prompts with @mcp.prompt("name") (string- or template-returning async functions).
  5. Run the server with your chosen transport: stdio, http, or streamable-http. Choose stateless_http=True for stateless HTTP mode.
Below is a minimal, practical example using the Python FastMCP SDK. The example demonstrates a resource, a tool, and a prompt, plus how to run the server locally. Example: a minimal MCP server (Python)
Note that:
  • Resources and tools are standard async functions decorated with @mcp.resource(...) and @mcp.tool() respectively.
  • Prompts are defined by developers and decorated with @mcp.prompt(name) so the AI assistant has reliable templates to call.
Choose resource and tool interfaces that match your backend systems (databases, caches, third-party APIs). Keep resource responses stable and typed so callers can rely on consistent schemas.

Server modes: stateful vs stateless

  • Stateful server (default): session state is maintained across requests and model conversations.
  • Stateless server: no session persistence. Use for simple HTTP request/response patterns or horizontally scalable APIs. Create with stateless_http=True.
Example:

Run-time transport options

Choose the transport that fits your deployment and client integration needs: Run examples:
Streamable HTTP is useful when you want to deliver incremental updates (for example, stepwise flight search results or streaming AI responses) to clients.

Best practices and next steps

  • Design resource schemas and tool interfaces to be stable and typed — this reduces runtime errors and simplifies client integrations.
  • Keep prompts concise but structured, making it easier for models to follow multi-step instructions.
  • For production, add monitoring, metrics, and authentication on HTTP transports.
  • Prototype locally with stdio for quick iteration, then deploy with an HTTP transport and stateless mode if you require horizontal scaling.
References and further reading Try implementing this example in a lab or sandbox environment, then extend resources, tools, and prompts to match your backend systems and product requirements.

Watch Video