Skip to main content
Glama

char-index-mcp (アーカイブ済み)

このリポジトリはアーカイブされました。 本プロジェクトは char-index-skill に移行しました。現在は Claude Code Skill プラグインとして利用可能であり、MCP サーバーのサポートも継続されています。

今後の Skill および MCP サーバー (char-index-mcp) のアップデートは、新しいリポジトリから公開されます。


文字単位のインデックスベースの文字列操作を提供する Model Context Protocol (MCP) サーバーです。正確な文字位置が重要となるテストコード生成に最適です。

License: MIT PyPI Python

🎯 存在理由

LLM はテキストをトークン単位で生成するため、正確な文字数をカウントするのが苦手です。特定の長さの要件を持つテストコードを生成したり、文字列の位置を検証したりする場合、正確なインデックスベースのツールが必要です。この MCP サーバーはその問題を解決します。

✨ 機能 (12ツール)

🔍 文字と部分文字列の検索 (4ツール)

  • find_nth_char - 文字の n 番目の出現箇所を検索

  • find_all_char_indices - 文字のすべてのインデックスを検索

  • find_nth_substring - 部分文字列の n 番目の出現箇所を検索

  • find_all_substring_indices - 部分文字列のすべての出現箇所を検索

✂️ 分割 (1ツール)

  • split_at_indices - 複数の位置で文字列を分割

✏️ 文字列の変更 (3ツール)

  • insert_at_index - 特定の位置にテキストを挿入

  • delete_range - 指定範囲の文字を削除

  • replace_range - 指定範囲を新しいテキストに置換

🛠️ ユーティリティ (3ツール)

  • find_regex_matches - 正規表現パターンに一致する箇所と位置を検索

  • extract_between_markers - 2つのマーカー間のテキストを抽出

  • count_chars - 文字統計(合計、文字数、数字など)

📦 バッチ処理 (1ツール)

  • extract_substrings - 1つ以上の部分文字列を抽出(統合ツール)

🚀 インストール

オプション 1: uvx を使用 (推奨)

インストール不要!設定して実行するだけです:

# Test it works
uvx char-index-mcp --help

オプション 2: PyPI から

pip install char-index-mcp

オプション 3: ソースから

git clone https://github.com/agent-hanju/char-index-mcp.git
cd char-index-mcp
pip install -e .

🔧 設定

Claude Desktop

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

Windows: %APPDATA%\Claude\claude_desktop_config.json

uvx を使用 (推奨)

{
  "mcpServers": {
    "char-index": {
      "command": "uvx",
      "args": ["char-index-mcp"]
    }
  }
}

pip install を使用

{
  "mcpServers": {
    "char-index": {
      "command": "char-index-mcp"
    }
  }
}

Claude Code

# Using uvx (recommended)
claude mcp add char-index '{"command":"uvx","args":["char-index-mcp"]}'

# Using pip install
claude mcp add char-index '{"command":"char-index-mcp"}'

Cursor

~/.cursor/mcp.json に追加:

uvx を使用 (推奨)

{
  "mcpServers": {
    "char-index": {
      "command": "uvx",
      "args": ["char-index-mcp"]
    }
  }
}

pip install を使用

{
  "mcpServers": {
    "char-index": {
      "command": "char-index-mcp"
    }
  }
}

📖 使用例

文字の検索

# Find 3rd occurrence of 'l'
find_nth_char("hello world", "l", 3)  # Returns: 9

# Find all occurrences of 'l'
find_all_char_indices("hello world", "l")  # Returns: [2, 3, 9]

部分文字列の操作

# Find 2nd "hello"
find_nth_substring("hello hello world", "hello", 2)  # Returns: 6

# Find all occurrences
find_all_substring_indices("hello hello world", "hello")  # Returns: [0, 6]

文字列の操作

# Insert comma after "hello"
insert_at_index("hello world", 5, ",")  # Returns: "hello, world"

# Delete " world"
delete_range("hello world", 5, 11)  # Returns: "hello"

# Replace "world" with "Python"
replace_range("hello world", 6, 11, "Python")  # Returns: "hello Python"

分割と抽出

# Split at multiple positions
split_at_indices("hello world", [2, 5, 8])  # Returns: ["he", "llo", " wo", "rld"]

# Extract single character
extract_substrings("hello", [{"start": 1, "end": 2}])
# Returns: [{"start": 1, "end": 2, "substring": "e", "length": 1}]

# Batch extraction
extract_substrings("hello world", [
    {"start": 0, "end": 5},
    {"start": 6, "end": 11}
])
# Returns: [
#   {"start": 0, "end": 5, "substring": "hello", "length": 5},
#   {"start": 6, "end": 11, "substring": "world", "length": 5}
# ]

パターンマッチング

# Find all numbers with their positions
find_regex_matches("test123abc456", r"\d+")
# Returns: [
#   {"start": 4, "end": 7, "match": "123"},
#   {"start": 10, "end": 13, "match": "456"}
# ]

テキストの抽出

# Extract content between markers
extract_between_markers("start[content]end", "[", "]", 1)
# Returns: {
#   "content": "content",
#   "content_start": 6,
#   "content_end": 13,
#   "full_start": 5,
#   "full_end": 14
# }

🧪 開発

# Clone the repository
git clone https://github.com/agent-hanju/char-index-mcp.git
cd char-index-mcp

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Run with coverage
pytest --cov=char_index_mcp --cov-report=term-missing

🎯 ユースケース

  1. テストコード生成: 正確な文字数を持つ文字列を生成

  2. データ処理: 正確な位置でデータを分割・抽出

  3. テキストフォーマット: 特定のインデックスで挿入・削除・置換

  4. パターン分析: パターンマッチング箇所を位置情報付きで検索・抽出

  5. LLM レスポンス解析: XML タグ間のコンテンツを位置に基づいて抽出

📝 例: テストコード生成

# Ask Claude: "Generate a test string that's exactly 100 characters long"
# Claude can use count_chars() to verify the exact length

# Ask: "Find where the 5th comma is in this CSV line"
# Claude can use find_nth_char(csv_line, ",", 5)

# Ask: "Split this string at characters 10, 25, and 50"
# Claude can use split_at_indices(text, [10, 25, 50])

# Ask: "Extract the text between the 2nd <thinking> and </thinking> tags"
# Claude can use extract_between_markers(text, "<thinking>", "</thinking>", 2)

🤝 貢献

貢献を歓迎します!以下の手順に従ってください:

  1. リポジトリをフォークする

  2. フィーチャーブランチを作成する

  3. 新機能のテストを追加する

  4. プルリクエストを送信する

📄 ライセンス

MIT ライセンス - 詳細は LICENSE ファイルを参照してください

🔗 関連プロジェクト

📮 お問い合わせ

問題、質問、提案については、GitHub で Issue を作成してください。


注意: これはインデックスベースの文字列操作専用に設計された最初の MCP サーバーです。他のテキスト関連 MCP サーバーは、カウント、大文字小文字変換、エンコーディングに焦点を当てており、正確な文字位置の指定には対応していません。

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/agent-hanju/char-index-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server