9Model Context Protocol

Project setup

5 min read915 words

Enough theory. The next few lessons build a working CLI chatbot with a custom MCP server exposing document-management tools and a matching MCP client that Claude talks to. This lesson gets the starter project downloaded, installed, and running so you have a clean baseline to add MCP features on top of.

What you're building

The project is a command-line chatbot with two halves:

  • The MCP client — handles user input in the terminal, talks to Claude, and invokes tools on the MCP server via the MCP protocol.
  • The MCP server — a custom server that exposes tools for managing an in-memory collection of documents. Initially just two tools: read a document by ID, and edit a document using a find-and-replace operation.

The documents live in a plain Python dict. No database, no file system, nothing to set up beyond the project itself. This keeps the focus squarely on the MCP mechanics — connecting, discovering tools, invoking them, getting results back — without dragging in infrastructure concerns.

A note on the unusual architecture

In real projects you normally implement either an MCP client or an MCP server — not both. Production patterns look more like:

  • You build an MCP server to expose your team's internal service to other developers and applications.
  • You build an MCP client to connect your application to existing MCP servers (GitHub, filesystems, internal APIs, etc.).

We're building both halves here for educational reasons. Watching the two sides communicate is by far the fastest way to build intuition about what each piece is responsible for, what messages flow where, and what the MCP SDK abstracts away. Once you've done this once, you'll immediately recognise which half of the picture you're working with in any real project.

Project structure

Download cli_project.zip from the lesson resources and extract it somewhere convenient. Open the folder in your editor.

You'll see something like:

cli_project/
├── .env.example
├── README.md
├── pyproject.toml        # or requirements.txt
├── main.py               # app entry point
├── mcp_client.py         # MCP client stub
└── mcp_server.py         # MCP server stub

Three files matter:

  • main.py — the entry point. Runs the chat loop that takes input from the terminal, sends it to Claude, and prints the response.
  • mcp_client.py — where the MCP client logic lives. Initially a stub; you'll fill it in over the next few lessons.
  • mcp_server.py — where the MCP server lives. Also initially a stub; you'll add the tool definitions as you go.

There's also a cli_project_COMPLETE.zip available if you want to see the final shape before starting — treat it as an answer key, not a shortcut.

Add your API key

Copy .env.example to .env and fill in your Anthropic key:

ANTHROPIC_API_KEY="sk-ant-..."

Same pattern you've been using since Module 3. The project already knows how to read this file via python-dotenv.

Install dependencies

The project uses UV (recommended) or regular pip.

With UV:

uv sync

UV will create a virtual environment and install everything from pyproject.toml in one go. This is the fastest option and handles the MCP SDK's install cleanly.

With pip:

python -m venv .venv
source .venv/bin/activate  # or .venv\Scripts\activate on Windows
pip install -r requirements.txt

Slightly more manual, same end state.

Verify the baseline runs

From the project directory:

# with UV
uv run main.py

# or with standard Python and the venv activated
python main.py

You should see a chat prompt appear in the terminal. Type a quick test question:

> What's 1 + 1?

You should get a fast response from Claude. Nothing MCP-related is wired up yet — at this stage the chatbot is just a plain terminal-based Claude client with no tools. Confirming it runs means your API key is loaded, the dependencies are installed correctly, and the chat loop is working.

If it doesn't run, the most common failure is a missing or invalid ANTHROPIC_API_KEY. Check the .env file, make sure the file is at the project root, and confirm there are no typos in the variable name.

What's next

With the baseline running, the next lesson starts building the MCP server. You'll use the FastMCP Python SDK to define the document read and edit tools, then wire the client to discover and call them. From this clean starting point, each lesson adds one identifiable piece of MCP functionality — tools, the server inspector, the client wiring, resources, and prompts — so you can watch the chatbot grow from "talks to Claude" to "talks to Claude with a real MCP-driven tool layer" step by step.

Key Takeaways

  • 1The project is a CLI chatbot with two halves: an MCP client that handles user input and talks to Claude, and a custom MCP server that exposes document-management tools.
  • 2In real projects you normally build one side of an MCP connection, not both — we are building both here purely to see the full architecture end to end.
  • 3Documents are stored in a plain Python dict so the lessons can focus on MCP mechanics without infrastructure overhead.
  • 4Download cli_project.zip, add your Anthropic API key to .env, install dependencies via UV or pip, and run main.py to verify the baseline chat loop works before adding MCP features.
  • 5The COMPLETE zip is available as an answer key if you want to see the final shape before starting — treat it as a reference, not a shortcut.