Content
# 1. Project Introduction
## 1.1 Main Content
The related videos for this series are as follows, in the order of release:
**(Episode 1)[2024.12.10] Major Breakthrough in Claude! Release of MCP (Model Context Protocol), Experience it in LLM Application Scripts without using Claude Desktop software, supporting OpenAI-style large models**
Main Content: Introduction to MCP, MCP functionality testing, LLM (large models supporting OpenAI interface style) application calling MCP
https://www.bilibili.com/video/BV1HBquYbE7t/
https://youtu.be/Jmo7rgb_OXQ
**(Episode 2)[2024.12.12] Claude MCP Application Text2SQL Use Case, Experience its Smoothness in LLM Applications without using Claude Desktop software, supporting OpenAI-style large models**
Main Content: Using MCP to implement Text2SQL functionality in LLM applications to manipulate MySQL databases
https://www.bilibili.com/video/BV1ELq4YME8T/
https://youtu.be/yaLAqEMz45A
**(Episode 3)[2024.12.12] Claude MCP Application Client Accessing and Calling Multiple Server Resources and Tools Simultaneously, without using Claude Desktop software, supporting OpenAI-style large models**
Main Content: MCP client accessing multiple MCP servers simultaneously, supporting file system operations and Text2SQL functionality to manipulate MySQL databases
https://www.bilibili.com/video/BV1oNqaYJEUy/
https://youtu.be/tG-ZjOgrcSA
**(Episode 4)[2024.12.23] DuckDuckGo Online Search, Fetch Content Extraction MCP Server, Accessing and Calling Multiple Server Resources and Tools, Supporting Alibaba Tongyi Qianwen Large Model, GPT Large Model, Ollama Local Open Source Large Model**
Main Content: MCP client accessing multiple MCP servers simultaneously, supporting file system operations, Text2SQL functionality to manipulate MySQL databases, online search (DuckDuckGo search engine) and web content extraction
https://www.bilibili.com/video/BV1SckXY3E6S/
https://youtu.be/9pzS9saNcGA
## 1.2 Introduction to MCP
MCP (Model Context Protocol) is an open protocol open-sourced by Claude that enables seamless integration between LLM applications and external data sources and tools.
The architecture is very simple: developers can expose data through MCP servers or build AI applications (MCP clients) that connect to these servers.
Currently, MCP is still in a testing phase, running as a local service on your own computer.
Official MCP Introduction: https://www.anthropic.com/news/model-context-protocol
MCP Documentation Manual: https://modelcontextprotocol.io/introduction
Official MCP Server List: https://github.com/modelcontextprotocol/servers
Python SDK GitHub Address: https://github.com/modelcontextprotocol/python-sdk
### (1) Python SDK Version
As of now (12.9), the current stable version is 1.1.0
### (2) How MCP Works
MCP follows a client-server architecture, where the host application can connect to multiple servers.
<img src="./01.png" alt="" width="600" />
**MCP Host:** The LLM application (Claude Desktop, IDE, or AI applications, etc.) that initiates the connection.
**MCP Client:** Maintains a 1:1 connection with the server within the host application.
**MCP Servers:** Provide context, tools, and prompts to the client.
### (3) Core Components
**Protocol Layer**
The protocol layer handles message frames, request/response links, and high-level communication patterns. Key classes: Protocol, Client, Server.
**Transport Layer**
The transport layer handles the actual communication between the client and the server.
Stdio (standard input/output): Communication using standard input/output.
SSE (Server-Sent Events): Sending messages from the server to the client using events sent by the server.
All transports use JSON-RPC 2.0 to exchange messages.
**Message Types**
Requests: Requests expect a response from the other party.
Notifications: Notifications are one-way messages that do not expect a response.
Results: Results are successful responses to requests.
Errors: Errors indicate that the request has failed.
### (4) Connection Lifecycle
**Initialization**
<img src="./02.png" alt="" width="600" />
The client sends an initialize request with the protocol version and capabilities.
The server responds with its protocol version and capabilities.
The client sends an initialized notification as confirmation.
Normal message exchange begins.
**Message Exchange**
After initialization, the following modes are supported:
Request-Response: The client or server sends a request, and the other party responds.
Notifications: Either party sends a one-way message.
**Termination**
The following standard error codes are defined:
ParseError = -32700
InvalidRequest = -32600
MethodNotFound = -32601
InvalidParams = -32602
InternalError = -32603
### (5) Core Features
**Resources**
Resources are a core feature of the Model Context Protocol (MCP), allowing servers to expose data and content that can be read by clients and used as context for LLM interactions.
File contents
Database records
API responses
Live system data
Screenshots and images
Log files
And more
Each resource is identified by a unique URI and can contain text or binary data.
**Prompts**
Servers can define reusable prompt templates and workflows, which clients can easily present to users and LLMs. They provide a powerful way to standardize and share common LLM interactions.
Accept dynamic parameters.
Include context from resources.
Guide specific workflows.
**Tools**
Tools are a powerful feature in MCP, designed to be controlled by LLMs, meaning tools are exposed from the server to the client for LLMs to automatically invoke them (with human approval in the loop).
Key aspects of tools include:
Discovery: Clients can list available tools through the tools/list endpoint.
Invocation: Tools can be invoked using the tools/call endpoint, where the server performs the requested operation and returns the result.
Flexibility: Tools range from simple calculations to complex API interactions.
**Sampling**
Sampling is a powerful MCP feature that allows the server to request LLM completions through the client, enabling complex proxy behaviors while maintaining security and privacy.
The server sends a sampling/createMessage request to the client.
The client reviews the request and can modify it.
Client samples for LLM sampling.
The client reviews the completion.
The client returns the results to the server.
This human-machine interaction design ensures that users maintain control over the content seen and generated by the LLM.
**Transports**
MCP's transports provide the foundation for communication between clients and servers. The transport handles the underlying mechanisms for sending and receiving messages.
MCP uses JSON-RPC 2.0 as its format. The transport layer is responsible for converting MCP protocol messages into JSON-RPC format for transmission and converting received JSON-RPC messages back into MCP protocol messages.
# 2. Preparation Work
## 2.1 Setting Up the Integrated Development Environment
Anaconda provides a Python virtual environment, and PyCharm provides the integrated development environment.
**Refer to the following video for details:**
【Large Model Application Development - Introductory Series】03 Setting Up the Integrated Development Environment - Preparation Work
https://youtu.be/KyfGduq5d7w
https://www.bilibili.com/video/BV1nvdpYCE33/
## 2.2 Large Model LLM Service Interface Calling Scheme
(1) For foreign large models like GPT, use a proxy since direct access is not available in China; choose your own proxy solution.
Here, we recommend using: https://nangeai.top/register?aff=Vxlp
(2) Non-GPT large model solutions using OneAPI or native interfaces from large model vendors.
(3) Local open-source large model solutions (Ollama method).
**Refer to the following video for details:**
【Large Model Application Development - Introductory Series】04 Large Model LLM Service Interface Calling Scheme
https://youtu.be/mTrgVllUl7Y
https://www.bilibili.com/video/BV1BvduYKE75/
# 3. Project Initialization
## 3.1 Download Source Code
Download the project files from GitHub or Gitee to your local machine, with the following download addresses:
https://github.com/NanGePlus/MCPTest
https://gitee.com/NanGePlus/MCPTest
## 3.2 Build Project
Use PyCharm to build a project and configure a virtual Python environment for the project.
Project Name: MCPTest
Keep the virtual environment name consistent with the project name.
## 3.3 Copy Relevant Code to the Project Directory
Copy all files from the downloaded code folder to the newly created project root directory.
## 3.4 Install Project Dependencies
Create a new command line terminal and run `pip install -r requirements.txt` in the terminal to install dependencies.
**Note:** It is recommended to test this project using the required corresponding versions to avoid code incompatibility due to version upgrades. After successful testing, you can proceed with upgrade testing.
# 4. Function Testing
## 4.1 (Episode 1)[2024.12.10] Testing Steps
**Core Demonstration Example: Filesystem Using Officially Provided File Operation MCP Server**
**Description:** Provides file system operation functionalities, including reading and writing files, directory management, and file searching.
**Resource:** file://system File System Resource URI
**Tools:** read_file, write_file, create_directory, list_directory, move_file, search_files, get_file_info
read_file: Reads file content, parameter: path (file path).
read_multiple_files: Reads multiple file contents, parameter: paths (array of file paths).
write_file: Creates or overwrites a file, parameters: path (file path), content (file content).
create_directory: Creates a directory, parameter: path (directory path).
list_directory: Lists directory contents, parameter: path (directory path).
move_file: Moves/renames a file, parameters: source (source path), destination (destination path).
search_files: Recursively searches for files, parameters: path (starting path), pattern (search pattern).
get_file_info: Retrieves file metadata, parameter: path (file path).
Corresponding link: https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem
**Code Directory**
Scripts are placed in nangeAGICode/basic, filesystem_basic, filesystem_chat directories; run the corresponding scripts for testing.
**Testing Content:**
Which folders can I currently access?
Help me create a test folder.
Help me create a file test1.txt in the test folder with the content: 南哥AGI研习社.
Change the content "agi" in test1.txt to uppercase "AGI".
## 4.2 (Episode 2)[2024.12.12] Testing Steps
**Core Demonstration Example: Text2SQL Custom Manipulation of MySQL Database MCP Server**
**Description:** Provides Text2SQL functionality to manipulate MySQL databases.
**Resource:** mysql://{table[0]}/data Database Table Resource URI
**Tool Description:** execute_sql
execute_sql: Runs SQL scripts, parameter: query (SQL statement).
**Code Directory**
Scripts are placed in nangeAGICode/mysql_chat directory; run the corresponding scripts for testing.
Provides LLM operations on MySQL databases, including create, delete, update, and query.
**Testing Content:**
(1) List available resources.
Which data tables can I currently access?
(2) Retrieve content of a certain resource.
Get the content of the nange_agi table.
(3) List available tools.
Which tools can I currently use?
(4) Query.
Call the tool to get the content of the nange_agi table.
(5) Add.
Randomly add a piece of data.
Call the tool to get the content of the nange_agi table.
(6) Modify.
Change the name of the newly added data to "test."
Call the tool to get the content of the nange_agi table.
(7) Delete.
Delete the newly created data.
Call the tool to get the content of the nange_agi table.
(8) Count the number of data entries.
How many data entries are there in this table?
## 4.3 (Episode 3)[2024.12.12] Testing Steps
**Core Demonstration Example: MCP Client Accessing Multiple MCP Servers**
**Description:** Integrating the content from the previous two episodes to use the Filesystem and Text2SQL servers together.
**Code Directory**
Scripts are placed in nangeAGICode/mysql_filesystem_chat directory; run the corresponding scripts for testing.
**Testing Content:**
Which resources can I currently access?
Which tables can I currently access?
Which tools can I currently use?
Create a test folder.
Create a file test1.txt in the test folder with the content: Username: NanGe003, Password: 6543217890, Content: 南哥AGI研习社++.
Get the content of the nange_agi table.
Add a piece of data with the content from the newly created test1.txt.
Get the content of the nange_agi table.
How many data entries are there in this table?
Change the name of the newly added data to "test."
Get the content of the nange_agi table.
Delete the newly created data.
Get the content of the nange_agi table.
## 4.4 (Episode 4)[2024.12.23] Testing Steps
**Core Demonstration Example: Online Search and Content Retrieval Using Custom Online Search DuckDuckGo MCP Server and Official Fetch MCP Server**
**Description:** Provides online search and extracts and summarizes web link content from the search results in advance.
**Tool Description:** duckduckgo_web_search, fetch
duckduckgo_web_search: Executes online search, parameters: query (search keywords); parameter: max_results (maximum number of returned contents).
fetch: Retrieves URL from the internet and extracts its content as markdown, parameters: url (link address); parameter: max_length (maximum number of characters returned, default: 5000); raw (retrieve original content without Markdown conversion, default: false).
**Code Directory**
Scripts are placed in nangeAGICode/search_mysql_filesystem_chat directory; run the corresponding scripts for testing.
**Testing Content:**
Which resources can I currently access?
Which tools can I currently use?
Search for the latest developments in AI in 2024, output the content in Chinese, list 10 entries, and include relevant links.
Write this content into test.txt file.
Retrieve the content from the first link and summarize it.
You Might Also Like
Ollama
Ollama enables easy access to large language models on various platforms.

n8n
n8n is a secure workflow automation platform for technical teams with 400+...
OpenWebUI
Open WebUI is an extensible web interface for customizable applications.

Dify
Dify is a platform for AI workflows, enabling file uploads and self-hosting.

Zed
Zed is a high-performance multiplayer code editor from the creators of Atom.
MarkItDown MCP
markitdown-mcp is a lightweight MCP server for converting various URIs to Markdown.