home / mcp / python line mcp server

Python LINE MCP Server

Provides access to LINE Bot messages for AI workflows via MCP using Python and FastAPI.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "amornpan-py-mcp-line": {
      "command": "python",
      "args": [
        "server.py"
      ],
      "env": {
        "SERVER_PORT": "8000",
        "MESSAGES_FILE": "data/messages.json",
        "LINE_ACCESS_TOKEN": "your_access_token",
        "LINE_CHANNEL_SECRET": "your_channel_secret"
      }
    }
  }
}

This MCP server enables a Language Model to access LINE Bot messages by running a Python-based service that reads LINE conversations and exposes them through a Model Context Protocol interface. It supports asynchronous operation, robust validation, and JSON-formatted message storage, making it practical for integrating LINE data into AI workflows.

How to use

To use the LINE MCP Server with an MCP client, run the local Python server and configure the client to connect to the provided MCP endpoint. The server exposes resources describing available LINE message types and allows reading stored messages in JSON format. You can filter read results by date, user, or content to tailor the data you feed into your AI model.

How to install

Prerequisites: Python 3.8 or newer, and a working Python environment.

Clone the project repository and navigate into it.

Install dependencies from the requirements file.

Run the server with the appropriate environment variables set for LINE integration and data storage.

git clone https://github.com/amornpan/py-mcp-line.git
cd py-mcp-line
pip install -r requirements.txt

# Run the server
# Ensure the environment variables LINE_CHANNEL_SECRET, LINE_ACCESS_TOKEN, SERVER_PORT, and MESSAGES_FILE are set

Configuration and runtime notes

The server is configured via environment variables. Example values are provided in the configuration snippet that follows. The server stores LINE messages in a JSON file and exposes a REST-like MCP interface for resource listing and reading.

Environment variables shown for running the server include:

- LINE_CHANNEL_SECRET: your_channel_secret - LINE_ACCESS_TOKEN: your_access_token - SERVER_PORT: 8000 - MESSAGES_FILE: data/messages.json

Claude Desktop integration example

If you use Claude Desktop, add the following MCP server configuration to your Claude configuration file to connect to the local Python server.

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

Security and error handling

The server validates LINE signatures, handles webhook errors, and provides clean error messages for resource access, URI validation, and LINE API responses. All operations are validated through data models to prevent malformed input from propagating into the system.

Notes and troubleshooting

Ensure the .env or equivalent environment configuration is loaded properly so the server can access LINE credentials and the path to your message storage file. If the server cannot start due to missing environment variables, provide the required keys with valid values and retry.

Available tools

list_resources

Lists available LINE message types and returns resources with URIs in the form line://<type>/data, including descriptions and MIME types.

read_resource

Reads messages of a specified type from the line data and returns them in JSON format, with optional filters by date, user, or content.