Skip to main content
Glama

extract_between_markers

Extract text content between specified start and end markers, returning both the extracted text and its character position information for precise text analysis.

Instructions

Extract content between markers with positions. Returns dict with content and position info.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes
start_markerYes
end_markerYes
occurrenceNo

Implementation Reference

  • The complete handler function for the 'extract_between_markers' tool, including decorator for registration and inline schema via Annotated types. This implements the core logic to find and extract content between specified markers.
    @mcp.tool()
    def extract_between_markers(
        text: Annotated[str, "Text to search in"],
        start_marker: Annotated[str, "Opening marker"],
        end_marker: Annotated[str, "Closing marker"],
        occurrence: Annotated[int, "Which occurrence to extract (1-based)"] = 1
    ) -> dict:
        """Extract content between markers with positions. Returns dict with content and position info."""
        if not start_marker or not end_marker:
            raise ValueError("Markers cannot be empty")
        if occurrence < 1:
            raise ValueError("occurrence must be >= 1")
        
        count = 0
        search_start = 0
        
        while True:
            start_idx = text.find(start_marker, search_start)
            if start_idx == -1:
                return {
                    "content": None,
                    "content_start": None,
                    "content_end": None,
                    "full_start": None,
                    "full_end": None
                }
            
            content_start = start_idx + len(start_marker)
            end_idx = text.find(end_marker, content_start)
            
            if end_idx == -1:
                return {
                    "content": None,
                    "content_start": None,
                    "content_end": None,
                    "full_start": None,
                    "full_end": None
                }
            
            count += 1
            if count == occurrence:
                return {
                    "content": text[content_start:end_idx],
                    "content_start": content_start,
                    "content_end": end_idx,
                    "full_start": start_idx,
                    "full_end": end_idx + len(end_marker)
                }
            
            search_start = content_start
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the return type (dict with content and position info), but doesn't cover critical aspects like error handling (e.g., if markers are not found), performance implications, or whether the extraction is case-sensitive. This leaves significant gaps for a tool with 4 parameters.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose. However, it could be more structured by separating usage details from return value, but it avoids unnecessary verbosity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (4 parameters, no annotations, no output schema), the description is incomplete. It lacks details on parameter usage, error cases, and behavioral traits, making it inadequate for safe and effective tool invocation by an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It doesn't explain any parameters beyond what the schema titles imply (e.g., 'occurrence' with default 1 is not clarified). No additional meaning is provided for 'text', 'start_marker', 'end_marker', or how 'occurrence' affects extraction.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('extract') and resource ('content between markers'), specifying it returns a dict with content and position info. However, it doesn't explicitly differentiate from sibling tools like 'extract_substrings' or 'find_regex_matches', which might offer similar extraction capabilities.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'extract_substrings' or 'find_regex_matches'. The description implies usage for extracting content between markers but lacks explicit context, prerequisites, or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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