Skip to content

Added grep command#100

Merged
jancurn merged 13 commits intomainfrom
feat/grep-cmd
Mar 24, 2026
Merged

Added grep command#100
jancurn merged 13 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
jancurn and others added 7 commits March 24, 2026 09:23
* Add --instructions flag to grep and check server capabilities before listing

- grep now searches server instructions by default (alongside tools)
- New --instructions flag for explicit control
- Check server capabilities before calling list_tools/list_resources/list_prompts
  to avoid "Method not found" errors on servers that don't support them

https://claude.ai/code/session_01CMqC1S3U6tWj5GanwqP8L9

* Add e2e tests for --instructions grep and limited-capability servers

- grep.test.sh: tests for --instructions flag, combined flags, JSON output
- grep-global.test.sh: tests for instructions in multi-session grep
- grep-global.test.sh: tests with a minimal server (NO_TOOLS, NO_PROMPTS)
  to verify grep gracefully skips unsupported capabilities
- test server: add NO_TOOLS, NO_RESOURCES, NO_PROMPTS env vars to
  conditionally disable capabilities and their handlers

https://claude.ai/code/session_01CMqC1S3U6tWj5GanwqP8L9

---------

Co-authored-by: Claude <noreply@anthropic.com>
* Update grep --json output to use unified sessions array format

Align grep JSON output with `mcpc --json` for consistency:
- Rename `results` → `sessions`, `session` → `name`
- Add `status` field to every session entry
- Merge errors and skipped sessions into unified `sessions` array
- Break `totalMatches` into per-type object: `{ tools, resources, prompts }`
- Include all queried sessions (even those with zero matches)
- Wrap single-session grep output in same format

https://claude.ai/code/session_01A1jJrRBzuNuXadaKB28WqD

* Fix max-results truncation showing full results for overflow sessions

When --max-results budget is exhausted, sessions beyond the limit were
falling back to their full (untruncated) results in JSON output. Now
they correctly show empty arrays when fully truncated.

https://claude.ai/code/session_01A1jJrRBzuNuXadaKB28WqD

---------

Co-authored-by: Claude <noreply@anthropic.com>
* Move `truncated` field inside `totalMatches` in grep JSON output

`totalMatches.truncated` is more natural than a separate top-level field,
since truncation count is directly related to match counts.

https://claude.ai/code/session_01ATNTBBmZqQeZ16bGvoF5gb

* Add changelog entry for grep JSON format change

https://claude.ai/code/session_01ATNTBBmZqQeZ16bGvoF5gb

* Consolidate grep changelog entries into a single Added entry

https://claude.ai/code/session_01ATNTBBmZqQeZ16bGvoF5gb

---------

Co-authored-by: Claude <noreply@anthropic.com>
@jancurn jancurn merged commit 6bd62e0 into main Mar 24, 2026
6 checks passed
jancurn pushed a commit that referenced this pull request Mar 24, 2026
Resolve conflicts with PR #100 (grep command) and PR #105 (help fix):
- Take main's grep.ts (more features: --instructions, -m, capability-aware)
  and re-apply reconnectCrashedSessions call
- Take main's index.ts grep options
- Export DisplayStatus/getBridgeStatus (used by grep.ts) with new states
- Merge changelog entries

https://claude.ai/code/session_01FJXX4xys8aMoF4iVZbkC86
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