Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmd/mcp-http/main.go
Comment thread
rafaeljusto marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/teamwork/mcp/internal/config"
"github.com/teamwork/mcp/internal/request"
"github.com/teamwork/mcp/internal/toolsets"
"github.com/teamwork/mcp/internal/twchat"
"github.com/teamwork/mcp/internal/twdesk"
"github.com/teamwork/mcp/internal/twprojects"
"github.com/teamwork/mcp/internal/twspaces"
Expand Down Expand Up @@ -125,10 +126,16 @@ func newMCPServer(resources config.Resources) (*mcp.Server, error) {
return nil, fmt.Errorf("failed to enable spaces toolsets: %w", err)
}

chatGroup := twchat.DefaultToolsetGroup(false, resources.TeamworkEngine())
if err := chatGroup.EnableToolsets(methods.Toolsets()...); err != nil {
return nil, fmt.Errorf("failed to enable chat toolsets: %w", err)
}

return config.NewMCPServer(resources,
projectsGroup,
deskGroup,
spacesGroup,
chatGroup,
), nil
}

Expand Down Expand Up @@ -165,7 +172,7 @@ func newRouter(resources config.Resources) *http.ServeMux {
"authorization_servers": ["` + resources.Info.APIURL + `"],
"bearer_methods_supported": ["header"],
"resource_documentation": "https://apidocs.teamwork.com/guides/teamwork/app-login-flow",
"scopes_supported": [ "projects", "desk", "spaces" ]
"scopes_supported": [ "projects", "desk", "spaces", "chat" ]
}`))
})
return mux
Expand Down
8 changes: 7 additions & 1 deletion cmd/mcp-stdio/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/teamwork/mcp/internal/cli"
"github.com/teamwork/mcp/internal/config"
"github.com/teamwork/mcp/internal/toolsets"
"github.com/teamwork/mcp/internal/twchat"
"github.com/teamwork/mcp/internal/twdesk"
"github.com/teamwork/mcp/internal/twprojects"
"github.com/teamwork/mcp/internal/twspaces"
Expand Down Expand Up @@ -128,7 +129,12 @@ func newMCPServer(resources config.Resources) (*mcp.Server, error) {
return nil, fmt.Errorf("failed to enable spaces toolsets: %w", err)
}

return config.NewMCPServer(resources, projectsGroup, deskGroup, spacesGroup), nil
chatGroup := twchat.DefaultToolsetGroup(readOnly, resources.TeamworkEngine())
if err := chatGroup.EnableToolsets(methods.Toolsets()...); err != nil {
return nil, fmt.Errorf("failed to enable chat toolsets: %w", err)
}

return config.NewMCPServer(resources, projectsGroup, deskGroup, spacesGroup, chatGroup), nil
}

func mcpError(logger *slog.Logger, err error, code jsonRPCErrorCode) {
Expand Down
4 changes: 3 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,13 @@ func NewMCPServer(resources Resources, groups ...*toolsets.ToolsetGroup) *mcp.Se
projectsScope := slices.Contains(scopes, "projects")
deskScope := slices.Contains(scopes, "desk")
spacesScope := slices.Contains(scopes, "spaces")
chatScope := slices.Contains(scopes, "chat")

listToolsResult.Tools = slices.DeleteFunc(listToolsResult.Tools, func(tool *mcp.Tool) bool {
return (strings.HasPrefix(tool.Name, "twprojects") && !projectsScope) ||
(strings.HasPrefix(tool.Name, "twdesk") && !deskScope) ||
(strings.HasPrefix(tool.Name, "twspaces") && !spacesScope)
(strings.HasPrefix(tool.Name, "twspaces") && !spacesScope) ||
(strings.HasPrefix(tool.Name, "twchat") && !chatScope)
})
return listToolsResult, nil
}
Expand Down
19 changes: 19 additions & 0 deletions internal/testutil/mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
deskclient "github.com/teamwork/desksdkgo/client"
"github.com/teamwork/mcp/internal/config"
"github.com/teamwork/mcp/internal/toolsets"
"github.com/teamwork/mcp/internal/twchat"
"github.com/teamwork/mcp/internal/twdesk"
"github.com/teamwork/mcp/internal/twprojects"
"github.com/teamwork/mcp/internal/twspaces"
Expand Down Expand Up @@ -80,6 +81,24 @@ func ProjectsMCPServerMock(t *testing.T, status int, response []byte) *mcp.Serve
return mcpServer
}

// ChatMCPServerMock creates a mock MCP server for twchat testing. The twchat
// tools ride the shared twapi.Engine, so it reuses ProjectsEngineMock to return
// the canned HTTP response.
func ChatMCPServerMock(t *testing.T, status int, response []byte) *mcp.Server {
mcpServer := mcp.NewServer(&mcp.Implementation{
Name: "test-server",
Version: "1.0.0",
}, &mcp.ServerOptions{})

toolsetGroup := twchat.DefaultToolsetGroup(false, ProjectsEngineMock(status, response))
if err := toolsetGroup.EnableToolsets(toolsets.MethodAll); err != nil {
t.Fatalf("failed to enable toolsets: %v", err)
}
toolsetGroup.RegisterAll(mcpServer)

return mcpServer
}

// ProjectsMockRoute pairs a substring match against the request URL path with
// the status and body to return when it matches.
type ProjectsMockRoute struct {
Expand Down
Loading