Skip to content

Commit e404d85

Browse files
Saranya-jenaHarness
authored andcommitted
chore: [ML-1220]: Add support for default toolsets (#54)
* chore: [ML-1220]: resolved comments Signed-off-by: Saranya-jena <[email protected]> * chore: [ML-1220]: resolved comments Signed-off-by: Saranya-jena <[email protected]> * chore: [ML-1220]: resolved comments Signed-off-by: Saranya-jena <[email protected]> * chore: [ML-1220]: Add support for default toolsets Signed-off-by: Saranya-jena <[email protected]>
1 parent d3fa5cb commit e404d85

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ The Harness MCP Server is a [Model Context Protocol (MCP)](https://modelcontextp
88

99
The server implements several toolsets:
1010

11+
#### Default Toolset
12+
13+
The default toolset contains essential tools from various services:
14+
15+
Toolset Name: `default`
16+
17+
- `get_connector_details`: Get details of a specific connector
18+
- `list_connector_catalogue`: List the Harness connector catalogue
19+
- `list_pipelines`: List pipelines in a repository
20+
- `get_pipeline`: Get details of a specific pipeline
21+
- `get_execution`: Get details of a specific pipeline execution
22+
- `list_executions`: List pipeline executions
23+
- `fetch_execution_url`: Fetch the execution URL for a pipeline execution
24+
- `list_dashboards`: Lists all available Harness dashboards
25+
- `get_dashboard_data`: Retrieves the data from a specific Harness dashboard
26+
1127
#### Pipelines Toolset
1228

1329
Toolset Name: `pipelines`
@@ -399,7 +415,7 @@ To use the Harness MCP Server with Amazon Q Developer CLI:
399415

400416
The Harness MCP Server supports the following command line arguments:
401417

402-
- `--toolsets`: Comma-separated list of tool groups to enable (default: "all")
418+
- `--toolsets`: Comma-separated list of tool groups to enable, if the list is empty or flag is not set, only default toolset is enabled (default: "")
403419
- `--read-only`: Run the server in read-only mode
404420
- `--log-file`: Path to log file for debugging
405421
- `--log-level`: Set the logging level (debug, info, warn, error)

pkg/harness/tools.go

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
// Default tools to enable
20-
var DefaultTools = []string{"all"}
20+
var DefaultTools = []string{}
2121

2222
// Service identity for JWT auth
2323
const serviceIdentity = "genaiservice" // TODO: can change once we have our own service, not needed at the moment
@@ -29,11 +29,69 @@ var defaultJWTLifetime = 1 * time.Hour
2929
// Default timeout for GenAI service
3030
const defaultGenaiTimeout = 300 * time.Second
3131

32+
// createServiceClient is a helper function to create a service client with the given parameters
33+
func createServiceClient(config *config.Config, serviceBaseURL, baseURL, path, secret string, timeouts ...time.Duration) (*client.Client, error) {
34+
url := buildServiceURL(config, serviceBaseURL, baseURL, path)
35+
return createClient(url, config, secret, timeouts...)
36+
}
37+
38+
// registerDefault registers the default toolset with essential tools from various services
39+
func registerDefault(config *config.Config, tsg *toolsets.ToolsetGroup) error {
40+
// Create pipeline service client
41+
pipelineClient, err := createServiceClient(config, config.PipelineSvcBaseURL, config.BaseURL, "pipeline", config.PipelineSvcSecret)
42+
if err != nil {
43+
return fmt.Errorf("failed to create client for pipeline service: %w", err)
44+
}
45+
pipelineServiceClient := &client.PipelineService{Client: pipelineClient}
46+
47+
// Create connector service client
48+
connectorClient, err := createServiceClient(config, config.NgManagerBaseURL, config.BaseURL, "ng/api", config.NgManagerSecret)
49+
if err != nil {
50+
return fmt.Errorf("failed to create client for connectors: %w", err)
51+
}
52+
connectorServiceClient := &client.ConnectorService{Client: connectorClient}
53+
54+
// Create dashboard service client
55+
customTimeout := 30 * time.Second
56+
dashboardClient, err := createServiceClient(config, config.DashboardSvcBaseURL, config.BaseURL, "dashboard", config.DashboardSvcSecret, customTimeout)
57+
if err != nil {
58+
return fmt.Errorf("failed to create client for dashboard service: %w", err)
59+
}
60+
dashboardServiceClient := &client.DashboardService{Client: dashboardClient}
61+
62+
// Create the default toolset with essential tools
63+
defaultToolset := toolsets.NewToolset("default", "Default essential Harness tools").AddReadTools(
64+
// Connector Management tools
65+
toolsets.NewServerTool(GetConnectorDetailsTool(config, connectorServiceClient)),
66+
toolsets.NewServerTool(ListConnectorCatalogueTool(config, connectorServiceClient)),
67+
68+
// Pipeline Management tools
69+
toolsets.NewServerTool(ListPipelinesTool(config, pipelineServiceClient)),
70+
toolsets.NewServerTool(GetPipelineTool(config, pipelineServiceClient)),
71+
toolsets.NewServerTool(FetchExecutionURLTool(config, pipelineServiceClient)),
72+
toolsets.NewServerTool(GetExecutionTool(config, pipelineServiceClient)),
73+
toolsets.NewServerTool(ListExecutionsTool(config, pipelineServiceClient)),
74+
75+
// Dashboard tools
76+
toolsets.NewServerTool(ListDashboardsTool(config, dashboardServiceClient)),
77+
toolsets.NewServerTool(GetDashboardDataTool(config, dashboardServiceClient)),
78+
)
79+
80+
// Add the default toolset to the group
81+
tsg.AddToolset(defaultToolset)
82+
return nil
83+
}
84+
3285
// InitToolsets initializes and returns the toolset groups
3386
func InitToolsets(config *config.Config) (*toolsets.ToolsetGroup, error) {
3487
// Create a toolset group
3588
tsg := toolsets.NewToolsetGroup(config.ReadOnly)
3689

90+
// Register default toolset with essential tools
91+
if err := registerDefault(config, tsg); err != nil {
92+
return nil, err
93+
}
94+
3795
// Register pipelines
3896
if err := registerPipelines(config, tsg); err != nil {
3997
return nil, err
@@ -594,6 +652,7 @@ func registerCloudCostManagement(config *config.Config, tsg *toolsets.ToolsetGro
594652

595653
// registerGenai registers the genai toolset
596654
func registerGenai(config *config.Config, tsg *toolsets.ToolsetGroup) error {
655+
597656
// Skip registration for external mode for now
598657
if !config.Internal {
599658
return nil

pkg/toolsets/toolsets.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ func (tg *ToolsetGroup) IsEnabled(name string) bool {
124124

125125
// EnableToolsets enables multiple toolsets by name
126126
func (tg *ToolsetGroup) EnableToolsets(names []string) error {
127+
if len(names) == 0 {
128+
err := tg.EnableToolset("default")
129+
if err != nil {
130+
return err
131+
}
132+
return nil
133+
}
127134
for _, name := range names {
128135
if name == "all" {
129136
tg.everythingOn = true
@@ -160,7 +167,13 @@ func (tg *ToolsetGroup) EnableToolset(name string) error {
160167

161168
// RegisterTools registers all enabled toolsets with the server
162169
func (tg *ToolsetGroup) RegisterTools(s *server.MCPServer) {
170+
if tg == nil || len(tg.Toolsets) == 0 {
171+
return
172+
}
173+
163174
for _, toolset := range tg.Toolsets {
164-
toolset.RegisterTools(s)
175+
if toolset != nil {
176+
toolset.RegisterTools(s)
177+
}
165178
}
166179
}

0 commit comments

Comments
 (0)