Skip to main content
Glama
4geru

MCP LINE Server

by 4geru
README.md
# MCP × LINE ハンズオン

AI に「LINE を送る力」を授ける MCP サーバーを作るハンズオン用リポジトリです。

## このリポジトリについて

このリポジトリは、**MCP (Model Context Protocol)** を使って、AI が LINE にメッセージを送れるようにするハンズオンのスターターキットです。

MCP サーバーを 0 から作成し、以下の機能を実装します:

- ✅ テキストメッセージの送信
- ✅ スタンプの送信
- ✅ Flex Message(リッチメッセージ)の送信
- ✅ Quota API による送信数の確認

## 必要なもの

- GitHub アカウント
- LINE アカウント
- Gemini API キー([Google AI Studio](https://aistudio.google.com/app/apikey) から取得)

## セットアップ

### 1. このリポジトリを Fork する

右上の **「Fork」** ボタンをクリックして、自分のアカウントにフォークしてください。

### 2. GitHub Codespaces で開く

1. **「Code」** ボタンをクリック
2. **「Codespaces」** タブを選択
3. **「Create codespace on main」** をクリック

### 3. 環境変数を設定

`.env.sample` をコピーして `.env` ファイルを作成します:

```bash
cp .env.sample .env
```

`.env` ファイルを編集して、以下の値を設定してください:

```bash
# Gemini API Key
GEMINI_API_KEY=your_gemini_api_key_here

# LINE Messaging API
LINE_CHANNEL_ACCESS_TOKEN=your_line_channel_access_token_here
LINE_USER_ID=your_line_user_id_here
```

### 4. 依存パッケージをインストール

```bash
npm install
```

### 5. ビルド

```bash
npm run build
```

### 6. Gemini CLI に MCP サーバーを登録

```bash
gemini mcp add line-server node ~/mcp-line-handson/dist/index.js
```

### 7. Gemini CLI を起動

```bash
gemini
```

### 8. 動作確認

Gemini CLI で以下のコマンドを実行して、MCP サーバーが正しく登録されているか確認します:

```
> /mcp
```

足し算ツールを試してみましょう:

```
> 5 + 3 は?
```

## ハンズオン資料

詳しい手順は、Zenn Book を参照してください:

📚 **[【MCP×LINE】AIに「LINEを送る力」を授けよう!](https://zenn.dev/books/mcp-line-handson)**

## プロジェクト構成

```
mcp-line-handson/
├── src/
│   └── index.ts          # MCP サーバーのメインファイル
├── dist/                 # ビルド出力先(自動生成)
├── .env.sample           # 環境変数のサンプル
├── .env                  # 環境変数(Git管理外)
├── package.json          # npm 設定
├── tsconfig.json         # TypeScript 設定
└── README.md             # このファイル
```

## 開発

TypeScript を編集した場合は、ビルドしてから Gemini CLI を再起動してください。

```bash
npm run build
gemini mcp remove line-server
gemini mcp add line-server node ~/mcp-line-handson/dist/index.js
gemini
```

## トラブルシューティング

### MCP サーバーが認識されない

- `npm run build` でビルドが成功しているか確認
- `gemini mcp list` で登録されているか確認
- Gemini CLI を再起動してみる

### LINE にメッセージが送れない

- `.env` ファイルの `LINE_CHANNEL_ACCESS_TOKEN` と `LINE_USER_ID` が正しく設定されているか確認
- LINE 公式アカウントを友だち追加しているか確認
- LINE Developers コンソールでチャネルアクセストークンが有効か確認

## 参考リンク

- [MCP 公式サイト](https://modelcontextprotocol.io/)
- [Gemini CLI (GitHub)](https://github.com/google-gemini/gemini-cli)
- [LINE Messaging API ドキュメント](https://developers.line.biz/ja/docs/messaging-api/)
- [LINE Developers](https://developers.line.biz/console/)

## ライセンス

MIT

## 作者

このハンズオンは Zenn Book と連動しています。詳しくは [Zenn Book](https://zenn.dev/books/mcp-line-handson) をご覧ください。

TDQS

B3.4/5.0

Scored across 1 tool

Disambiguation5/5

With only one tool, there is no possibility of ambiguity or overlap between tools, as there are no other tools to confuse it with. The tool's purpose is clearly distinct by default.

Naming Consistency5/5

A single tool inherently has perfect naming consistency, as there are no other tools to compare it against for patterns or conventions. The name 'add' is straightforward and follows a simple verb pattern.

Tool Count2/5

A single tool for a server named 'MCP LINE Server' suggests a very limited scope, likely too thin for practical use unless it's a minimal utility. Typically, servers have 3-15 tools for adequate functionality, so this is borderline but leans toward being insufficient.

Completeness1/5

The server appears to be for mathematical operations based on the tool description, but with only an 'add' tool, there are severe gaps—no subtraction, multiplication, division, or other basic operations. This makes the surface incomplete for any meaningful mathematical domain.

Maintenance

ActivityInactive
ResponsivenessNo issues