char-index-mcp

char-index-mcp

Character-level string manipulation tools via MCP server.

0
Stars
1
Forks
0
Watchers
0
Issues
char-index-mcp is a Model Context Protocol (MCP) server offering character-level, index-based string manipulation tools. It provides utilities for finding, splitting, and modifying strings with precise control over character positions, making it highly suited for test code generation that requires exact text handling. The server can be easily installed and integrated with platforms like Claude and Cursor, and features batch processing and regex-based utilities.

Key Features

Find nth occurrence of a character or substring
Retrieve all character or substring indices in text
Split strings at specified character indices
Insert text at an exact character position
Delete or replace character ranges within a string
Perform regex matching with position reporting
Extract text between specified markers
Provide detailed character statistics (letters, digits, etc.)
Batch extracting of multiple substrings
Integration-ready with uvx, Claude, and Cursor

Use Cases

Generating test code with strict string or character requirements
Validating output for correct character or substring placement
Automated string editing for development tools
Parsing and analyzing text for custom pipelines
Extracting specific content bounded by markers in code or data
Applying regex to match and locate patterns within input text
Splitting text for downstream processing based on custom logic
Improving LLM workflows that require exact text positioning
Assisting in building or testing compilers and tokenizers
Providing backend services for IDEs or code-assistant tools

README

char-index-mcp

A Model Context Protocol (MCP) server providing character-level index-based string manipulation. Perfect for test code generation where precise character positioning matters.

smithery badge License: MIT PyPI Python

This project was created with Claude AI.

🎯 Why This Exists

LLMs generate text token-by-token and struggle with exact character counting. When generating test code with specific length requirements or validating string positions, you need precise index-based tools. This MCP server solves that problem.

✨ Features (12 Tools)

🔍 Character & Substring Finding (4 tools)

  • find_nth_char - Find nth occurrence of a character
  • find_all_char_indices - Find all indices of a character
  • find_nth_substring - Find nth occurrence of a substring
  • find_all_substring_indices - Find all occurrences of a substring

✂️ Splitting (1 tool)

  • split_at_indices - Split string at multiple positions

✏️ String Modification (3 tools)

  • insert_at_index - Insert text at specific position
  • delete_range - Delete characters in range
  • replace_range - Replace range with new text

🛠️ Utilities (3 tools)

  • find_regex_matches - Find regex pattern matches with positions
  • extract_between_markers - Extract text between two markers
  • count_chars - Character statistics (total, letters, digits, etc.)

📦 Batch Processing (1 tool)

  • extract_substrings - Extract one or more substrings (unified tool)

🚀 Installation

Option 1: Using uvx (Recommended)

No installation required! Just configure and run:

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

Option 2: From PyPI

bash
pip install char-index-mcp

Option 3: From Source

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

🔧 Configuration

Claude Desktop

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

Windows: %APPDATA%\Claude\claude_desktop_config.json

Using uvx (Recommended)

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

Using pip install

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

Claude Code

bash
# 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

Add to ~/.cursor/mcp.json:

Using uvx (Recommended)

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

Using pip install

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

📖 Usage Examples

Finding Characters

python
# 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]

Working with Substrings

python
# 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]

String Manipulation

python
# 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"

Splitting & Extracting

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}
# ]

Pattern Matching

python
# 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"}
# ]

Extracting Text

python
# 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
# }

🧪 Development

bash
# 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

🎯 Use Cases

  1. Test Code Generation: Generate strings with exact character counts
  2. Data Processing: Split/extract data at precise positions
  3. Text Formatting: Insert/delete/replace at specific indices
  4. Pattern Analysis: Find and extract pattern matches with positions
  5. LLM Response Parsing: Extract content between XML tags by position

📝 Example: Test Code Generation

python
# 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)

🤝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Submit a pull request

📄 License

MIT License - see LICENSE file for details

🔗 Related Projects

📮 Contact

For issues, questions, or suggestions, please open an issue on GitHub.


Note: This is the first MCP server specifically designed for index-based string manipulation. All other text MCP servers focus on counting, case conversion, or encoding - not precise character positioning.

Star History

Star History Chart

Repository Owner

Repository Details

Language Python
Default Branch main
Size 21 KB
Contributors 1
License MIT License
MCP Verified Nov 12, 2025

Programming Languages

Python
97.88%
Dockerfile
2.12%

Tags

Join Our Newsletter

Stay updated with the latest AI tools, news, and offers by subscribing to our weekly newsletter.

We respect your privacy. Unsubscribe at any time.

Related MCPs

Discover similar Model Context Protocol servers

  • mcp-server-sql-analyzer

    mcp-server-sql-analyzer

    MCP server for SQL analysis, linting, and dialect conversion.

    Provides standardized MCP server capabilities for analyzing, linting, and converting SQL queries across multiple dialects using SQLGlot. Supports syntactic validation, dialect transpilation, extraction of table and column references, and offers tools for understanding query structures. Facilitates seamless workflow integration with AI assistants through a set of MCP tools.

    • 26
    • MCP
    • j4c0bs/mcp-server-sql-analyzer
  • AI Distiller (aid)

    AI Distiller (aid)

    Efficient codebase summarization and context extraction for AI code generation.

    AI Distiller enables efficient distillation of large codebases by extracting essential context, such as public interfaces and data types, discarding method implementations and non-public details by default. It helps AI agents like Claude, Cursor, and other MCP-compatible tools understand project architecture more accurately, reducing hallucinations and code errors. With configurable CLI options, it generates condensed contexts that fit within AI model limitations, improving code generation accuracy and integration with the Model Context Protocol.

    • 106
    • MCP
    • janreges/ai-distiller
  • Token Optimizer MCP

    Token Optimizer MCP

    Efficient token reduction for context window optimization in AI workflows

    Token Optimizer MCP is a server that reduces context window usage for AI tools by intelligently caching, compressing, and externally storing large content. It offers smart replacements for standard file and API operations, integrating seamlessly with tools such as Claude Desktop and other code assistants. The tool employs persistent caching with SQLite, high-ratio Brotli compression, and precise token counting to optimize both accuracy and efficiency. Production results indicate consistent 60-90% token usage reduction over tens of thousands of operations.

    • 6
    • MCP
    • ooples/token-optimizer-mcp
  • MCP Language Server

    MCP Language Server

    Bridge codebase navigation tools to AI models using MCP-enabled language servers.

    MCP Language Server implements the Model Context Protocol, allowing MCP-enabled clients, such as LLMs, to interact with language servers for codebase navigation. It exposes standard language server features—like go to definition, references, rename, and diagnostics—over MCP for seamless integration with AI tooling. The server supports multiple languages by serving as a proxy to underlying language servers, including gopls, rust-analyzer, and pyright.

    • 1,256
    • MCP
    • isaacphi/mcp-language-server
  • APISIX Model Context Protocol Server

    APISIX Model Context Protocol Server

    Bridge LLMs with APISIX for natural language API management.

    APISIX Model Context Protocol (MCP) Server enables large language models to interact with and manage APISIX resources via natural language commands. It provides a standardized protocol for connecting AI clients like Claude, Cursor, and Copilot to the APISIX Admin API. The server supports a range of operations including CRUD for routes, services, upstreams, plugins, security configurations, and more. Installation is streamlined via Smithery, npm, or direct source setup with customizable environment variables.

    • 29
    • MCP
    • api7/apisix-mcp
  • Memcord

    Memcord

    Privacy-first, self-hosted chat memory and context management for Claude and AI applications.

    Memcord serves as a self-hosted MCP (Model Context Protocol) server that enables users to securely organize, summarize, and search through their chat history with AI, especially for Claude, without compromising privacy. It offers intelligent memory management, conversation auto-summarization, deduplication, and context merging to build a searchable knowledge base across multiple conversations. Memcord also integrates seamlessly with Claude Desktop, VSCode, and supports various installation methods for flexibility.

    • 18
    • MCP
    • ukkit/memcord
  • Didn't find tool you were looking for?

    Be as detailed as possible for better results