Skip to main content
Glama

find_matching_chunks_in_file

Locate specific code segments in a file by searching for matching strings or patterns, ideal for identifying function references or definitions within your project.

Instructions

Step 2: Find the actual matching chunks in a specific file.

Required after find_files_by_chunk_content or list_all_files_in_project to see
matches, as those tools only show files, not their contents.

This can be used for things like:
  - Finding all chunks in a file that make reference to a specific function
    (e.g. find_matching_chunks_in_file(..., ["my_funk"])
  - Finding a chunk where a specific function is defined
    (e.g. find_matching_chunks_in_file(..., ["def my_funk"])

Some chunks are split into multiple parts, because they are too large. This
will look like 'chunkx_part1', 'chunkx_part2', ...

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filter_YesMatch if any of these strings appear. Match all if None/null. Single empty string or empty list will match all.
project_nameYes
rel_pathYesRelative to project root

Implementation Reference

  • Handler function for the 'find_matching_chunks_in_file' tool, decorated with @mcp.tool(). It constructs a ProjectFile and delegates to the helper _list_chunks_in_file to find and list matching chunks.
    @mcp.tool()
    @log_inputs_outputs()
    def find_matching_chunks_in_file(
        project_name: str,
        rel_path: Annotated[pathlib.Path, Field(description="Relative to project root")],
        filter_: FilterType,
    ) -> ToolResponse:
        """Step 2: Find the actual matching chunks in a specific file.
    
        Required after find_files_by_chunk_content or list_all_files_in_project to see
        matches, as those tools only show files, not their contents.
    
        This can be used for things like:
          - Finding all chunks in a file that make reference to a specific function
            (e.g. find_matching_chunks_in_file(..., ["my_funk"])
          - Finding a chunk where a specific function is defined
            (e.g. find_matching_chunks_in_file(..., ["def my_funk"])
    
        Some chunks are split into multiple parts, because they are too large. This
        will look like 'chunkx_part1', 'chunkx_part2', ...
        """
        proj_file = ProjectFile(project_name=project_name, rel_path=rel_path)
        return _list_chunks_in_file(proj_file, filter_, "name_or_content").render()
  • Pydantic type definition for the filter_ parameter, which accepts a string, list of strings, or None to match chunks by name or content.
    FilterType = Annotated[
        str | list[str] | None,
        Field(
            description=(
                "Match if any of these strings appear. Match all if None/null. "
                "Single empty string or empty list will match all."
            ),
        ),
    ]
  • Helper function that filters chunks in a file based on the filter and filter_on criteria, formats their IDs with category and size, and returns a formatted MCPToolOutput.
    def _list_chunks_in_file(
        proj_file: ProjectFile,
        filter_: FilterType,
        filter_on: Literal["name", "name_or_content"],
    ) -> MCPToolOutput:
        target_file = proj_file.file
        chunks = [x for x in target_file.chunks if x.matches_filter(filter_, filter_on)]
        resp_data = [
            f"id={x.id_(path=target_file.abs_path)} (category={x.category} chars={len(x.content)})"
            for x in chunks
        ]
        resp_text = "\n".join(resp_data)
        chunk_info = f"({len(chunks)} of {len(target_file.chunks)} chunks)"
        return MCPToolOutput(text=f"{chunk_info}\n{resp_text}")
Behavior4/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 effectively describes key behavioral traits: it explains that some chunks are split into multiple parts due to size, and it clarifies that the tool shows actual content matches (not just file listings). However, it doesn't cover aspects like error handling, performance characteristics, or authentication requirements.

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

Conciseness5/5

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

The description is well-structured and appropriately sized. It starts with the core purpose, then provides usage context, followed by concrete examples, and ends with an important behavioral note about chunk splitting. Every sentence adds value with no redundant information.

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

Completeness4/5

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

For a tool with 3 parameters, no annotations, and no output schema, the description does a good job covering purpose, usage context, and key behavioral aspects. However, it doesn't describe what the output looks like (format, structure, or content of returned chunks), which would be important given the lack of output schema.

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

Parameters4/5

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

The schema description coverage is 67% (two of three parameters have descriptions). The description doesn't explicitly discuss individual parameters, but it provides valuable semantic context through usage examples that illustrate how the 'filter_' parameter works (e.g., '["my_funk"]' or '["def my_funk"]'). This adds meaningful guidance beyond what the schema provides about parameter usage.

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

Purpose5/5

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

The description clearly states the tool's purpose: 'Find the actual matching chunks in a specific file.' It specifies the verb ('find'), resource ('matching chunks'), and location ('in a specific file'), and distinguishes it from sibling tools like 'find_files_by_chunk_content' and 'list_all_files_in_project' by noting those only show files, not contents.

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

Usage Guidelines5/5

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

The description provides explicit usage guidelines: it states this tool is 'Required after find_files_by_chunk_content or list_all_files_in_project to see matches,' and gives concrete examples of when to use it (e.g., finding references to a function or where a function is defined). It clearly differentiates from alternatives by explaining the limitations of sibling tools.

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

Related 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/jurasofish/mcpunk'

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