MCP Python Learning Server
Provides tools to search and retrieve details of programming topics, and exposes a catalog resource for topic listings.
README
MCP Servers in Python
Description
This beginner project demonstrates how to build, test and consume a local Model Context Protocol (MCP) server with Python and FastMCP.
The server exposes a small programming-topic dataset through two tools and one read-only resource. A deterministic agent-like client connects to the server through MCP, searches for a relevant topic, retrieves its complete details and creates a short study recommendation.
Completed tasks:
- Task 0 — Project structure
- Task 1 — MCP architecture explanation
- Task 2 — Basic FastMCP server
- Task 3 — Local topic dataset
- Task 4 —
search_topicstool - Task 5 —
get_topic_detailstool - Task 6 — Read-only catalogue resource
- Task 7 — Direct MCP server testing
- Task 8 — MCP-connected agent-like client
- Task 9 — Third-party MCP server review
- Task 10 — Complete documentation and reflection
Project structure:
mcp-intro/
├── server/
│ ├── __init__.py
│ └── learning_server.py
├── client/
│ ├── __init__.py
│ ├── mcp_client.py
│ ├── agent.py
│ └── test_server.py
├── data/
│ └── topics.json
├── output/
│ └── sample_agent_response.md
├── README.md
├── requirements.txt
├── .env.example
└── .gitignore
MCP Architecture Summary
MCP gives an AI application a standard way to connect to external tools and data sources.
Student
↓
Agent-like application
↓
FastMCP client
↓
Programming Learning Server
↓
Tools or resource
↓
data/topics.json
The main parts are:
- MCP host: the application that manages the overall interaction.
- MCP client: the connection between the host or application and one MCP server.
- MCP server: the program that publishes focused capabilities.
- Tool: a callable operation that accepts input and returns a result.
- Resource: readable data exposed through a stable URI.
The server should expose only the capabilities and data that the client needs.
Requirements
- Python 3.10 or newer
- A Python virtual environment
- Packages listed in
requirements.txt
The current Python dependencies are:
fastmcp
python-dotenv
Setup
cd ~/mcp-intro
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Validate the local dataset:
python -m json.tool data/topics.json > /dev/null
Compile the Python files:
python -m py_compile \
server/learning_server.py \
client/mcp_client.py \
client/test_server.py \
client/agent.py
No output from these validation commands means they completed successfully.
How to Run the Server
The server uses FastMCP's default stdio transport.
cd ~/mcp-intro
source .venv/bin/activate
python server/learning_server.py
The process waits for an MCP client to communicate through standard input and output. Stop it with Ctrl+C.
Do not add ordinary debug print() calls to the server's standard output because they can interfere with stdio MCP messages.
How to Test the Server
Run the cumulative FastMCP integration test:
cd ~/mcp-intro
source .venv/bin/activate
python client/test_server.py
The test client starts the server through stdio and verifies that:
- the server responds to a ping;
- both tools are listed;
search_topicsreturns a valid match;get_topic_detailsreturns a complete topic;- blank and unknown inputs return understandable messages;
topics://catalogis listed and can be read;- the catalogue contains five topic ids and titles.
Expected final line:
All MCP server tests passed.
The server can also be inspected manually:
fastmcp dev server/learning_server.py
Useful manual inputs are:
search_topics: functions
search_topics: methods
search_topics: networking
get_topic_details: python-functions
get_topic_details: unknown-topic
resource: topics://catalog
How to Run the Agent
Run the agent-like client with a student question:
cd ~/mcp-intro
source .venv/bin/activate
python client/agent.py "I want to study Python functions. What should I review first?"
It can also prompt for a question interactively:
python client/agent.py
The agent:
- receives the student's question;
- connects to
server/learning_server.pythrough a FastMCP client; - calls
search_topicsthrough MCP; - calls
get_topic_detailsthrough MCP; - formats the returned data as a student-facing answer;
- saves the answer to
output/sample_agent_response.md.
It does not import the server's tool functions directly.
Available Tools
search_topics
Searches topic titles and key concepts.
Input:
{"query": "functions"}
It returns up to three compact matches containing:
idtitlesummaryprerequisiteskey_concepts
A blank query or a query with no match returns a clear message.
get_topic_details
Retrieves one complete topic by its stable id.
Input:
{"topic_id": "python-functions"}
A successful result contains:
idtitlesummaryprerequisiteskey_conceptscommon_mistakespractice_idea
A blank or unknown id returns a clear message.
Available Resources
topics://catalog
This read-only resource returns a JSON string containing only the available topic ids and titles.
Example:
[
{"id": "python-functions", "title": "Python Functions"},
{"id": "python-lists", "title": "Python Lists"}
]
The resource reads the existing dataset and does not create, edit or delete files or topic records.
Third-Party MCP Server Review
The reviewed third-party server is the official reference Filesystem MCP Server from the modelcontextprotocol/servers repository.
Purpose: It allows an MCP client to read files, inspect directories and metadata, search files, create directories, write or edit files, and move files or directories.
Where it runs: It runs locally as a Node.js process and normally communicates through stdio. It can be started with npx or Docker.
Exposed tools: Its documented tools include file reading, directory listing, directory trees, file search, file information, directory creation, file writing, file editing, moving files and listing allowed directories. The reviewed documentation describes tools rather than MCP resources.
Permissions and credentials: It does not require an API key or personal account. It requires explicit filesystem directory access and runs with the current user's permissions inside the allowed directories.
Restricted configuration example:
{
"mcpServers": {
"filesystem-review": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/tmp/mcp-filesystem-review"
]
}
}
}
Risk: Broad access could expose private files or allow important files to be overwritten, edited or moved.
Safety measure: Grant access only to a dedicated test directory containing disposable files. Never expose the complete home directory, SSH keys, browser profiles, password stores or project secrets. Prefer a read-only mount when write access is unnecessary.
Documentation reviewed:
https://github.com/modelcontextprotocol/servers/tree/main/src/filesystemhttps://modelcontextprotocol.io/docs/develop/connect-local-servers
Example Output
A real generated example is saved in output/sample_agent_response.md.
Recommended topic: Python Functions
Why it is relevant:
Functions group reusable instructions under a name so that code can be organised and called when needed.
Prerequisites:
- Variables
- Basic Python syntax
Key concepts:
- Defining functions
- Parameters and arguments
- Return values
Practice idea:
Create a function that receives two numbers and returns their total.
Common mistakes to avoid:
- Calling a function before defining it
- Using print when a return value is needed
Known Limitations
- The local dataset contains only five topics.
- Search uses simple case-insensitive substring matching rather than semantic search.
- The agent chooses the first matching topic rather than ranking several possibilities intelligently.
- The agent is deterministic and does not use an LLM.
- A question about a missing topic, such as Python decorators, cannot produce a detailed recommendation.
- The server currently uses local stdio only; it does not expose an authenticated HTTP endpoint.
- The dataset is loaded from disk on every tool or resource call.
- The agent overwrites
output/sample_agent_response.mdeach time it runs. - The project has no database, user accounts, authentication, rate limiting or persistent conversation memory.
- Expected invalid searches return result messages rather than formal MCP error objects.
During development, the most important errors to check were an incorrect path to data/topics.json, accidentally bypassing MCP by importing server functions directly, and writing debug output to stdout while using stdio.
Reflection
What problem does MCP solve?
MCP provides a standard connection between AI applications and external capabilities. Without it, every application and data source would need a custom integration. MCP lets a client discover and call tools or read resources through a consistent protocol.
What is the difference between an MCP tool and an MCP resource?
A tool is called with input to perform an operation or computation. A resource exposes readable data at a URI. In this project, topic searching and exact lookup are tools, while the topic catalogue is a read-only resource.
What does this MCP server expose?
The server exposes search_topics, get_topic_details and the topics://catalog resource. These capabilities use the five records in data/topics.json.
How does the agent use the MCP server?
The agent starts an MCP client connection over stdio. It calls search_topics to discover a candidate, then calls get_topic_details with the selected id. It formats only the returned topic data into a short study recommendation and saves the answer as Markdown.
What should be checked before using a third-party MCP server?
Check who published it, whether it runs locally or remotely, which tools and resources it exposes, which files or systems it can access, which credentials it requires, whether it can modify data, and whether its permissions can be restricted. Its documentation and source should be reviewed before granting access.
What limitation was observed in this implementation?
The clearest limitation is the small dataset combined with literal substring search. A reasonable question can fail simply because the requested topic or wording is not present. For example, the supplied dataset has no decorators topic, so the agent must report that no match exists rather than inventing an answer.
Git Validation, Commit and Push
cd ~/mcp-intro
source .venv/bin/activate
python -m json.tool data/topics.json > /dev/null
python -m py_compile \
server/learning_server.py \
client/mcp_client.py \
client/test_server.py \
client/agent.py
python client/test_server.py
python client/agent.py "I want to study Python functions. What should I review first?"
git remote -v
git status
git add README.md
git commit -m "Complete MCP project documentation"
git push origin main
Self-Validation
Cumulative Project
- [x] Tasks 0–10 are documented as complete.
- [x] The project structure is documented.
- [x] The JSON dataset contains five valid topic records.
- [x] The FastMCP server has a script entry point.
- [x]
search_topicsis exposed through MCP. - [x]
get_topic_detailsis exposed through MCP. - [x]
topics://catalogis exposed as a read-only resource. - [x] The direct MCP integration test checks tools, errors and the resource.
- [x] The agent calls both tools through MCP rather than direct imports.
- [x] A real sample response is saved in the output directory.
- [x] A third-party MCP server and its risks are reviewed.
Task 10 — Complete Documentation and Reflection
- [x]
README.mdincludes all required sections. - [x]
README.mdexplains what the server does. - [x]
README.mdexplains how to run the server. - [x]
README.mdexplains how to test the server. - [x]
README.mdexplains how to run the agent. - [x]
README.mdlists the available tools. - [x]
README.mdlists the available resources. - [x]
README.mdincludes the third-party MCP server review. - [x]
README.mdincludes one example output. - [x]
README.mdincludes known limitations. - [x]
README.mdincludes a reflection answering every required question. - [x] No secrets are included.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.