Skip to content

feat: 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
16 changes: 14 additions & 2 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -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。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `limit` (number?): 取得するユーザーIDの最大数(1~1000)。デフォルトは1000
- `limit` (number?): 取得するユーザーIDの最大数(1~1000)。デフォルトは300

- **出力:**
- `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を有効にしてください。

Comment on lines -54 to -55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This not should be removed.

### Step 2: AI Agentを設定

Claude DesktopやClaudeなどのAI Agentに次の設定を追加してください。
Expand Down Expand Up @@ -96,6 +107,7 @@ git clone [email protected]:line/line-bot-mcp-server.git
```

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

```
docker build -t line/line-bot-mcp-server .
```
Expand Down
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `limit` (number?): Maximum number of user IDs to retrieve (1-1000). Default is 1000.
- `limit` (number?): Maximum number of user IDs to retrieve (1-1000). Default is 300.

- **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:

Expand Down Expand Up @@ -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:
Expand All @@ -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": {
Expand Down Expand Up @@ -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 <http://semver.org/>

## Contributing

Expand Down
24 changes: 7 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
45 changes: 39 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Comment on lines +24 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 @@ -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.",
),
});

Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand Down Expand Up @@ -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");
Expand Down
Loading