> ## Documentation Index
> Fetch the complete documentation index at: https://shinydapps-bd9fa40b.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP Server

> l402-kit をMCPツールとして追加することで、Claude Desktop、Cursor、およびMCP対応AIがLightning APIに自動的に支払いを行えるようになります。

## MCPとは？

[Model Context Protocol](https://modelcontextprotocol.io) は、LLMが外部ツールにアクセスできるようにするAnthropicのオープン標準です。l402-kit には2つのカテゴリのツールを備えた既製のMCPサーバーが付属しています：

### 汎用 L402 ツール

| ツール                    | 説明                             |
| ---------------------- | ------------------------------ |
| `l402_fetch`           | 任意のURLを取得 — 402が返された場合は自動的に支払い |
| `l402_balance`         | Lightning の残余予算を確認             |
| `l402_spending_report` | セッション中の支払いの完全な内訳               |

### VERITY ツール — 有料サービス、自動支払い対応

| ツール                   |          価格 | 説明                            |
| --------------------- | ----------: | ----------------------------- |
| `verity_btc_price`    |     10 sats | USD、EUR、BRL でのリアルタイム BTC 価格   |
| `verity_worldstate`   |     80 sats | UTC 時刻 + ジオロケーション + 現地の天気     |
| `verity_search`       |    100 sats | ウェブ検索、上位10件のオーガニック結果          |
| `verity_summarize`    |     50 sats | 最大50,000文字のAI要約               |
| `verity_sentiment`    |     30 sats | センチメントスコア + キーワード             |
| `verity_scrape`       |    200 sats | ウェブスクレイピングによるクリーンなmarkdown生成  |
| `verity_domain_intel` |    500 sats | WHOIS + DNS + SSL証明書          |
| `verity_translate`    |     50 sats | 11ロケール対応のAI翻訳、MDX対応           |
| `verity_integration`  | 10,000 sats | 任意のGitHubリポジトリへの完全なl402-kit統合 |

VERITY ツールは自律的に支払いを行います — 手動でのインボイス処理は不要です。

***

## Claude Desktop でのセットアップ

### 1. Node.js ≥ 18 をインストール

### 2. ウォレットを設定する

<Tabs>
  <Tab title="Blink">
    `claude_desktop_config.json` を編集します：

    ```json theme={null}
    {
      "mcpServers": {
        "l402": {
          "command": "npx",
          "args": ["l402-kit-mcp"],
          "env": {
            "BLINK_API_KEY": "your-blink-api-key",
            "BLINK_WALLET_ID": "your-wallet-id",
            "BUDGET_SATS": "2000"
          }
        }
      }
    }
    ```
  </Tab>

  <Tab title="Alby">
    ```json theme={null}
    {
      "mcpServers": {
        "l402": {
          "command": "npx",
          "args": ["l402-kit-mcp"],
          "env": {
            "ALBY_TOKEN": "your-alby-access-token",
            "BUDGET_SATS": "2000"
          }
        }
      }
    }
    ```

    セルフホストの Alby Hub の場合は以下を追加します：

    ```json theme={null}
    "ALBY_HUB_URL": "https://your-hub.example.com"
    ```
  </Tab>
</Tabs>

**設定ファイルの場所：**

* macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
* Windows: `%APPDATA%\Claude\claude_desktop_config.json`

### 3. Claude Desktop を再起動する

`l402_fetch`、`l402_balance`、`l402_spending_report` のツールがClaudeのツール一覧に表示されます。

***

## 環境変数

| 変数                |    必須    | 説明                           |
| ----------------- | :------: | ---------------------------- |
| `BLINK_API_KEY`   | Blink のみ | Blink APIキー                  |
| `BLINK_WALLET_ID` | Blink のみ | Blink ウォレットID                |
| `ALBY_TOKEN`      |  Alby のみ | Alby アクセストークン                |
| `ALBY_HUB_URL`    |    任意    | カスタム Alby Hub のベースURL        |
| `BUDGET_SATS`     |    任意    | セッションあたりの最大支出額（デフォルト：`2000`） |

***

## ツールの使い方

サーバーが起動すると、ClaudeはVERITYおよびL402で保護された任意のAPIを自律的に呼び出せます：

```
You: What's the BTC price right now?

Claude: [calls verity_btc_price]
        [Paid 10 sats] {"bitcoin":{"usd":97500,"eur":89800,"brl":548000}}

        Bitcoin is currently $97,500 USD (Cost: 10 sats)
```

```
You: Summarize this article: <pastes 5,000 words>

Claude: [calls verity_summarize with text="..."]
        [Paid 50 sats] {"summary":"..."}
```

```
You: Search for "lightning network adoption 2026"

Claude: [calls verity_search with q="lightning network adoption 2026"]
        [Paid 100 sats] {"results":[...]}
```

```
You: How much have I spent so far?

Claude: [calls l402_spending_report]
        === L402 Spending Report ===
        Total spent:  160 sats
        Remaining:    1840 sats

        By domain:
          l402kit.com: 160 sats
```

***

## HTTP MCP エンドポイント

stdioパッケージに加えて、VERITYはライブの **HTTP MCP サーバー** を公開しています — インストール不要です：

```
POST https://l402kit.com/api/mcp
Content-Type: application/json
```

ストリーム可能なHTTPトランスポートをサポートする任意のMCPクライアントが直接接続できます。Blinkの認証情報をヘッダーとして渡してください：

```
X-BLINK-API-KEY: your-blink-api-key
X-BLINK-WALLET-ID: your-wallet-id
```

**初期化：**

```json theme={null}
{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"my-agent","version":"1.0"}},"id":1}
```

**ツール一覧の取得：**

```json theme={null}
{"jsonrpc":"2.0","method":"tools/list","params":{},"id":2}
```

**ツールの呼び出し：**

```json theme={null}
{"jsonrpc":"2.0","method":"tools/call","params":{"name":"verity_btc_price","arguments":{}},"id":3}
```

このエンドポイントはウォレットの認証情報を使って Lightning インボイスを自動的に支払い、VERITY の結果を直接返します。

***

## MCP レジストリ

l402-kit は主要なMCPレジストリすべてに登録されています：

| レジストリ                      | リンク                                                                                            |
| -------------------------- | ---------------------------------------------------------------------------------------------- |
| Anthropic MCP Registry（公式） | `io.github.ThiagoDataEngineer/l402-kit`                                                        |
| Glama                      | [glama.ai/mcp/servers/@ShinyDapps/l402-kit](https://glama.ai/mcp/servers/@ShinyDapps/l402-kit) |
| Smithery                   | [smithery.ai/servers/shinydapps/l402-kit](https://smithery.ai/servers/shinydapps/l402-kit)     |
| mcp.so                     | `l402-kit` で検索                                                                                 |

マシンリーダブルなマニフェスト：`GET https://l402kit.com/.well-known/mcp.json`

***

## Cursor でのセットアップ

**Settings → MCP Servers** にある Cursor のMCP設定に同じ設定ブロックを追加してください。

***

## 任意のMCPクライアントでのセットアップ

サーバーは `stdin` から読み取り、`stdout` に書き込みます（stdioトランスポート）：

```bash theme={null}
BLINK_API_KEY=xxx BLINK_WALLET_ID=yyy BUDGET_SATS=500 npx l402-kit-mcp
```

MCP対応の任意のクライアントがstdioトランスポートを使って接続できます。

***

## カスタムMCPサーバーの構築

`L402Client` を独自のMCPサーバーに直接組み込むこともできます：

```typescript theme={null}
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { L402Client, BlinkWallet } from "l402-kit";
import { z } from "zod";

const client = new L402Client({
  wallet: new BlinkWallet(process.env.BLINK_API_KEY!, process.env.BLINK_WALLET_ID!),
  budgetSats: 1000,
});

const server = new McpServer({ name: "my-agent", version: "1.0.0" });

server.tool(
  "fetch_weather",
  "Get current weather for a city — pays automatically",
  { city: z.string() },
  async ({ city }) => {
    const res = await client.fetch(`https://api.weather.com/current?city=${city}`);
    const text = await res.text();
    return { content: [{ type: "text", text }] };
  },
);

const transport = new StdioServerTransport();
await server.connect(transport);
```

***

## セキュリティに関する注意事項

* 予算の上限（`BUDGET_SATS`）が主要な安全策です — 保守的な値を設定してください
* 各 `npx l402-kit-mcp` プロセスは独自のインメモリ予算を持ちます；再起動するとリセットされます
* プロダクション環境のエージェントでは、`onSpend` コールバックを通じて支払いログを外部ストアに永続化してください
