Roadmaps / AI Engineering / Lab 6

Lab 6 of 8 · MCP: sharing tools with any AI app

Publish your document search as an MCP server

Wrap your search and refund tools in an MCP server, test it in the MCP Inspector, and use it from Claude Code.

Time
45–60 minutes
Cost
Free (the Inspector runs locally). Using it from Claude Code uses your Claude plan or API credit.

What you learn

The Model Context Protocol (MCP) is a standard way to give AI apps your tools and data. Write a tool once as an MCP server, and Claude Desktop, Claude Code and many other apps can use it.

  • MCP servers, clients and transports
  • Turning Python functions into MCP tools
  • Testing a server with the MCP Inspector
  • Connecting a server to Claude Code

In the AI era: Companies are exposing internal systems to AI through MCP servers. Building and securing them is a fast-growing part of AI engineering jobs.

Before you start

  • Finish lab 5.

  • Install Node.js 20 or newer for the Inspector (node --version).

Step by step

  1. 1 Write the server

    Each decorated function becomes an MCP tool; its docstring and type hints become the description and schema. The server talks over standard input and output.

    File: mcp_server.py
    from mcp.server import MCPServer
    
    from agent import refund_amount as calculate_refund
    from rag import search
    
    server = MCPServer("northwind-docs")
    
    
    @server.tool()
    def search_docs(query: str) -> list[dict]:
        """Search Northwind Coffee's policy documents and return the most relevant paragraphs."""
        return search(query)
    
    
    @server.tool()
    def refund_amount(price: float, days_since_delivery: int, opened: bool) -> dict:
        """Exact refund for an order under Northwind Coffee's refund policy."""
        return calculate_refund(price, days_since_delivery, opened)
    
    
    if __name__ == "__main__":
        server.run()
    
  2. 2 Test it in the MCP Inspector

    This opens a web page. Click Connect, open the Tools tab, choose search_docs, enter express shipping and click Run Tool.

    Run this
    npx @modelcontextprotocol/inspector .venv/bin/python mcp_server.py
    You should see:

    Both tools are listed, and search_docs returns the shipping paragraph about $12 express shipping.

  3. 3 Use it from Claude Code

    If you use Claude Code, register the server, start Claude Code in this folder, and ask "Using northwind-docs, can I return an opened bag after 20 days?". Use full paths so it works from anywhere.

    Run this
    claude mcp add northwind-docs -- "$PWD/.venv/bin/python" "$PWD/mcp_server.py"
    claude mcp list
    You should see:

    northwind-docs is listed as connected, and Claude answers that the 14-day window for opened bags has passed.

  4. 4 Commit and push

    In your README, explain how someone else can connect your server.

    Run this
    git add mcp_server.py README.md
    git commit -m "Expose document tools over MCP"
    git push

You are done when

  • The Inspector lists both tools and runs them.

  • You can explain the difference between an MCP server and an MCP client.

  • Your README explains how to connect the server.

Finished? Get your proof page

We check your public GitHub repository and give you a page to share with recruiters, and can add the project to your resume.