,

Building an MCP Server in Python: Scraping Google Reviews

Building an MCP Server in Python

In my last post, Connecting Open WebUI to MCP Servers, we connected our local AI to existing MCP servers and saw the power of the protocol. But the real competitive advantage lies in building your own MCP servers — custom tools that wire your AI directly to your systems, your data, your workflows.

This is the final post in a four-part series. We’ve built the same MCP server in Go, JavaScript, and C#. Now we’re finishing with Python — the language that makes building MCP servers feel almost too easy.

The tool we’re building? A Google Reviews scraper. Your AI agent asks “What are our latest Google reviews?” or “Show me reviews with ratings below 3 stars” — and the MCP server fetches and returns structured data. One server. Every AI client. Forever reusable.

In the Go version, we compiled to a single binary. In the JavaScript version, we ran on Node.js. In the C# version, we used ASP.NET Core. Here in Python, we’re using the FastMCP API — a decorator-based approach that lets you write an MCP server in fewer lines of code than any other language.

What Is an MCP Server?

MCP (Model Context Protocol) is an open specification that defines how AI clients communicate with external tools and data sources. Think of it as a universal USB-C port for AI. One standard. Any tool. Any client.

The protocol exposes three primitives:

  • Tools — actions the AI can invoke (scrape reviews, query a database, create a file)
  • Resources — readable data sources (a live dashboard, an API response, a document)
  • Prompts — reusable message templates for common workflows

The official MCP SDK is available in six languages, all Tier 1 for feature completeness and protocol support: TypeScript, Python, C#, and Go (maintained in collaboration with Google), plus Java and Rust at Tier 2. The SDK handles the JSON-RPC plumbing. You focus on the business logic.

For the full SDK reference, see the official MCP SDK documentation.

Setting Up the Python SDK

The official Python SDK is published on PyPI as mcp. It includes both the server and client implementations, plus a CLI for development tools.

Create a new project and install the SDK using uv (the recommended tool) or pip:

Using uv:

uv init mcp-google-reviews
cd mcp-google-reviews
uv add "mcp[cli]"

Or using pip:

pip install "mcp[cli]"

What this command is doing:

  • uv init mcp-google-reviews – Initializes a new Python project with a pyproject.toml file. uv is the fast Python package installer and project manager from Astral (the creators of Ruff).
  • uv add "mcp[cli]" – Installs the MCP Python SDK with the optional CLI extras. The [cli] feature adds the mcp command-line tool for testing and development.

The Complete Google Reviews MCP Server in Python

Here is the full server. It exposes a single tool — fetch_reviews — that takes a Google Maps place ID and returns the latest reviews as structured JSON.

Save this as server.py:

from mcp.server.fastmcp import FastMCP

# Create the MCP server with identification
mcp = FastMCP("google-reviews-scraper", json_response=True)

@mcp.tool()
def fetch_reviews(
    place_id: str,
    limit: int = 10,
) -> str:
    """Fetch Google reviews for a business using its Place ID.
    Returns structured review data including ratings, text, and author names."""

    # In a real implementation, you would:
    # 1. Call the Google Places API with place_id
    # 2. Parse the response into review objects
    # 3. Return structured data

    reviews = [
        {"author_name": "Alice Johnson", "rating": 5, "text": "Excellent service! The team went above and beyond.", "time_ago": "2 days ago"},
        {"author_name": "Bob Smith", "rating": 4, "text": "Great experience overall, minor wait time.", "time_ago": "1 week ago"},
        {"author_name": "Carol Davis", "rating": 1, "text": "Disappointing. Did not meet expectations.", "time_ago": "3 weeks ago"},
    ]

    result = {
        "place_id": place_id,
        "reviews": reviews[:limit],
        "count": len(reviews),
    }

    return str(result)

# Run with streamable HTTP transport
if __name__ == "__main__":
    mcp.run(transport="streamable-http")

That is the entire server. Fourteen lines of business logic.

What this code is doing:

  • FastMCP("google-reviews-scraper", json_response=True) – Creates the MCP server with identification metadata. The json_response=True flag configures the server to return JSON responses instead of Server-Sent Events (SSE), which is simpler and compatible with all modern MCP clients including Open WebUI.
  • @mcp.tool() – This decorator transforms a regular Python function into an MCP tool. The function name becomes the tool name, the docstring becomes the tool’s description (which tells the AI when and how to invoke it), and the type annotations define the input schema automatically. No manual schema definition needed.
  • mcp.run(transport="streamable-http") – Starts the server using Streamable HTTP transport on localhost:8000 by default. The transport parameter determines how the server communicates with clients. Streamable HTTP is the recommended and most widely supported transport method.

Running the Server

Run the server with Python:

uv run server.py

Or directly with Python:

python server.py

Expected output:

INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO:     Started server process [12345]
INFO:     Waiting for application startup.
INFO:     Application startup complete.

The server is now listening on port 8000. The fetch_reviews tool is registered and ready for AI clients to discover.

Connecting to Open WebUI

Follow the same process from my Connecting Open WebUI to MCP Servers post, pointing the Server URL to http://localhost:8000:

  1. Navigate to Admin Settings → External Tools in your Open WebUI admin panel
  2. Click + (Add Server)
  3. Set Type to MCP (Streamable HTTP)
  4. Set Server URL to http://localhost:8000
  5. Set Auth to None
  6. Click Save

From Example to Production

The code above returns sample data. For production, inject httpx (a modern HTTP client for Python):

import httpx

@mcp.tool()
async def fetch_reviews(
    place_id: str,
    limit: int = 10,
) -> str:
    """Fetch Google reviews for a business using its Place ID."""
    async with httpx.AsyncClient() as client:
        response = await client.get(
            f"https://places.googleapis.com/v1/places/{place_id}:reviews",
            headers={
                "Content-Type": "application/json",
                "X-Goog-Api-Key": "your-api-key-here",
            },
        )
        response.raise_for_status()
        return str(response.json())

The MCP structure stays identical. You’re only replacing the business logic inside the fetch_reviews function. The SDK handles protocol compliance, JSON-RPC, session management, and the Streamable HTTP transport — everything you’d normally build yourself.

What’s Next

We’ve now built the same Google Reviews MCP server in four languages. Here is the complete series:

  • Go version – Compiled to a single binary with zero runtime dependencies. Best for performance-critical, minimal-footprint deployments.
  • JavaScript version – Runs on Node.js or Bun. Great for web teams already working in JavaScript.
  • C# version – Built with the official Microsoft-maintained C# SDK and ASP.NET Core. Ideal for enterprise .NET stacks.
  • This Python version – Built with the FastMCP API using decorators. The quickest to write and prototype, with automatic schema generation from type hints.

For the full Python SDK documentation, see the MCP Python SDK documentation.

Key Takeaway

  • Developer velocity: Python’s FastMCP API is the fastest way to build an MCP server. Decorators, type annotations, and docstrings — that’s all you need. No manual schema definition, no boilerplate, no configuration. Write the function, decorate it, run it.
  • Type safety without boilerplate: Python’s type hints automatically generate the JSON Schema that AI clients need. No Zod, no attributes, no manual schema files. Just type your parameters and the SDK does the rest.
  • Strategic: Your AI agent now has direct access to your company’s Google reviews. The Python version means you can build, test, and iterate faster than any other language. Speed matters when your competitors are still reading documentation.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *