char-index-mcp
char-index-mcp (已归档)
此仓库已归档。 该项目已迁移至 char-index-skill,现作为 Claude Code Skill 插件提供,并继续支持 MCP 服务器。
未来对该 Skill 和 MCP 服务器 (
char-index-mcp) 的更新将从新仓库发布。
一个提供基于字符级索引的字符串操作的模型上下文协议 (MCP) 服务器。非常适合需要精确字符定位的测试代码生成场景。
🎯 存在意义
大语言模型按 Token 生成文本,难以处理精确的字符计数。在生成有特定长度要求的测试代码或验证字符串位置时,你需要基于索引的精确工具。此 MCP 服务器正是为了解决该问题。
Related MCP server: MCP Character Tools
✨ 功能 (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- 提取两个标记之间的文本count_chars- 字符统计(总数、字母、数字等)
📦 批量处理 (1 个工具)
extract_substrings- 提取一个或多个子字符串(统一工具)
🚀 安装
选项 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 安装
{
"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 安装
{
"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🎯 应用场景
测试代码生成:生成具有精确字符计数的字符串
数据处理:在精确位置分割/提取数据
文本格式化:在特定索引处插入/删除/替换
模式分析:查找并提取带有位置信息的模式匹配项
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)🤝 贡献
欢迎贡献!请:
Fork 本仓库
创建功能分支
为新功能添加测试
提交 Pull Request
📄 许可证
MIT 许可证 - 详情请参阅 LICENSE 文件
🔗 相关项目
mcp-character-counter - 字符计数与分析
mcp-wordcounter - 文件单词与字符计数
text-master-mcp - 综合文本处理工具包
📮 联系方式
如有问题、疑问或建议,请在 GitHub 上提交 Issue。
注意:这是第一个专门为基于索引的字符串操作而设计的 MCP 服务器。所有其他文本 MCP 服务器都侧重于计数、大小写转换或编码,而非精确的字符定位。
Available Tools
12 toolscount_charsB
Count character statistics. Returns dict with total, without_spaces, letters, digits, spaces, special.
Inputs: text (required).
delete_rangeC
Delete characters in range [start, end).
Inputs: text (required), start (required), end (required). Returns: result
extract_between_markersC
Extract content between markers with positions. Returns dict with content and position info.
Inputs: text (required), start_marker (required), end_marker (required), occurrence.
extract_substringsB
Extract substrings by index ranges. Supports negative indices and omitting end. Returns list of {start, end, substring, length} dicts.
Inputs: text (required), ranges (required). Returns: result
find_all_char_indicesA
Find all indices where a character appears. Returns empty list if not found.
Inputs: text (required), char (required). Returns: result
find_all_substring_indicesB
Find all starting indices where a substring appears (includes overlaps).
Inputs: text (required), substring (required). Returns: result
find_nth_charA
Find index of nth occurrence of a character. Returns -1 if not found.
Inputs: text (required), char (required), n. Returns: result
find_nth_substringA
Find starting index of nth occurrence of a substring. Returns -1 if not found.
Inputs: text (required), substring (required), n. Returns: result
find_regex_matchesB
Find all regex matches with positions. Returns list of {start, end, match} dicts.
Inputs: text (required), pattern (required). Returns: result
insert_at_indexC
Insert text at index position without replacing. Supports negative indices.
Inputs: text (required), index (required), insertion (required). Returns: result
replace_rangeB
Replace characters in range [start, end) with new text.
Inputs: text (required), start (required), end (required), replacement (required). Returns: result
split_at_indicesB
Split text at exact index positions. Indices auto-sorted and deduplicated.
Inputs: text (required), indices (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 12 tools
Each tool has a clearly distinct purpose with no overlap: character counting, deletion, extraction, finding indices, regex matching, insertion, replacement, and splitting. The descriptions precisely differentiate operations like find_all_char_indices vs find_nth_char, and extract_between_markers vs extract_substrings.
All tools follow a consistent snake_case verb_noun pattern (e.g., count_chars, delete_range, extract_between_markers). The naming is predictable and readable throughout, with verbs like count, delete, extract, find, insert, replace, and split consistently applied.
12 tools are well-scoped for a character/index manipulation server, covering essential operations without bloat. Each tool earns its place by addressing specific needs like character statistics, range operations, substring extraction, and pattern matching.
The toolset provides complete coverage for text manipulation tasks: counting, insertion, deletion, replacement, extraction, finding indices (both character and substring), regex matching, and splitting. There are no obvious gaps; agents can perform a full lifecycle of operations on text data.
Maintenance
Related MCP Connectors
Exact text tools for AI agents: unified diff, patch apply, regex testing, grapheme counting.
Exact character/word counting, reversal, palindrome checks, indexing, sorting; Unicode-safe.
300+ deterministic data utilities for AI agents: validate, normalize, parse, match, redact.
Token counting, RAG chunking, truncation, HTML to Markdown and JSON repair
Related MCP Servers
- AlicenseAqualityNot gradedmaintenanceEnables agents to quickly find and edit code in a codebase with surgical precision. Find symbols, edit them everywhere with tools for reading code blocks, searching/replacing text, and making precise line-based modifications.311 npm-
- AlicenseAqualityDmaintenanceProvides 14+ character-level text analysis tools that give LLMs the ability to accurately count letters, analyze individual characters, and work with text at the character level—overcoming tokenization limitations.143MIT
- AlicenseBqualityBmaintenanceEnables LLMs to efficiently read, write, and refactor code using precise AST-based operations, reducing token usage and context window waste.25238 npm3MIT
- AlicenseNot gradedqualityDmaintenanceEnables precise code extraction from 30+ languages using tree-sitter parsing, allowing AI assistants to retrieve functions, classes, and code snippets with accurate line numbers.23 PyPI8MIT