From e0f4d3eaab3cc82741fac0ffe4a315c754af13f3 Mon Sep 17 00:00:00 2001 From: Evan Lin Date: Sun, 27 Apr 2025 18:41:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Add=20get=5Ffollower=5Fids=20to?= =?UTF-8?q?ol=20to=20retrieve=20user=20IDs=20of=20followers=20for=20LINE?= =?UTF-8?q?=20Official=20Account?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.ja.md | 15 ++++++++++++++- README.md | 22 ++++++++++++++++++---- src/index.ts | 26 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/README.ja.md b/README.ja.md index 8072469..e55e822 100644 --- a/README.ja.md +++ b/README.ja.md @@ -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 以上 このリポジトリをクローンします: @@ -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)に従って作成してください。 @@ -100,6 +112,7 @@ Claude DesktopやClaudeなどのAI Agentに次の設定を追加してくださ #### Option 2: Dockerを利用する場合 まずDockerイメージをビルドします: + ``` docker build -t line/line-bot-mcp-server . ``` diff --git a/README.md b/README.md index 3c30a23..40e6be3 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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). @@ -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 . ``` @@ -127,7 +141,7 @@ docker build -t line/line-bot-mcp-server . This project respects semantic versioning -See http://semver.org/ +See ## Contributing diff --git a/src/index.ts b/src/index.ts index ba4ff81..618184c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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."; @@ -213,6 +214,31 @@ 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"); From a537ed74845991135144399f88825a5ffae40b95 Mon Sep 17 00:00:00 2001 From: Evan Lin Date: Sun, 27 Apr 2025 18:46:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20Improve=20formatting=20of=20par?= =?UTF-8?q?ameters=20in=20get=5Ffollower=5Fids=20tool=20for=20better=20rea?= =?UTF-8?q?dability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 618184c..6a8f6bb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -218,8 +218,21 @@ 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."), + 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 { @@ -234,7 +247,9 @@ server.tool( }); return createSuccessResponse(res.data); } catch (error) { - return createErrorResponse(`Failed to get follower ids: ${error.message}`); + return createErrorResponse( + `Failed to get follower ids: ${error.message}`, + ); } }, );