计算机桌面txt文件助手
该项目展示了如何使用 MCP (模型上下文协议) 来创建和使用各种智能助手和工具。项目包含了多个示例,展示了不同场景下的 MCP 应用。
服务介绍
MCP (Model Context Protocol) Example Project
This project demonstrates how to use MCP (Model Context Protocol) to create and utilize various intelligent assistants and tools. The project includes multiple examples showcasing the application of MCP in different scenarios.
Project Structure
day11_MCP_A2A/
├── CASE-A2A/ # Agent to Agent example case
├── MCP-demo01/ # Basic MCP example
└── MCP-demo02/ # Advanced MCP example
Main Functional Modules
1. CASE-A2A
Agent to Agent (A2A) communication example, demonstrating how different agents can collaborate through a standard protocol.
Component Description
-
BasketBallAgent.py: Basketball activity scheduling agent- Communicates with WeatherAgent via A2A protocol
- Makes intelligent decisions on whether to schedule basketball activities based on weather conditions
- Supports custom date activity scheduling
- Includes a complete error handling mechanism
-
WeatherAgent.py: Weather service agent- Implemented as a RESTful service using FastAPI
- Provides standard A2A protocol interfaces
- Supports Agent Card declaration (/.well-known/agent.json)
- Simulates weather data storage and query functions
A2A Protocol Implementation
-
Agent Card Specification
json
{
"name": "WeatherAgent",
"version": "1.0",
"description": "Provides weather data queries for specified dates",
"endpoints": {
"task_submit": "/api/tasks/weather",
"sse_subscribe": "/api/tasks/updates"
},
"input_schema": {
"type": "object",
"properties": {
"date": {"type": "string", "format": "date"},
"location": {"type": "string", "enum": ["Beijing"]}
},
"required": ["date"]
}
} -
Communication Process
- BasketBallAgent retrieves the capability description of WeatherAgent
- Constructs a task request that conforms to the specification
- Sends the request and processes the response
- Makes decisions based on the weather data
Running Instructions
-
Start the WeatherAgent service:
bash
cd CASE-A2A
python WeatherAgent.py -
Run the BasketBallAgent example:
bash
python BasketBallAgent.py
Dependency Requirements
bash
pip install fastapi uvicorn requests pydantic
Example Output
python
Sunny day example
Basketball scheduling result: {'status': 'confirmed', 'weather': {'temperature': '22℃', 'condition': 'Partly cloudy turning sunny'}}
Rainy day example
Basketball scheduling result: {'status': 'cancelled', 'reason': 'Bad weather'}
2. MCP-demo01
Basic MCP functionality example, demonstrating how to use MCP to create various tools and services.
-
assistant_mcp_amap_bot.py: Intelligent assistant integrated with Amap API- Supports geocoding and reverse geocoding
- Provides route planning functionality
- Supports nearby search and weather queries
-
assistant_mcp_txt_bot.py: Text processing intelligent assistant- Text statistics and analysis
- Document parsing functionality
-
txt_counter.py: Desktop TXT file management tool- Counts the number of .txt files on the desktop
- Lists all .txt files on the desktop
- Reads the content of a specified txt file
- Supports UTF-8 encoded text files
-
dalian_tour.html: Dalian travel itinerary planning webpage- Complete one-day tour itinerary
- Printable in a friendly A4 format
- Includes detailed information such as transportation and dining
3. MCP-demo02
Advanced MCP functionality example, demonstrating the combined application scenarios of multiple MCP servers.
assistant_bot.py: Multi-functional intelligent assistant- Integrates three MCP servers:
- Amap map service (amap-maps): Provides geographical location and route planning
- Web content fetching service (fetch): Supports web content extraction and conversion
- Bing search service (bing-cn-mcp-server): Provides search functionality
- Supports three interaction modes:
- GUI mode: Web interface with preset query suggestions
- TUI mode: Terminal interaction supporting continuous dialogue
- Test mode: Single query testing
- Advanced features:
- Web content extraction and conversion (HTML to Markdown)
- Intelligent search and information aggregation
- Multi-modal input support
- Context-aware conversation management
- Integrates three MCP servers:
Running example:
bash
cd MCP-demo02
Configure necessary environment variables
export DASHSCOPE_API_KEY='your-api-key'
Run (default is GUI mode)
python assistant_bot.py
Example queries:
-
Web content extraction:
Convert the https://example.com webpage into Markdown format2. Location Query:
Find me a cafe near West Lake
-
Comprehensive Search:
Search for AI technology news from the past week
Note: Before using, make sure all necessary MCP servers are installed:
bash
npm install -g @amap/amap-maps-mcp-server
npm install -g @bing/bing-cn-mcp-server
npm install -g @fetch/fetch-mcp-server
Tool Integration
The project integrates multiple practical tools:
doc_parser: Document parsing toolsimple_doc_parser: Simple document parser
Environment Requirements
- Python 3.7+
- Node.js and npm (for MCP servers)
- Related Python packages:
- dashscope==1.22.1
- mcp==1.7.1
- qwen_agent==0.0.19
Configuration Instructions
1. API Keys Configuration
-
DashScope API Key (Required):
-
Obtain from: https://dashscope.console.aliyun.com/
-
Set by:
bash
export DASHSCOPE_API_KEY='your-api-key' -
Or set directly in the code (not recommended)
-
-
AMap API Key (Required if using map features):
- Obtain from: https://console.amap.com/dev/key/app
- Configure in assistant_mcp_amap_bot.py
2. Install Dependencies
bash
Install Python dependencies
pip install -r MCP-demo01/requirements.txt
Install Node.js dependencies (if using map features)
npm install -g @amap/amap-maps-mcp-server
Running Instructions
1. AMap Assistant (assistant_mcp_amap_bot.py)
Environment Preparation
bash
1. Install necessary dependencies
pip install dashscope qwen-agent requests
2. Set environment variables
export DASHSCOPE_API_KEY='your-api-key'
export AMAP_API_KEY='your-amap-key'
3. Install AMap MCP server
npm install -g @amap/amap-maps-mcp-server
Running Modes
- GUI Mode (Default) - Web Interface
bash
python MCP-demo01/assistant_mcp_amap_bot.py
Access http://localhost:8080 to start using
- TUI Mode - Terminal Interaction
python
Modify the end of the file to:
if name == 'main':
app_tui()
- Test Mode - Single Query
python
Modify the end of the file to:
if name == 'main':
test()
Example Queries
- Location Query:
Where is the specific address of the Forbidden City in Beijing?
- Route Planning:
What's the fastest way from Beijing South Railway Station to Tiananmen Square?
- Nearby Search:
Find me highly rated restaurants near West Lake
- Travel Planning:
Help me plan a two-day trip to Hangzhou, mainly visiting West Lake and Lingyin Temple
2. Text Processing Assistant (assistant_mcp_txt_bot.py)
Environment Preparation
bash
1. Install dependencies
pip install dashscope qwen-agent
2. Start local text counting service
cd MCP-demo01
python txt_counter.py
Running Modes
- GUI Mode (Default)
bash
python MCP-demo01/assistant_mcp_txt_bot.py
Access http://localhost:8080 to start using
- TUI Mode
python
Modify the end of the file to:
if name == 'main':
app_tui()
- Test Mode
python
Modify the end of the file to:
if name == 'main':
test()
Example Queries
- Basic Text Statistics:
Count the number of characters and lines in this text:
Hello World!
你好,世界!
こんにちは、世界!
- Code Analysis:
Count the effective lines of this Python code (excluding blank lines and comments):
def hello():
# This is a comment
print("Hello World!")
return True
- Text Formatting:
Format this JSON for me:
{"name":"John","age":30,"city":"New York"}
- Multilingual Analysis:
Analyze the character count of each language in this multilingual text:
你好世界 Hello World こんにちは
Notes
- An effective API key must be configured before using AMap features.
- Some features may require an internet connection.
- Ensure all dependencies are correctly installed.
Contribution Guidelines
We welcome issues and improvement suggestions! Please ensure before submitting:
- The code style conforms to the project standards.
- Appropriate test cases are added.
- Relevant documentation is updated.
License
This project is licensed under the MIT License. See the LICENSE file for details.