Python LINE Server

Python LINE Server

python mcp LINE. Contribute to amornpan/py-mcp-line development by creating an account on GitHub.

AI集成系统
访问服务器

README

Python LINE MCP Server

Version Python MCP FastAPI License

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 initialization
    • server.py - Main server implementation
  • data/ - Data storage directory
    • messages.json - Stored LINE messages
  • tests/ - Test files directory
    • __init__.py - Test package initialization
    • test_line.py - LINE functionality tests
  • .env - Environment configuration file (not in git)
  • .env.example - Example environment configuration
  • .gitignore - Git ignore rules
  • README.md - Project documentation
  • Dockerfile - Docker configuration
  • requirements.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://<message_type>/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://<message_type>/data
  • Returns messages in JSON format
  • Supports filtering by date, user, or content

Usage with Claude Desktop

Add to your Claude Desktop configuration:

On MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json On Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "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"
      }
    }
  }
}

Error Handling

The server implements comprehensive error handling for:

  • Webhook validation failures
  • Message storage errors
  • Resource access errors
  • URI validation
  • LINE API response errors

All errors are logged and returned with appropriate error messages.

Security Features

  • Environment variable based configuration
  • LINE message signature validation
  • Proper error handling
  • Input validation through Pydantic

Contact Information

Amornpan Phornchaicharoen

Email LinkedIn HuggingFace GitHub

Feel free to reach out to me if you have any questions about this project or would like to collaborate!


Made with ❤️ by Amornpan Phornchaicharoen

Author

Amornpan Phornchaicharoen

Requirements

Create a requirements.txt file with:

fastapi>=0.104.1
pydantic>=2.10.6
uvicorn>=0.34.0 
python-dotenv>=1.0.1
line-bot-sdk>=3.5.0
anyio>=4.5.0
mcp==1.2.0

These versions have been tested and verified to work together. The key components are:

  • fastapi and uvicorn for the API server
  • pydantic for data validation
  • line-bot-sdk for LINE Bot integration
  • mcp for Model Context Protocol implementation
  • python-dotenv for environment configuration
  • anyio for asynchronous I/O support

Acknowledgments

  • LINE Developers for the LINE Messaging API
  • Model Context Protocol community
  • Python FastAPI community
  • Contributors to the python-dotenv project

推荐服务器

Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
mcp-server-qdrant

mcp-server-qdrant

这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。

官方
精选
AIO-MCP Server

AIO-MCP Server

🚀 集成了 AI 搜索、RAG 和多服务(GitLab/Jira/Confluence/YouTube)的一体化 MCP 服务器,旨在增强 AI 驱动的开发工作流程。来自 Folk。

精选
本地
https://github.com/Streen9/react-mcp

https://github.com/Streen9/react-mcp

react-mcp 与 Claude Desktop 集成,能够根据用户提示创建和修改 React 应用程序。

精选
本地
MCP Atlassian

MCP Atlassian

适用于 Atlassian Cloud 产品(Confluence 和 Jira)的 Model Context Protocol (MCP) 服务器。此集成专为 Atlassian Cloud 实例设计,不支持 Atlassian Server 或 Data Center 部署。

精选
any-chat-completions-mcp

any-chat-completions-mcp

将 Claude 与任何 OpenAI SDK 兼容的聊天完成 API 集成 - OpenAI、Perplexity、Groq、xAI、PyroPrompts 等。

精选
MySQL MCP Server

MySQL MCP Server

允许人工智能助手通过受控界面列出表格、读取数据和执行 SQL 查询,从而使数据库探索和分析更安全、更有条理。

精选
browser-use MCP server

browser-use MCP server

一个由人工智能驱动的浏览器自动化服务器,它实现了模型上下文协议,从而能够使用自然语言控制网页浏览器,以执行诸如导航、表单填写和视觉交互等任务。

精选
mcp-codex-keeper

mcp-codex-keeper

作为开发知识的守护者,为 AI 助手提供精心策划的最新文档和最佳实践访问权限。

精选