Skip to content

Added grep command#100

Open
jancurn wants to merge 6 commits intomainfrom
feat/grep-cmd
Open

Added grep command#100
jancurn wants to merge 6 commits intomainfrom
feat/grep-cmd

Conversation

@jancurn
Copy link
Member

@jancurn jancurn commented Mar 23, 2026

Overview

Implements a new grep command that searches tools, resources, and prompts across all active sessions or within a single session.

Features

  • Multi-session search: mcpc grep <pattern> searches all active sessions
  • Single-session search: @session grep <pattern> searches within a specific session
  • Type filtering: --tools, --resources, --prompts flags to limit search scope
  • Regex support: -E/--regex flag for regular expression patterns
  • Case sensitivity: -s/--case-sensitive flag for case-sensitive matching
  • Dual output modes: Human-readable and JSON output for scripting

Changes

  • Added src/cli/commands/grep.ts with search logic and formatting
  • Registered grep command in both global and session contexts
  • Exported utility formatting functions from output.ts for reuse
  • Updated command parser to recognize new grep command
  • Updated CHANGELOG with feature description

jancurn and others added 3 commits March 23, 2026 22:50
Adds a new grep command that searches tools, resources, and prompts
by name and description across all active MCP sessions. Supports
regex matching (-E), case-sensitive mode (-s), and type filters
(--tools, --resources, --prompts). Available as both a top-level
command (all sessions) and session command (single session).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
jancurn and others added 3 commits March 24, 2026 00:51
* Add recovery hints for crashed and expired sessions in session list

Show actionable hints under crashed and expired sessions in `mcpc` output,
similar to the existing hint for unauthorized sessions.

https://claude.ai/code/session_01D6ovkixxWohRHXaJP7Hh3g

* Remove extra text from crashed session hint

https://claude.ai/code/session_01D6ovkixxWohRHXaJP7Hh3g

---------

Co-authored-by: Claude <noreply@anthropic.com>
* Make grep --resources and --prompts opt-in flags

By default, grep now searches only tools. Users must explicitly pass
--resources and/or --prompts to include those types in search results.
When --tools is combined with other flags, it behaves as an explicit
opt-in just like the others.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J

* Fix grep to always search tools; add e2e tests

Tools are now always searched by default (additive model):
- No flags → tools only
- --resources → tools + resources
- --prompts → tools + prompts
- --no-tools --resources → resources only

Also adds comprehensive e2e tests for grep covering default
behavior, opt-in flags, regex, case sensitivity, and JSON output.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J

* Change grep type flags to explicit selection model

No flags → tools only (default). Specifying --resources or --prompts
searches exactly those types, skipping tools. Use --tools alongside
other flags to include tools explicitly. Updated e2e tests to match.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J

* Fix grep double-@ prefix on session names in grepAllSessions

Session names in sessions.json already include the @ prefix (e.g. "@test"),
but grepAllSessions was prepending another @, producing "@@test" which
failed to resolve. Now correctly checks for existing prefix.

Also changed --tools/--resources/--prompts to explicit selection model:
specifying any flag searches exactly those types, default is tools only.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J

* Improve grep to search session names and full tool schemas, show unavailable sessions

The grep matcher now builds searchable text as "@session/item-name <JSON schema>"
so patterns can match session names, tool parameters, and other schema metadata.
Unavailable sessions (crashed, disconnected, etc.) are now displayed with their
status instead of being silently skipped.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J

* Remove time-ago from skipped session lines in grep output

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J

* Add -m/--max-results option to grep command

Limits the number of results shown. The total match count is still reported
so users know how many were omitted. Works for both single-session and
multi-session grep, with the limit applied globally across sessions.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J

* Add global grep e2e tests and README documentation

- Add test/e2e/suites/basic/grep-global.test.sh covering mcpc grep <pattern>
  across all active sessions (multi-session search, type flags, regex,
  case sensitivity, JSON output, --max-results, no-sessions edge case)
- Add grep section to README with usage examples
- Add grep to command listings in README help block
- Remove per-session "(N matches)" suffix from global grep human output

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J

* Consolidate grep changelog entries into single Added entry

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J

* Fix grep-global e2e test flakiness by using isolated home directory

The test's "no sessions" assertions at the end could fail when other
parallel tests had active sessions with matching tools in the shared
home directory.

https://claude.ai/code/session_016JBmUAMywHLhbJWq94JV3J

---------

Co-authored-by: Claude <noreply@anthropic.com>
@jancurn jancurn changed the title Added grep command (attempt 2) Added grep command Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants