diff --git a/README.ja.md b/README.ja.md index 278eec4..36c9b99 100644 --- a/README.ja.md +++ b/README.ja.md @@ -41,18 +41,29 @@ LINE公式アカウントとAI Agentを接続するために、LINE Messaging AP - LINE公式アカウントのメッセージ容量と消費量を取得します。月間メッセージ制限と現在の使用量が表示されます。 - **入力:** - なし +7. **get_follower_ids** + - LINE公式アカウントを友だち追加したユーザーのユーザーID一覧を取得します。 + - **入力:** + - `start` (string?): ページネーション用の継続トークン。省略時は先頭から取得します。 + - `limit` (number?): 取得するユーザーIDの最大数(1~1000)。デフォルトは1000。 + - **出力:** + - `userIds` (配列): ユーザーIDのリスト。 + - `next` (string?): 次ページ取得用トークン。存在する場合はこの値で再度リクエストしてください。 + - `total` (number?): ユーザーIDの総数(取得できる場合)。 + - **注意:** + - 認証済みまたはプレミアムアカウントのみ利用可能です。 + - 一部ユーザーIDはプライバシーやユーザー操作により取得できない場合があります(詳細は[こちら](https://developers.line.biz/ja/reference/messaging-api/#get-follower-ids-obtainable-ids)を参照してください)。 ## インストール (npxを使用) 要件: + - Node.js v20 以上 ### Step 1: LINE公式アカウントを作成 このMCP ServerはLINE公式アカウントを利用しています。公式アカウントをお持ちでない場合は、[こちらの手順](https://developers.line.biz/ja/docs/messaging-api/getting-started/#create-oa)に従って作成してください。 -LINE公式アカウントをお持ちであれば、[こちらの手順](https://developers.line.biz/ja/docs/messaging-api/getting-started/#using-oa-manager)に従ってMessaging APIを有効にしてください。 - ### Step 2: AI Agentを設定 Claude DesktopやClaudeなどのAI Agentに次の設定を追加してください。 @@ -96,6 +107,7 @@ git clone git@github.com:line/line-bot-mcp-server.git ``` Dockerイメージをビルドします: + ``` docker build -t line/line-bot-mcp-server . ``` diff --git a/README.md b/README.md index c32da85..08172d7 100644 --- a/README.md +++ b/README.md @@ -43,21 +43,34 @@ - Get the message quota and consumption of the LINE Official Account. This shows the monthly message limit and current usage. - **Inputs:** - None +7. **get_follower_ids** + - Gets the list of User IDs of users who have added your LINE Official Account as a friend. + - **Inputs:** + - `start` (string?): Continuation token for pagination. If omitted, fetches from the beginning. + - `limit` (number?): Maximum number of user IDs to retrieve (1-1000). Default is 1000. + - **Returns:** + - `userIds` (array): List of user IDs. + - `next` (string?): Token for the next page. If present, repeat the request with this value to get more user IDs. + - `total` (number?): 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 [documents](https://developers.line.biz/en/reference/messaging-api/#get-follower-ids-obtainable-ids) for details). ## Installation (Using npx) requirements: + - Node.js v20 or later ### Step 1: 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 2: 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: @@ -89,7 +102,6 @@ This MCP server utilizes a LINE Official Account. If you do not have one, please 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 2: Build line-bot-mcp-server image Clone this repository: @@ -115,7 +127,6 @@ Set the environment variables or arguments as follows: - `DESTINATION_USER_ID`: (optional) The default user ID of the recipient. If the Tool's input does not include `user_id`, `DESTINATION_USER_ID` is required. You can confirm this by following [this instructions](https://developers.line.biz/en/docs/messaging-api/getting-user-ids/#get-own-user-id). - ```json { "mcpServers": { @@ -144,7 +155,7 @@ You can confirm this by following [this instructions](https://developers.line.bi This project respects semantic versioning -See http://semver.org/ +See ## Contributing diff --git a/package-lock.json b/package-lock.json index 10579f8..7a9abab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@line/bot-sdk": "^9.8.0", "@modelcontextprotocol/sdk": "^1.8.0", + "axios": "^1.9.0", "zod": "^3.24.2" }, "bin": { @@ -569,15 +570,13 @@ "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "license": "MIT", - "optional": true + "license": "MIT" }, "node_modules/axios": { - "version": "1.8.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.8.4.tgz", - "integrity": "sha512-eBSYY4Y68NNlHbHBMdeDmKNtDgXWhQsJcGqzO3iLUM0GraQFSS9cVgPX5I9b3lbdFKyYoAEGAZF1DwhTaljNAw==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz", + "integrity": "sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==", "license": "MIT", - "optional": true, "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -660,7 +659,6 @@ "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", "license": "MIT", - "optional": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -756,7 +754,6 @@ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", "license": "MIT", - "optional": true, "engines": { "node": ">=0.4.0" } @@ -844,7 +841,6 @@ "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", "license": "MIT", - "optional": true, "dependencies": { "es-errors": "^1.3.0", "get-intrinsic": "^1.2.6", @@ -1161,7 +1157,6 @@ } ], "license": "MIT", - "optional": true, "engines": { "node": ">=4.0" }, @@ -1176,7 +1171,6 @@ "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz", "integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==", "license": "MIT", - "optional": true, "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -1192,7 +1186,6 @@ "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", "license": "MIT", - "optional": true, "engines": { "node": ">= 0.6" } @@ -1202,7 +1195,6 @@ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", "license": "MIT", - "optional": true, "dependencies": { "mime-db": "1.52.0" }, @@ -1357,7 +1349,6 @@ "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", "license": "MIT", - "optional": true, "dependencies": { "has-symbols": "^1.0.3" }, @@ -1781,8 +1772,7 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "license": "MIT", - "optional": true + "license": "MIT" }, "node_modules/pump": { "version": "3.0.2", @@ -2339,4 +2329,4 @@ } } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index bb32054..c4937be 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "dependencies": { "@line/bot-sdk": "^9.8.0", "@modelcontextprotocol/sdk": "^1.8.0", + "axios": "^1.9.0", "zod": "^3.24.2" }, "devDependencies": { diff --git a/src/index.ts b/src/index.ts index be097b7..087acf6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,6 +21,8 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js" import * as line from "@line/bot-sdk"; import { z } from "zod"; import { LINE_BOT_MCP_SERVER_VERSION, USER_AGENT } from "./version.js"; +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."; @@ -94,8 +96,8 @@ const flexMessageSchema = z.object({ .passthrough() .describe( "Flexible container structure following LINE Flex Message format. For 'bubble' type, can include header, " + - "hero, body, footer, and styles sections. For 'carousel' type, includes an array of bubble containers in " + - "the 'contents' property.", + "hero, body, footer, and styles sections. For 'carousel' type, includes an array of bubble containers in " + + "the 'contents' property.", ), }); @@ -126,7 +128,7 @@ server.tool( server.tool( "push_flex_message", "Push a highly customizable flex message to a user via LINE. Supports both bubble (single container) and carousel " + - "(multiple swipeable bubbles) layouts.", + "(multiple swipeable bubbles) layouts.", { userId: userIdSchema, message: flexMessageSchema, @@ -153,7 +155,7 @@ server.tool( server.tool( "broadcast_text_message", "Broadcast a simple text message via LINE to all users who have followed your LINE Official Account. Use this for sending " + - "plain text messages without formatting. Please be aware that this message will be sent to all users.", + "plain text messages without formatting. Please be aware that this message will be sent to all users.", { message: textMessageSchema, }, @@ -174,8 +176,8 @@ server.tool( server.tool( "broadcast_flex_message", "Broadcast a highly customizable flex message via LINE to all users who have added your LINE Official Account. " + - "Supports both bubble (single container) and carousel (multiple swipeable bubbles) layouts. Please be aware that " + - "this message will be sent to all users.", + "Supports both bubble (single container) and carousel (multiple swipeable bubbles) layouts. Please be aware that " + + "this message will be sent to all users.", { message: flexMessageSchema, }, @@ -229,6 +231,37 @@ 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( + "Value of the continuation token found in the next property of the JSON object returned in the response. Include this parameter to get the next array of user IDs. If omitted, fetches from the beginning.", + ), + limit: z + .int() + .min(1) + .max(1000) + .default(300) + .describe( + "Maximum number of user IDs to retrieve (1-1000). Default is 300.", + ), + }, + async ({ start, limit }: { start?: string; limit?: number }) => { + try { + const response = messagingApiClient.getFollowers(start, limit); + return createSuccessResponse(response); + } 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");