Skip to content

Commit 39e5d7f

Browse files
committed
Merge branch 'master' of github.com:korotovsky/slack-mcp-server
2 parents 43074cd + af37da3 commit 39e5d7f

File tree

8 files changed

+55
-53
lines changed

8 files changed

+55
-53
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ Open your `claude_desktop_config.json` and add the mcp server to the list of `mc
100100
"-i",
101101
"--rm",
102102
"-e",
103-
"SLACK_MCP_XOXC_TOKEN=$SLACK_MCP_XOXC_TOKEN",
103+
"SLACK_MCP_XOXC_TOKEN",
104104
"-e",
105-
"SLACK_MCP_XOXD_TOKEN=$SLACK_MCP_XOXD_TOKEN",
105+
"SLACK_MCP_XOXD_TOKEN",
106106
"ghcr.io/korotovsky/slack-mcp-server",
107107
"mcp-server",
108108
"--transport",

cmd/slack-mcp-server/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package main
22

33
import (
44
"flag"
5-
"github.com/korotovsky/slack-mcp-server/pkg/provider"
6-
"github.com/korotovsky/slack-mcp-server/pkg/server"
75
"log"
86
"os"
97
"strconv"
8+
9+
"github.com/korotovsky/slack-mcp-server/pkg/provider"
10+
"github.com/korotovsky/slack-mcp-server/pkg/server"
1011
)
1112

1213
var defaultSseHost = "127.0.0.1"

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ toolchain go1.23.5
77
require (
88
github.com/bbalet/stopwords v1.0.0
99
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
10-
github.com/mark3labs/mcp-go v0.20.0
10+
github.com/mark3labs/mcp-go v0.31.0
1111
github.com/slack-go/slack v0.16.0
1212
)
1313

1414
require (
1515
github.com/google/uuid v1.6.0 // indirect
1616
github.com/gorilla/websocket v1.4.2 // indirect
17+
github.com/spf13/cast v1.7.1 // indirect
1718
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
1819
golang.org/x/text v0.24.0 // indirect
1920
)

go.sum

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,33 @@ github.com/bbalet/stopwords v1.0.0 h1:0TnGycCtY0zZi4ltKoOGRFIlZHv0WqpoIGUsObjztf
22
github.com/bbalet/stopwords v1.0.0/go.mod h1:sAWrQoDMfqARGIn4s6dp7OW7ISrshUD8IP2q3KoqPjc=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
6+
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
57
github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho=
68
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
79
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 h1:FWNFq4fM1wPfcK40yHE5UO3RUdSNPaBC+j3PokzA6OQ=
810
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI=
9-
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
1011
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
12+
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
13+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1114
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1215
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1316
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
1417
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
15-
github.com/mark3labs/mcp-go v0.20.0 h1:NYZDZ10GBKHVz4SdQ2tPFSDFQFKCTrTZJLn4wj6jAaw=
16-
github.com/mark3labs/mcp-go v0.20.0/go.mod h1:KmJndYv7GIgcPVwEKJjNcbhVQ+hJGJhrCCB/9xITzpE=
18+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
19+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
20+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
21+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
22+
github.com/mark3labs/mcp-go v0.31.0 h1:4UxSV8aM770OPmTvaVe/b1rA2oZAjBMhGBfUgOGut+4=
23+
github.com/mark3labs/mcp-go v0.31.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
1724
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1825
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
26+
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
27+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
1928
github.com/slack-go/slack v0.16.0 h1:khp/WCFv+Hb/B/AJaAwvcxKun0hM6grN0bUZ8xG60P8=
2029
github.com/slack-go/slack v0.16.0/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
30+
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
31+
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
2132
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
2233
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
2334
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=

pkg/handler/channels.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ package handler
22

33
import (
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

1415
var AllChanTypes = []string{"mpim", "im", "public_channel", "private_channel"}
15-
var PubChanType = []string{"public_channel"}
16+
var PubChanType = "public_channel"
1617

1718
type Channel struct {
1819
ID string `json:"id"`
@@ -24,43 +25,40 @@ type Channel struct {
2425

2526
type ChannelsHandler struct {
2627
apiProvider *provider.ApiProvider
28+
validTypes map[string]bool
2729
}
2830

2931
func 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

3543
func (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{

pkg/handler/conversations.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"strconv"
8+
"strings"
9+
"time"
10+
711
"github.com/gocarina/gocsv"
812
"github.com/korotovsky/slack-mcp-server/pkg/provider"
913
"github.com/korotovsky/slack-mcp-server/pkg/text"
1014
"github.com/mark3labs/mcp-go/mcp"
1115
"github.com/slack-go/slack"
12-
"strconv"
13-
"strings"
14-
"time"
1516
)
1617

1718
type Message struct {
@@ -42,22 +43,13 @@ func (ch *ConversationsHandler) ConversationsHistoryHandler(ctx context.Context,
4243
paramLatest string
4344
)
4445

45-
channel, ok := request.Params.Arguments["channel_id"].(string)
46-
if !ok {
46+
channel := request.GetString("channel_id", "")
47+
if channel == "" {
4748
return nil, errors.New("channel_id must be a string")
4849
}
4950

50-
limit := ""
51-
limitOptional := request.Params.Arguments["limit"]
52-
if limitOptional != nil {
53-
limit = limitOptional.(string)
54-
}
55-
56-
cursor := ""
57-
cursorOptional := request.Params.Arguments["cursor"]
58-
if cursorOptional != nil {
59-
cursor = cursorOptional.(string)
60-
}
51+
limit := request.GetString("limit", "")
52+
cursor := request.GetString("cursor", "")
6153

6254
if strings.HasSuffix(limit, "d") {
6355
paramLimit, paramOldest, paramLatest, err = limitByDays(limit)

pkg/provider/api.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import (
55
"crypto/tls"
66
"crypto/x509"
77
"encoding/json"
8-
"github.com/korotovsky/slack-mcp-server/pkg/transport"
9-
"github.com/slack-go/slack"
108
"io/ioutil"
119
"log"
1210
"net/http"
1311
"net/url"
1412
"os"
13+
14+
"github.com/korotovsky/slack-mcp-server/pkg/transport"
15+
"github.com/slack-go/slack"
1516
)
1617

1718
type ApiProvider struct {

pkg/server/server.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package server
22

33
import (
44
"fmt"
5+
56
"github.com/korotovsky/slack-mcp-server/pkg/handler"
67
"github.com/korotovsky/slack-mcp-server/pkg/provider"
78
"github.com/mark3labs/mcp-go/mcp"
@@ -41,12 +42,9 @@ func NewMCPServer(provider *provider.ApiProvider) *MCPServer {
4142

4243
s.AddTool(mcp.NewTool("channels_list",
4344
mcp.WithDescription("Get list of channels"),
44-
mcp.WithArray("channel_types",
45+
mcp.WithString("channel_types",
4546
mcp.Required(),
46-
mcp.Description("Possible channel types. Allowed values: 'mpim', 'im', 'public_channel', 'private_channel'."),
47-
mcp.Items(map[string]any{
48-
"type": "string",
49-
}),
47+
mcp.Description("Comma-separated channel types. Allowed values: 'mpim', 'im', 'public_channel', 'private_channel'. Example: 'public_channel,private_channel,im'"),
5048
),
5149
mcp.WithString("sort",
5250
mcp.Description("Type of sorting. Allowed values: 'popularity' - sort by number of members/participants in each channel."),

0 commit comments

Comments
 (0)