Turn your rent agent into an MCP server

Ask rent questions inside Claude or Cursor instead of running a script. Wrap the same three functions in an MCP server and you're done.

In the last post we built an agent that answers rent questions from Zillow's free data. It works, but you have to open a terminal and run a script every time you have a question. Most of us already have Claude or Cursor open all day.

This post moves the same three tools into an MCP server. MCP (Model Context Protocol) is the standard way for apps like Claude Desktop, Claude Code and Cursor to call your code. Add the server once, and you can ask "where are Florida rents falling?" in the chat you already use.

Why a server instead of a script

There's a trade. With the agent script, you wrote the system prompt. With an MCP server, the app's own model decides when and how to call your tools. So the instructions have to live in the tools themselves: clear descriptions, and outputs that say exactly what each field means.

Writing tools for a model you don't control

A few habits make the difference between Claude using your tools well and guessing:

  • Say what the input looks like. "state is a two-letter code, e.g. FL" saves a failed call.
  • Return dates with every number. Each result carries as_of, so the answer always names the month.
  • Keep each tool to one job. Three small tools beat one tool with a dozen options; the model picks them more reliably.

The server

The tools are the same pandas functions as before. The new part is three lines of setup and a typed return value. The SDK turns that type into a schema, so Claude knows exactly which fields come back:

from typing import TypedDict
from mcp.server.mcpserver import MCPServer
 
mcp = MCPServer("rents")
 
class Overview(TypedDict):
    as_of: str
    rising: int
    falling: int
    at_record_high: int
    median_yoy_pct: float
 
@mcp.tool()
def state_overview(state: str) -> Overview:
    """How many of a state's counties are rising, falling or at a record high."""

rank_counties and county_detail follow the same pattern. Zillow's file downloads once, on the first question, and stays in memory while the server runs.

Connect it

The file ends with mcp.run(), which talks over stdin and stdout. Claude Code starts the script for you:

pip install -r requirements.txt
claude mcp add rents -- python /full/path/to/rent_mcp.py

Claude Desktop and Cursor take the same command in their MCP settings. In Claude Desktop, open Settings, then Developer, then Edit Config, add the server under mcpServers, and restart the app. The rent tools then show up in every new chat.

Test it without an API key

The MCP client in the SDK can connect to the server in-process, so the tests use the real protocol with fixture data and no network:

@pytest.mark.anyio
async def test_tools_answer_over_mcp():
    async with Client(rent_mcp.mcp) as client:
        overview = await client.call_tool("state_overview", {"state": "FL"})
        ranked = await client.call_tool("rank_counties", {"state": "FL", "sort_by": "vs_peak_pct"})
    assert overview.structured_content["falling"] == 1
    assert ranked.structured_content["result"][0]["county"] == "Lee County"

Ask it in Claude Code

We asked Claude Code "Where are Florida rents falling, and is there a pattern?" It found the rents tools on its own, called state_overview, then rank_counties twice. Part of its answer:

Southwest Florida Gulf Coast is the weak spot. Lee, Charlotte, Manatee, Sarasota and Collier are all 4–9% below their peaks. Those peaks came in 2023, between January and December, and rents never recovered.

Same finding as the agent, with no agent code. It also kept its own guess separate from the data. It said the hurricane and new-supply explanations were inference on its part, because the tools don't cover either.

Run it yourself

The full project (server, tests, pinned requirements) is in our public repo. Run pytest, add it with the command above, and ask about your state.

Before you use it

  • It reads asking rents on new listings, so use it to price your next lease, then check a few comps near your property.
  • Next: package this as a Claude skill, so Claude also knows how to read the numbers, not just fetch them.