Skip to content

Add get_follower_ids tool #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,25 @@ LINE公式アカウントとAI Agentを接続するために、LINE Messaging AP
- LINEユーザーの詳細なプロフィール情報を取得する。表示名、プロフィール画像URL、ステータスメッセージ、言語を取得できる。
- **Inputs:**
- `user_id` (string?): プロフィールを取得したいユーザーのユーザーID。デフォルトはDESTINATION_USER_ID。
6. **get_follower_ids**
- LINE公式アカウントを友だち追加したユーザーのユーザーID一覧を取得します。
- **入力:**
- `start` (string, オプション): ページネーション用の継続トークン。省略時は先頭から取得します。
- `limit` (number, オプション): 取得するユーザーIDの最大数(1~1000)。デフォルトは1000。
- **返却値:**
- `userIds` (配列): ユーザーIDのリスト。
- `next` (string, オプション): 次ページ取得用トークン。存在する場合はこの値で再度リクエストしてください。
- `total` (number, オプション): ユーザーIDの総数(取得できる場合)。
- **注意:**
- 認証済みまたはプレミアムアカウントのみ利用可能です。
- 一部ユーザーIDはプライバシーやユーザー操作により取得できない場合があります(詳細はLINE APIドキュメント参照)。

## インストール

### Step 1: line-bot-mcp-serverをインストール

要件:

- Node.js v20 以上

このリポジトリをクローンします:
Expand All @@ -55,7 +68,6 @@ Node.jsを利用する場合は、必要な依存関係をインストールし
cd line-bot-mcp-server && npm install && npm run build
```


### Step 2: LINE公式アカウントを作成

このMCP ServerはLINE公式アカウントを利用しています。公式アカウントをお持ちでない場合は、[こちらの手順](https://developers.line.biz/ja/docs/messaging-api/getting-started/#create-oa)に従って作成してください。
Expand Down Expand Up @@ -100,6 +112,7 @@ Claude DesktopやClaudeなどのAI Agentに次の設定を追加してくださ
#### Option 2: Dockerを利用する場合

まずDockerイメージをビルドします:

```
docker build -t line/line-bot-mcp-server .
```
Expand Down
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,25 @@
- Get detailed profile information of a LINE user including display name, profile picture URL, status message and language.
- **Inputs:**
- `user_id` (string?): The ID of the user whose profile you want to retrieve. Defaults to DESTINATION_USER_ID.

6. **get_follower_ids**
- Gets the list of User IDs of users who have added your LINE Official Account as a friend.
- **Inputs:**
- `start` (string, optional): Continuation token for pagination. If omitted, fetches from the beginning.
- `limit` (number, optional): Maximum number of user IDs to retrieve (1-1000). Default is 1000.
- **Returns:**
- `userIds` (array): List of user IDs.
- `next` (string, optional): Token for the next page. If present, repeat the request with this value to get more user IDs.
- `total` (number, optional): Total number of user IDs (if available).
- **Notes:**
- Only available for verified or premium accounts.
- Some user IDs may not be included due to privacy or user actions (see LINE API docs for details).

## Installation

### Step 1: Install line-bot-mcp-server

requirements:

- Node.js v20 or later

Clone this repository:
Expand All @@ -60,15 +72,16 @@ cd line-bot-mcp-server && npm install && npm run build

### Step 2: Create LINE Official Account

This MCP server utilizes a LINE Official Account. If you do not have one, please create it by following [this instructions](https://developers.line.biz/en/docs/messaging-api/getting-started/#create-oa).
This MCP server utilizes a LINE Official Account. If you do not have one, please create it by following [this instructions](https://developers.line.biz/en/docs/messaging-api/getting-started/#create-oa).

If you have a LINE Official Account, enable the Messaging API for your LINE Official Account by following [this instructions](https://developers.line.biz/en/docs/messaging-api/getting-started/#using-oa-manager).

### Step 3: Configure AI Agent

Please add the following configuration for an AI Agent like Claude Desktop or Cline.
Please add the following configuration for an AI Agent like Claude Desktop or Cline.

Set the environment variables or arguments as follows:

- `mcpServers.args`: (required) The path to `line-bot-mcp-server`.
- `CHANNEL_ACCESS_TOKEN`: (required) Channel Access Token. You can confirm this by following [this instructions](https://developers.line.biz/en/docs/basics/channel-access-token/#long-lived-channel-access-token).
- `DESTINATION_USER_ID`: (optional) The default user ID of the recipient. You can confirm this by following [this instructions](https://developers.line.biz/en/docs/messaging-api/getting-user-ids/#get-own-user-id).
Expand All @@ -95,6 +108,7 @@ Set the environment variables or arguments as follows:
#### Option 2: Use Docker

Build the Docker image first:

```
docker build -t line/line-bot-mcp-server .
```
Expand Down Expand Up @@ -127,7 +141,7 @@ docker build -t line/line-bot-mcp-server .

This project respects semantic versioning

See http://semver.org/
See <http://semver.org/>

## Contributing

Expand Down
41 changes: 41 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
import * as line from "@line/bot-sdk";
import { z } from "zod";
import pkg from "../package.json" with { type: "json" };
import axios from "axios";

const NO_USER_ID_ERROR =
"Error: Specify the userId or set the DESTINATION_USER_ID in the environment variables of this MCP Server.";
Expand Down Expand Up @@ -213,6 +214,46 @@ server.tool(
},
);

server.tool(
"get_follower_ids",
"Gets the list of User IDs of users who have added your LINE Official Account as a friend.",
{
start: z
.string()
.optional()
.describe(
"Continuation token for pagination. If omitted, fetches from the beginning.",
),
limit: z
.number()
.int()
.min(1)
.max(1000)
.optional()
.describe(
"Maximum number of user IDs to retrieve (1-1000). Default is 1000.",
),
},
async ({ start, limit }) => {
try {
const params = new URLSearchParams();
if (limit) params.append("limit", limit.toString());
if (start) params.append("start", start);
const res = await axios.get("https://api.line.me/v2/bot/followers/ids", {
params,
headers: {
Authorization: `Bearer ${channelAccessToken}`,
},
});
return createSuccessResponse(res.data);
} catch (error) {
return createErrorResponse(
`Failed to get follower ids: ${error.message}`,
);
}
},
);

async function main() {
if (!process.env.CHANNEL_ACCESS_TOKEN) {
console.error("Please set CHANNEL_ACCESS_TOKEN");
Expand Down