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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。