@@ -2,17 +2,18 @@ package handler
22
33import (
44 "context"
5- "fmt"
5+ "log"
6+ "sort"
7+ "strings"
8+
69 "github.com/gocarina/gocsv"
710 "github.com/korotovsky/slack-mcp-server/pkg/provider"
811 "github.com/mark3labs/mcp-go/mcp"
912 "github.com/slack-go/slack"
10- "log"
11- "sort"
1213)
1314
1415var AllChanTypes = []string {"mpim" , "im" , "public_channel" , "private_channel" }
15- var PubChanType = [] string { "public_channel" }
16+ var PubChanType = "public_channel"
1617
1718type Channel struct {
1819 ID string `json:"id"`
@@ -24,43 +25,40 @@ type Channel struct {
2425
2526type ChannelsHandler struct {
2627 apiProvider * provider.ApiProvider
28+ validTypes map [string ]bool
2729}
2830
2931func NewChannelsHandler (apiProvider * provider.ApiProvider ) * ChannelsHandler {
32+ validTypes := make (map [string ]bool , len (AllChanTypes ))
33+ for _ , v := range AllChanTypes {
34+ validTypes [v ] = true
35+ }
36+
3037 return & ChannelsHandler {
3138 apiProvider : apiProvider ,
39+ validTypes : validTypes ,
3240 }
3341}
3442
3543func (ch * ChannelsHandler ) ChannelsHandler (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
36- sortType := request .Params .Arguments ["sort" ]
37- if sortType == "" || sortType == nil {
38- sortType = "popularity"
39- }
44+ sortType := request .GetString ("sort" , "popularity" )
45+ types := request .GetString ("channel_types" , PubChanType )
4046
41- types , ok := request .Params .Arguments ["channel_types" ].([]interface {})
42- if ! ok {
43- return nil , fmt .Errorf ("channel_types should be an array" )
44- }
47+ // MCP Inspector v0.14.0 has issues with Slice type
48+ // introspection, so some type simplification makes sense here
4549 channelTypes := []string {}
46- for i , v := range types {
47- s , ok := v .(string )
48- if ! ok || s == "" {
49- fmt .Printf ("element at index %d is not a string\n " , i )
50- continue
50+ for _ , t := range strings .Split (types , "," ) {
51+ t = strings .TrimSpace (t )
52+ if ch .validTypes [t ] {
53+ channelTypes = append (channelTypes , t )
5154 }
52- channelTypes = append (channelTypes , s )
5355 }
5456
5557 api , err := ch .apiProvider .Provide ()
5658 if err != nil {
5759 return nil , err
5860 }
5961
60- if len (types ) == 0 {
61- channelTypes = PubChanType
62- }
63-
6462 var channels []slack.Channel
6563
6664 params := & slack.GetConversationsParameters {
0 commit comments