Skip to content

Auto-generate session names for connect command#136

Merged
jancurn merged 13 commits intomainfrom
claude/auto-generate-session-names-CDRSb
Apr 8, 2026
Merged

Auto-generate session names for connect command#136
jancurn merged 13 commits intomainfrom
claude/auto-generate-session-names-CDRSb

Conversation

@jancurn
Copy link
Copy Markdown
Member

@jancurn jancurn commented Apr 4, 2026

Summary

The mcpc connect command now auto-generates session names when the @session argument is omitted, making it easier to connect to servers without requiring explicit session naming. If a session for the same server already exists with matching authentication settings, it is reused instead of creating a duplicate.

Key Changes

  • Added generateSessionName() function in src/lib/utils.ts that creates session names from server targets:

    • For URL targets: extracts the "brand" from the hostname (e.g., mcp.apify.com@apify)
    • Strips common prefixes (mcp., api., www.)
    • Appends non-standard ports (e.g., localhost:3000@localhost-3000)
    • For config entries: uses the entry name directly (e.g., ~/.vscode/mcp.json:filesystem@filesystem)
  • Added resolveSessionName() function in src/cli/commands/sessions.ts that:

    • Checks for existing sessions matching the server target and auth settings (profile, headers)
    • Reuses matching sessions instead of creating duplicates
    • Falls back to generating a new name if no match found
    • Handles name collisions by appending numeric suffixes (e.g., @apify-2)
  • Added findMatchingSession() helper that compares sessions by:

    • Normalized server URL
    • Profile name (with --no-profile support)
    • HTTP header keys (values are redacted)
  • Updated connect command to make @session optional:

    • Changed usage from <server> <@session> to <server> [@session]
    • Updated help text to explain auto-generation behavior
    • Calls resolveSessionName() when session name is omitted
  • Added comprehensive test coverage in test/unit/lib/utils.test.ts for generateSessionName() with 20+ test cases covering URL parsing, hostname extraction, port handling, IP addresses, and config entries

Notable Implementation Details

  • Session name generation is deterministic and based on server hostname/entry name, enabling consistent reuse across invocations
  • URL normalization via normalizeServerUrl() ensures consistent comparison of URLs with different schemes/formats
  • Header matching only compares key sets (not values) since header values are redacted in stored sessions
  • Config entry matching is deferred to name-based deduplication since stdio transports can't be easily compared
  • Numeric suffix collision handling supports up to 99 variants per base name

https://claude.ai/code/session_01SRw2NArnxDKmgZLrNL72c6

claude and others added 13 commits March 18, 2026 22:50
…mand

The `mcpc connect <server>` command now auto-generates a session name from the
server hostname (e.g. mcp.apify.com → @apify) or config entry name when the
@session argument is omitted. If an existing session already matches the same
server and auth settings, it is reused instead of creating a duplicate.

https://claude.ai/code/session_01SRw2NArnxDKmgZLrNL72c6
…ertion

- Cast opts.profile and opts.noProfile with explicit types to satisfy
  exactOptionalPropertyTypes (consistent with existing patterns in file)
- Replace labels[0]! with nullish coalescing to satisfy no-non-null-assertion

https://claude.ai/code/session_01SRw2NArnxDKmgZLrNL72c6
- Resolve CHANGELOG.md conflict (keep both entries)
- Update README help block to match new connect command description

https://claude.ai/code/session_01SRw2NArnxDKmgZLrNL72c6
…opts

Use the properly-typed HandlerOptions from getOptionsFromCommand() instead
of casting raw Commander opts, consistent with how connectSession receives
its options via ...globalOpts spread.

https://claude.ai/code/session_01SRw2NArnxDKmgZLrNL72c6
Build resolveSessionName options with conditional spreads to avoid passing
undefined values to optional properties, matching the pattern used by
connectSession (e.g. `...(headers && { headers })`).

https://claude.ai/code/session_01SRw2NArnxDKmgZLrNL72c6
- CHANGELOG: keep auto-generate session names entry + main's new entries
- README/index.ts: take main's --json (removed -j alias from PR #146)
- index.ts: combine session name help text with main's jsonHelp() output

https://claude.ai/code/session_01SRw2NArnxDKmgZLrNL72c6
Keep our "Session name" help section (auto-generated names with
matching criteria) alongside main's changes (error handling, CI,
InitializeResult docs).

https://claude.ai/code/session_01SRw2NArnxDKmgZLrNL72c6
@jancurn jancurn merged commit 57b3ba0 into main Apr 8, 2026
6 checks passed
@jancurn jancurn deleted the claude/auto-generate-session-names-CDRSb branch April 8, 2026 11:01
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.

3 participants