Merge pull request #263 from Christian-Sidak/feat/users-search-by-id

feat: support direct user ID lookup in users_search
This commit is contained in:
Dmitrii Korotovskii
2026-05-14 20:47:31 +02:00
committed by GitHub
2 changed files with 18 additions and 2 deletions
+16
View File
@@ -1199,10 +1199,26 @@ func (ap *ApiProvider) IsOAuth() bool {
return ok && client != nil && client.IsOAuth()
}
// slackUserIDPattern matches Slack user IDs (e.g., U07VCEPP4N5, W0123456789).
var slackUserIDPattern = regexp.MustCompile(`^[UW][A-Z0-9]{2,}$`)
// SearchUsers searches for users by name, email, or display name.
// If the query matches a Slack user ID pattern (e.g., U07VCEPP4N5), it looks up the user
// directly via the users.info API instead of searching.
// For OAuth tokens (xoxp/xoxb), it searches the local users cache using regex matching.
// For browser tokens (xoxc/xoxd), it uses the edge API's UsersSearch method.
func (ap *ApiProvider) SearchUsers(ctx context.Context, query string, limit int) ([]slack.User, error) {
if slackUserIDPattern.MatchString(query) {
users, err := ap.client.GetUsersInfo(query)
if err != nil {
return nil, err
}
if users != nil {
return *users, nil
}
return nil, nil
}
if ap.IsOAuth() {
return ap.searchUsersInCache(query, limit)
}
+2 -2
View File
@@ -286,12 +286,12 @@ func NewMCPServer(provider *provider.ApiProvider, logger *zap.Logger, enabledToo
if shouldAddTool(ToolUsersSearch, enabledTools, "") {
s.AddTool(mcp.NewTool(ToolUsersSearch,
mcp.WithDescription("Search for users by name, email, or display name. Returns user details and DM channel ID if available."),
mcp.WithDescription("Search for users by name, email, display name, or Slack user ID. If a Slack user ID is provided (e.g. U07VCEPP4N5), the user is looked up directly. Returns user details and DM channel ID if available."),
mcp.WithTitleAnnotation("Search Users"),
mcp.WithReadOnlyHintAnnotation(true),
mcp.WithString("query",
mcp.Required(),
mcp.Description("Search query - matches against real name, display name, username, or email."),
mcp.Description("Search query - matches against real name, display name, username, email, or a Slack user ID (e.g. U07VCEPP4N5)."),
),
mcp.WithNumber("limit",
mcp.DefaultNumber(10),