
Python MCP 线路
概览
一个用 Python 实现的模型上下文协议服务器,提供访问 LINE 机器人消息的权限。该服务器使语言模型能够通过标准化接口读取和分析 LINE 对话。 * 使用 Python 的 asyncio 异步操作 * 基于环境的配置 Python dotenv * 全面的日志系统 * LINE 机器人 webhook 事件处理 * JSON 格式的消息存储 * API 端点的快速API集成 * 数据验证用Pydantic模型 * 支持文本、贴纸和图片消息 * Python 3.8+ * Required Python packages: * fastapi * pydantic * python-dotenv * mcp-server * line-bot-sdk * uvicorn * src/line/ - 主源代码目录 * .py - 包初始化 * server.py - 主服务器实现 * data/ - 数据存储目录 * messages.json - 存储的LINE消息 * tests/ - 测试文件目录 * .py - 测试包初始化 * test_line.py - LINE功能测试 * 。
概述(AI 翻译)
一个用 Python 实现的模型上下文协议服务器,提供访问 LINE 机器人消息的权限。该服务器使语言模型能够通过标准化接口读取和分析 LINE 对话。
特色
核心功能
- 使用 Python
asyncio的异步操作 - 基于环境的配置,使用
python-dotenv - 综合记录系统
- LINE 机器人网络钩事件处理
- JSON 格式的消息存储
- API端点的FastAPI集成
- 用于数据验证的意向模型
- 支持文本、贴纸和图片信息
先修条件
- Python 3.8+
- 必备的 Python 包:
- Fastapi
- 皮丹特
- python-dotenv
- MCP-服务器
- line-bot-sdk
- 独角兽
安装
项目结构
目录结构解释
src/line/- 主源代码目录__init__.py- 包初始化server.py- 主服务器实现data/- 数据存储目录messages.json- 存储的LINE消息tests/- 测试文件目录__init__.py- 测试包初始化test_line.py- LINE 功能测试.env- 环境配置文件(不在 git 中)- '.环境。
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Python LINE MCP Server
A Model Context Protocol server implementation in Python that provides access to LINE Bot messages. This server enables Language Models to read and analyze LINE conversations through a standardized interface.
Features
Core Functionality
- Asynchronous operation using Python’s
asyncio - Environment-based configuration using
python-dotenv - Comprehensive logging system
- LINE Bot webhook event handling
- Message storage in JSON format
- FastAPI integration for API endpoints
- Pydantic models for data validation
- Support for text, sticker, and image messages
Prerequisites
- Python 3.8+
- Required Python packages:
- fastapi
- pydantic
- python-dotenv
- mcp-server
- line-bot-sdk
- uvicorn
Installation
git clone https://github.com/amornpan/py-mcp-line.git
cd py-mcp-line
pip install -r requirements.txt
Project Structure
PY-MCP-LINE/
├── src/
│ └── line/
│ ├── __init__.py
│ └── server.py
├── data/
│ └── messages.json
├── tests/
│ ├── __init__.py
│ └── test_line.py
├── .env
├── .env.example
├── .gitignore
├── README.md
├── Dockerfile
└── requirements.txt
Directory Structure Explanation
src/line/- Main source code directory__init__.py- Package initializationserver.py- Main server implementation
data/- Data storage directorymessages.json- Stored LINE messages
tests/- Test files directory__init__.py- Test package initializationtest_line.py- LINE functionality tests
.env- Environment configuration file (not in git).env.example- Example environment configuration.gitignore- Git ignore rulesREADME.md- Project documentationDockerfile- Docker configurationrequirements.txt- Project dependencies
Configuration
Create a .env file in the project root:
LINE_CHANNEL_SECRET=your_channel_secret
LINE_ACCESS_TOKEN=your_access_token
SERVER_PORT=8000
MESSAGES_FILE=data/messages.json
API Implementation Details
Resource Listing
@app.list_resources()
async def list_resources() -> list[Resource]
- Lists available message types from the LINE Bot
- Returns resources with URIs in the format
line:///data - Includes resource descriptions and MIME types
Resource Reading
@app.read_resource()
async def read_resource(uri: AnyUrl) -> str
- Reads messages of the specified type
- Accepts URIs in the format
line:///data
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →配置
{
"mcpServers": {
"line": {
"command": "python",
"args": [
"server.py"
],
"env": {
"LINE_CHANNEL_SECRET": "your_channel_secret",
"LINE_ACCESS_TOKEN": "your_access_token",
"SERVER_PORT": "8000",
"MESSAGES_FILE": "data/messages.json"
}
}
}
}