In the previous lessons, we explored how MCP connects AI applications to external tools.
Now we’ll build a local MCP server for our Research Agent. It will expose two tools: one for retrieving stored research information and another for fetching content from approved webpages.
Creating the MCP Server
An MCP server is a program that makes capabilities available to compatible AI applications.
Our server is written in Python using the MCP SDK. We start by creating a server instance:
from mcp.server import MCPServer
mcp = MCPServer("Product Research Server")
This creates the server that will register and expose our research tools.
Registering Our First Tool
We’ll use @mcp.tool() to make a Python function available through MCP.
@mcp.tool()
def get_research_source(source_id: str) -> str:
"""Retrieve curated research source metadata by ID (not full article content)."""
record = SOURCE_RECORDS.get(source_id)
return json.dumps(record if record else {"error": "Research source not found"})
The decorator registers the function as an MCP tool. Its name, description, and parameter definitions help the MCP client discover how it can be used.
Our first tool retrieves prepared research metadata. It does not search the internet.
Adding a Webpage Retrieval Tool
Our second tool, fetch_article(url), retrieves content from an approved webpage.
Unlike get_research_source(), it performs external retrieval. The server controls which URLs are permitted and how text is extracted.
A tool can expose stored data or perform an operation on an external system.
Starting the Server
Our local MCP server uses stdio:
if __name__ == "__main__":
mcp.run(transport="stdio")
The agent application starts the MCP server as a separate process. The MCP client communicates with it through standard input and output.
The server does not decide which tool the agent should use. It exposes available tools and executes requests received through MCP.
What We’ve Built
| Tool | Purpose |
|---|---|
get_research_source(source_id) |
Retrieve stored research metadata |
fetch_article(url) |
Retrieve webpage content from an approved URL |
Extract the ZIP and open the lab-03 folder. The README covers setup, your API key, and costs.
The sample source builder_pm_001 is illustrative data, not published research.
Test Your Understanding
Question 1 of 3
What does @mcp.tool() do?