Skip to main content
Glama

Serena MCP Server

by lin2000wl

search_for_pattern

Search for custom patterns in code or non-code files within your project. Use regex patterns, restrict by file type or path, and include context lines around matches for precise results.

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

NameRequiredDescriptionDefault
context_lines_afterNoNumber of lines of context to include after each match.
context_lines_beforeNoNumber of lines of context to include before each match.
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.
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.
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.
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.
substring_patternYesRegular expression for a substring pattern to search for.

Input Schema (JSON Schema)

{ "properties": { "context_lines_after": { "default": 0, "description": "Number of lines of context to include after each match.", "title": "Context Lines After", "type": "integer" }, "context_lines_before": { "default": 0, "description": "Number of lines of context to include before each match.", "title": "Context Lines Before", "type": "integer" }, "max_answer_chars": { "default": 200000, "description": "If the output is longer than this number of characters,\nno content will be returned. Don't adjust unless there is really no other way to get the content\nrequired for the task. Instead, if the output is too long, you should\nmake a stricter query.", "title": "Max Answer Chars", "type": "integer" }, "paths_exclude_glob": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional glob pattern specifying files to exclude from the search.\nMatches against relative file paths from the project root (e.g., \"*test*\", \"**/*_generated.py\").\nTakes precedence over paths_include_glob. Only matches files, not directories.", "title": "Paths Exclude Glob" }, "paths_include_glob": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional glob pattern specifying files to include in the search.\nMatches against relative file paths from the project root (e.g., \"*.py\", \"src/**/*.ts\").\nOnly matches files, not directories.", "title": "Paths Include Glob" }, "relative_path": { "default": "", "description": "Only subpaths of this path (relative to the repo root) will be analyzed. If a path to a single\nfile is passed, only that will be searched. The path must exist, otherwise a `FileNotFoundError` is raised.", "title": "Relative Path", "type": "string" }, "restrict_search_to_code_files": { "default": false, "description": "Whether to restrict the search to only those files where\nanalyzed code symbols can be found. Otherwise, will search all non-ignored files.\nSet this to True if your search is only meant to discover code that can be manipulated with symbolic tools.\nFor example, for finding classes or methods from a name pattern.\nSetting to False is a better choice if you also want to search in non-code files, like in html or yaml files,\nwhich is why it is the default.", "title": "Restrict Search To Code Files", "type": "boolean" }, "substring_pattern": { "description": "Regular expression for a substring pattern to search for.", "title": "Substring Pattern", "type": "string" } }, "required": [ "substring_pattern" ], "title": "applyArguments", "type": "object" }

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