# Build an MCP server with FastMCP

> The Model Context Protocol lets AI assistants call your own tools. Here is how to build a small MCP server in Python with FastMCP, connect it to Claude, and keep it safe.

The **Model Context Protocol (MCP)** is an open standard that lets an AI assistant call tools you write, such as reading a file, listing processes or querying a database. An **MCP server** is a small program that describes those tools and runs them when the model asks. [F.R.I.D.A.Y](/work/friday-voice-ai/) uses a custom MCP server to control a Windows desktop.

## Install

```bash
pip install fastmcp
```

## A first server

```python
# server.py
from pathlib import Path
from fastmcp import FastMCP

mcp = FastMCP("Desk tools")

NOTES = Path.home() / "Notes"

@mcp.tool()
def list_notes() -> list[str]:
    """List the note files in the Notes folder."""
    return sorted(p.name for p in NOTES.glob("*.md"))

@mcp.tool()
def read_note(name: str) -> str:
    """Read one note by file name, for example 'ideas.md'."""
    path = (NOTES / name).resolve()
    if path.parent != NOTES.resolve():
        raise ValueError("Only files directly inside the Notes folder can be read")
    return path.read_text(encoding="utf-8")

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

FastMCP reads the **type hints and docstrings** to tell the model what each tool does and what arguments it takes, so write them clearly: they are the model's instructions.

## Connect it to Claude Desktop

Add the server to Claude Desktop's `claude_desktop_config.json` and restart the app:

```json
{
  "mcpServers": {
    "desk-tools": {
      "command": "python",
      "args": ["C:/path/to/server.py"]
    }
  }
}
```

By default `mcp.run()` talks over standard input and output, which is how desktop apps launch local servers.

## Keep it safe

An MCP tool runs with your permissions, so treat every model request as untrusted input:

- **Allowlist, do not blocklist.** Only expose specific folders, commands or apps.
- **Validate paths** as in `read_note`, so `../` cannot escape the folder.
- **Prefer read-only tools.** Make destructive actions separate tools that ask for confirmation.
- **Log every call** so you can see what the model did.

## Going further

F.R.I.D.A.Y adds tools for processes, terminal commands and keyboard macros, pairs the server with LiveKit for real-time voice, and stores long-term memory in ChromaDB so the assistant remembers past sessions.
