Skip to main content
Glama
lin2000wl

Serena MCP Server

by lin2000wl

search_for_pattern

Search for patterns in code and non-code files using regular expressions, with options to restrict by file type, path, or glob patterns and include context lines around matches.

Instructions

Offers a flexible search for arbitrary patterns in the codebase, including the possibility to search in non-code files. Generally, symbolic operations like find_symbol or find_referencing_symbols should be preferred if you know which symbols you are looking for.

Pattern Matching Logic: For each match, the returned result will contain the full lines where the substring pattern is found, as well as optionally some lines before and after it. The pattern will be compiled with DOTALL, meaning that the dot will match all characters including newlines. This also means that it never makes sense to have .* at the beginning or end of the pattern, but it may make sense to have it in the middle for complex patterns. If a pattern matches multiple lines, all those lines will be part of the match. Be careful to not use greedy quantifiers unnecessarily, it is usually better to use non-greedy quantifiers like .*? to avoid matching too much content.

File Selection Logic: The files in which the search is performed can be restricted very flexibly. Using restrict_search_to_code_files is useful if you are only interested in code symbols (i.e., those symbols that can be manipulated with symbolic tools like find_symbol). You can also restrict the search to a specific file or directory, and provide glob patterns to include or exclude certain files on top of that. The globs are matched against relative file paths from the project root (not to the relative_path parameter that is used to further restrict the search). Smartly combining the various restrictions allows you to perform very targeted searches. Returns A JSON object mapping file paths to lists of matched consecutive lines (with context, if requested).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
substring_patternYesRegular expression for a substring pattern to search for.
context_lines_beforeNoNumber of lines of context to include before each match.
context_lines_afterNoNumber of lines of context to include after each match.
paths_include_globNoOptional glob pattern specifying files to include in the search. Matches against relative file paths from the project root (e.g., "*.py", "src/**/*.ts"). Only matches files, not directories.
paths_exclude_globNoOptional glob pattern specifying files to exclude from the search. Matches against relative file paths from the project root (e.g., "*test*", "**/*_generated.py"). Takes precedence over paths_include_glob. Only matches files, not directories.
relative_pathNoOnly subpaths of this path (relative to the repo root) will be analyzed. If a path to a single file is passed, only that will be searched. The path must exist, otherwise a `FileNotFoundError` is raised.
restrict_search_to_code_filesNoWhether to restrict the search to only those files where analyzed code symbols can be found. Otherwise, will search all non-ignored files. Set this to True if your search is only meant to discover code that can be manipulated with symbolic tools. For example, for finding classes or methods from a name pattern. Setting to False is a better choice if you also want to search in non-code files, like in html or yaml files, which is why it is the default.
max_answer_charsNoIf the output is longer than this number of characters, no content will be returned. Don't adjust unless there is really no other way to get the content required for the task. Instead, if the output is too long, you should make a stricter query.
Behavior5/5

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

Since no annotations are provided, the description carries the full burden of behavioral disclosure. It thoroughly explains the pattern matching logic (e.g., DOTALL compilation, handling of multi-line matches, advice on greedy vs. non-greedy quantifiers), file selection logic (e.g., glob patterns, precedence rules), and output format ('Returns A JSON object mapping file paths to lists of matched consecutive lines'). This goes well beyond basic functionality.

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 well-structured with clear sections (Pattern Matching Logic, File Selection Logic) and front-loaded key information. Most sentences earn their place by providing essential guidance, though some parts could be slightly more concise (e.g., the explanation of DOTALL and quantifiers is detailed but necessary).

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

Completeness5/5

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

Given the complexity of the tool (8 parameters, no annotations, no output schema), the description is highly complete. It covers purpose, usage guidelines, behavioral details, parameter semantics, and output format. The only minor gap is the lack of an output schema, but the description compensates by specifying the return value structure.

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?

With 100% schema description coverage, the baseline is 3. The description adds significant value by explaining the semantics of parameters like restrict_search_to_code_files ('useful if you are only interested in code symbols'), relative_path ('only subpaths of this path'), and glob patterns ('matched against relative file paths from the project root'). However, it doesn't cover all parameters equally (e.g., max_answer_chars is only briefly mentioned).

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: 'Offers a flexible search for arbitrary patterns in the codebase, including the possibility to search in non-code files.' It specifies the verb ('search'), resource ('codebase'), and scope ('non-code files'), and distinguishes it from siblings like find_symbol and find_referencing_symbols by noting when to prefer those alternatives.

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 guidance on when to use this tool versus alternatives: 'Generally, symbolic operations like find_symbol or find_referencing_symbols should be preferred if you know which symbols you are looking for.' It also explains when to use specific parameters, such as restrict_search_to_code_files for code symbols or False for non-code files.

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/lin2000wl/Serena-cursor-mcp'

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