DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Automatic Code Transformation With OpenRewrite
  • A Complete Guide to Modern AI Developer Tools
  • Build a Local AI-Powered Document Summarization Tool
  • Build an AI Browser Agent With LLMs, Playwright, Browser Use

Trending

  • Mastering Advanced Traffic Management in Multi-Cloud Kubernetes: Scaling With Multiple Istio Ingress Gateways
  • AI's Dilemma: When to Retrain and When to Unlearn?
  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Cookies Revisited: A Networking Solution for Third-Party Cookies
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Building a Simple Todo App With Model Context Protocol (MCP)

Building a Simple Todo App With Model Context Protocol (MCP)

MCP is an open standard that connects AI models, apps, and data sources, enabling secure and easy integrations for AI-driven tools and workflows.

By 
Suleiman Dibirov user avatar
Suleiman Dibirov
DZone Core CORE ·
Apr. 28, 25 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
1.9K Views

Join the DZone community and get the full member experience.

Join For Free

What Is MCP?

The Model Context Protocol (MCP) is an open protocol that standardizes how applications, tools, and AI models provide and access context. Think of MCP as the “USB-C port for AI applications”—just as USB-C lets you connect all sorts of devices with a single standard, MCP lets you connect AI models, desktop apps, and tools to a wide variety of data sources and capabilities in a consistent way.

MCP is especially useful for building agents and complex workflows on top of large language models (LLMs), making it easy to integrate your own data and tools into AI-powered environments.

Why MCP?

  • Plug-and-play integrations: Connect your code, data, and tools to any MCP-compatible client (like Claude Desktop, IDEs, or custom AI apps).
  • Standardized discovery: Expose your functions, data, and prompts in a way that can be automatically discovered and described.
  • Security and control: Users retain control over what data and actions are shared or executed.

For more, see the official introduction.

MCP Architecture: How Does It Work?

MCP follows a client-server architecture:

  • MCP hosts: Applications like Claude Desktop or IDEs that want to access data and tools via MCP.
  • MCP servers: Lightweight programs (like the Todo app in this article) that expose specific capabilities through MCP.
  • Local/remote data sources: The actual data or services your server connects to.

A host can connect to multiple MCP servers, each exposing different resources, tools, or prompts.

What Can You Expose With MCP?

MCP is flexible and supports several item types:

  • Resources: Data endpoints that provide access to information (e.g., a list of todos, a file system, a database table).
  • Tools: Functions or actions that modify data or trigger operations (e.g., add a todo, send an email).
  • Prompts: Templated messages and workflows for users or models.
  • Sampling, roots, and more: For advanced workflows and integrations.

This article focuses on the two most common and fundamental types: resources and tools.
Once you’re comfortable with these, you can explore prompts and other advanced features in the MCP documentation.

Example: Todo MCP Server in Python

Let’s see how this works in practice with a simple todo application, implemented as an MCP server.

1. Defining Resources and Tools

In the example repo, server.py uses the mcp Python package to expose a todo list as both resources and tools:

Python
 
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("ToDo")

items = []


@mcp.resource("todo://list")
def list_todo():
    """
    List all TODO items.
    """
    return items


@mcp.resource("todo://view/{item_idx}")
def view_todo(item_idx: int):
    """
    View a TODO item.
    """

    if item_idx < 0 or item_idx >= len(items):
        return "Item not found"
    return items[item_idx]


@mcp.tool()
def add_todo(value: str):
    """
    Add a TODO item.
    """

    items.append(value)
    return f"Added TODO item: '{value}' at index '{len(items) - 1}'"


@mcp.tool()
def remove_todo(item_idx: int):
    """
    Remove a TODO item.
    """

    if item_idx < 0 or item_idx >= len(items):
        return "Item not found"
    removed_item = items.pop(item_idx)

    return f"Removed TODO item: '{removed_item}' from index '{item_idx}'"


