Skip to content

Conversation

@Flare576
Copy link
Contributor

@Flare576 Flare576 commented Feb 3, 2026

Summary

  • Adds fallback resolution for #channel-name syntax when the SearchChannels API fails with team_is_restricted error (common in Enterprise Grid)
  • Falls back to search.messages API with in:#channel-name query to extract channel ID

Problem

In Slack Enterprise Grid environments with multiple workspaces, the search.modules.channels API (used by SearchChannels) returns team_is_restricted even when the user has access to the channel. This prevents using #channel-name syntax for message operations.

However, the search.messages API handles channel names server-side and works correctly - Slack resolves in:#channel-name internally before searching.

Solution

  1. Primary path: Try SearchChannels API (works in most environments)
  2. Fallback path: If team_is_restricted error, use search.messages with in:#channel-name query and extract channel ID from results
  3. Cache update: On successful resolution, update the in-memory cache for future lookups

Changes

  • pkg/provider/api.go: Add SearchChannels method to SlackAPI interface and MCPSlackClient
  • pkg/handler/conversations.go:
    • resolveChannelIDWithFallback: Main resolution with Enterprise Grid fallback
    • resolveUserDMChannelWithFallback: DM channel resolution with user search fallback
    • resolveChannelViaSearch: Extract channel ID from search results
    • isTeamRestrictedError: Detect the Enterprise Grid restriction error
    • paramFormatChannel/paramFormatUser: Updated to use fallback methods

Testing

  • Tested in ASU Enterprise Grid environment where SearchChannels consistently returns team_is_restricted
  • #channel-name syntax now resolves correctly via the search fallback
  • Standard Slack workspaces continue to use the primary SearchChannels path

Depends On

@korotovsky
Copy link
Owner

@Flare576 pls rebase with master

@Flare576 Flare576 force-pushed the feat/enterprise-grid-channel-fallback branch from d20def6 to f8dfad4 Compare February 6, 2026 12:20
- Validate Slack tokens on startup via AuthTest() - server now fails fast
  with clear error message if tokens are invalid/expired
- Namespace cache files by TeamID (e.g., T12345_users_cache.json) to prevent
  cross-workspace cache contamination when switching between Slack workspaces
- Log authenticated workspace info on startup for debugging
When SearchChannels API fails with team_is_restricted (common in Enterprise
Grid cross-workspace scenarios), fall back to search.messages API to resolve
channel names to IDs.

Changes:
- Add SearchChannels method to SlackAPI interface and MCPSlackClient
- Add resolveChannelIDWithFallback with search API fallback for #channel syntax
- Add resolveUserDMChannelWithFallback for @username DM resolution
- Add resolveChannelViaSearch using search.messages in:#channel-name query
- Add isTeamRestrictedError helper to detect Enterprise Grid restriction
- Update paramFormatChannel and paramFormatUser with API fallbacks

This enables using #channel-name syntax in Enterprise Grid environments where
the channels API is restricted, but search API works.
@Flare576 Flare576 force-pushed the feat/enterprise-grid-channel-fallback branch from f8dfad4 to acbb27b Compare February 11, 2026 02: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.

2 participants