@mcp.tool()
def clear_todo():
    """
    Clear all TODO items.
    """

    items.clear()
    return "Cleared all TODO items"


def main() -> None:
    """Run the MCP server."""
    mcp.run()


if __name__ == "__main__":
    main()


  • Resources (with @mcp.resource) are endpoints for data retrieval (e.g., listing or viewing todos).
  • Tools (with @mcp.tool) are actions that can be invoked (e.g., adding or removing todos).

2. Running the MCP Server

You can run the server locally or in Docker. The server will register its resources and tools so that any MCP-compatible client can discover and use them.

Local Setup

1. Clone the repository:

  • git clone https://github.com/idsulik/todo-mcp-server.git 
  • cd todo-mcp-server

2. Install dependencies:

  • uv sync

3. Start the server:

  • mcp dev server.py

This starts the server and opens the MCP Inspector for interactive testing. The output should look something like this:

Shell
 
Starting MCP inspector...
Proxy server listening on port 6277
MCP Inspector is up and running at http://127.0.0.1:6274


Now, you can open the link http://127.0.0.1:6274 and start interacting with the server.

First of all, you need to click on the connect button:
Click the connect button

After you can open the "Tools" tab, click on the "List Tools" button, select the "add_todo", paste some content, and click on the "Run Tool":

Click on Run tool

Now you can open the "Resources" tab, click on the "List Resources" button, and see the todo item:

See the to-do item

Or, click on the "List Templates", select the "view_todo", enter the item's index(it's 0) to see the specific item:

Click on List templates

See the specific item

Registering With a Client

To make your server available to an MCP client (like Claude Desktop), run:

Plain Text
 
mcp install server.py --name "Todo MCP"


If you prefer to add the server manually to your MCP configuration, you can add the following JSON to your Claude:

Desktop configuration file. This is typically located at:

  • ~/.claude-desktop/claude_desktop_config.json on Mac/Linux
  • C:\Users\YourUsername\AppData\Roaming\Claude\claude_desktop_config.json on Windows)
JSON
 
{

  "mcpServers": {
    "todo": {
      "command": "uv",
      "args": [
        "run",
        "--with",
        "mcp[cli]",
        "mcp",
        "run",
        "/path/to/your/server.py"
      ]
    }
  }
}


Replace /path/to/your/server.py with the absolute path to your server.py file. Make sure to use absolute paths, not relative paths.

Using Docker

You can also run this MCP server using Docker without installing anything locally. Add the following to your Claude Desktop configuration:

JSON
 
{
  "mcpServers": {
    "todo": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "idsulik/todo-mcp-server"
      ]
    }
  }
}


Restart your Claude Desktop to see available MCP tools:
Available MCP toolsAvailable MCP tools

Start interacting with the MCP server by asking Claude to add an item to the todo list, and allow it to use the integration:
Allow
Interact with MCP server

Why Use MCP?

  • No more custom APIs: Expose your Python logic with a few decorators.
  • AI-ready: MCP is designed for AI models and agents to discover and use your tools.
  • Rapid prototyping: Build and test new tools quickly, then connect them to any MCP-enabled client.
  • Security: Users must explicitly consent to data access and tool execution, as recommended by the protocol.

Conclusion

MCP is a powerful new protocol for making your Python code accessible to the next generation of AI-driven tools and applications. With just a few lines of code, you can expose your business logic, data, or automation scripts to any compatible client.

The Todo MCP Server is a minimal but complete example — clone it, run it, and start building your own MCP-powered tools today!

Learn more:

  • Model Context Protocol
  • Example Repo: todo-mcp-server
AI Tool app

Opinions expressed by DZone contributors are their own.

Related

  • Automatic Code Transformation With OpenRewrite
  • A Complete Guide to Modern AI Developer Tools
  • Build a Local AI-Powered Document Summarization Tool
  • Build an AI Browser Agent With LLMs, Playwright, Browser Use

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: