Skip to content

Commit fc77b15

Browse files
Swarnendu GuptaHarness
authored andcommitted
Get Details about a specific connector (#24)
* Remove .DS_Store files * Get Details about a specific connector
1 parent 3b27178 commit fc77b15

File tree

4 files changed

+132
-1
lines changed

4 files changed

+132
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ dist/
1111
__debug_bin*
1212

1313
# Go
14-
vendor
14+
vendor
15+
16+
**/.DS_Store

client/connectors.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,31 @@ func (c *ConnectorService) ListConnectorCatalogue(ctx context.Context, scope dto
5757

5858
return result, nil
5959
}
60+
61+
// GetConnector retrieves a connector by its identifier
62+
// https://apidocs.harness.io/tag/Connectors#operation/getConnector
63+
func (c *ConnectorService) GetConnector(ctx context.Context, scope dto.Scope, connectorIdentifier string) (*pkgDTO.ConnectorDetail, error) {
64+
path := fmt.Sprintf("/ng/api/connectors/%s", connectorIdentifier)
65+
params := make(map[string]string)
66+
// Ensure accountIdentifier is always set
67+
if scope.AccountID == "" {
68+
return nil, fmt.Errorf("accountIdentifier cannot be null")
69+
}
70+
addScope(scope, params)
71+
72+
// Define a struct to match the actual API response structure
73+
type connectorResponse struct {
74+
Status string `json:"status"`
75+
Data pkgDTO.ConnectorDetail `json:"data"`
76+
MetaData interface{} `json:"metaData"`
77+
CorrelationID string `json:"correlationId"`
78+
}
79+
80+
var response connectorResponse
81+
err := c.Client.Get(ctx, path, params, nil, &response)
82+
if err != nil {
83+
return nil, fmt.Errorf("failed to get connector: %w", err)
84+
}
85+
86+
return &response.Data, nil
87+
}

pkg/harness/dto/connectors.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,66 @@ type ConnectorCatalogueItem struct {
2929
SSCAType string `json:"sscaType,omitempty"`
3030
SSCASupported bool `json:"sscaSupported,omitempty"`
3131
}
32+
33+
// ConnectorDetail represents the detailed information of a connector.
34+
// Based on https://apidocs.harness.io/tag/Connectors#operation/getConnector
35+
type ConnectorDetail struct {
36+
Connector Connector `json:"connector"`
37+
CreatedAt int64 `json:"createdAt"`
38+
LastModifiedAt int64 `json:"lastModifiedAt"`
39+
Status ConnectorStatus `json:"status"`
40+
ActivityDetails ActivityDetails `json:"activityDetails"`
41+
HarnessManaged bool `json:"harnessManaged"`
42+
GitDetails GitDetails `json:"gitDetails"`
43+
EntityValidityDetails EntityValidityDetails `json:"entityValidityDetails"`
44+
GovernanceMetadata interface{} `json:"governanceMetadata,omitempty"`
45+
IsFavorite bool `json:"isFavorite"`
46+
}
47+
48+
// Connector represents the core connector information.
49+
type Connector struct {
50+
Name string `json:"name"`
51+
Identifier string `json:"identifier"`
52+
Description string `json:"description"`
53+
AccountIdentifier string `json:"accountIdentifier"`
54+
OrgIdentifier string `json:"orgIdentifier"`
55+
ProjectIdentifier string `json:"projectIdentifier"`
56+
Tags map[string]string `json:"tags"`
57+
Type string `json:"type"`
58+
Spec map[string]interface{} `json:"spec"`
59+
}
60+
61+
// ConnectorStatus represents the status information of a connector.
62+
type ConnectorStatus struct {
63+
Status string `json:"status"`
64+
ErrorSummary string `json:"errorSummary"`
65+
Errors []ConnectorError `json:"errors"`
66+
TestedAt int64 `json:"testedAt"`
67+
LastTestedAt int64 `json:"lastTestedAt"`
68+
LastConnectedAt int64 `json:"lastConnectedAt"`
69+
LastAlertSent int64 `json:"lastAlertSent"`
70+
}
71+
72+
// ConnectorError represents an error in connector status.
73+
type ConnectorError struct {
74+
Reason string `json:"reason"`
75+
Message string `json:"message"`
76+
Code int `json:"code"`
77+
}
78+
79+
// ActivityDetails represents the activity information of a connector.
80+
type ActivityDetails struct {
81+
LastActivityTime int64 `json:"lastActivityTime"`
82+
}
83+
84+
// GitDetails represents git-related information of a connector.
85+
type GitDetails struct {
86+
Valid bool `json:"valid"`
87+
InvalidYaml string `json:"invalidYaml"`
88+
}
89+
90+
// EntityValidityDetails represents the validity information of a connector.
91+
type EntityValidityDetails struct {
92+
Valid bool `json:"valid"`
93+
InvalidYaml string `json:"invalidYaml"`
94+
}

pkg/harness/tools.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,43 @@ func ListConnectorCatalogueTool(harnessConfig *config.Config, c *client.Client)
7474
}
7575
}
7676

77+
// GetConnectorDetailsTool creates a tool for getting details of a specific connector
78+
// https://apidocs.harness.io/tag/Connectors#operation/getConnector
79+
func GetConnectorDetailsTool(config *config.Config, c *client.Client) (mcp.Tool, server.ToolHandlerFunc) {
80+
return mcp.NewTool("get_connector_details",
81+
mcp.WithDescription("Get detailed information about a specific connector."),
82+
mcp.WithString("connector_identifier",
83+
mcp.Required(),
84+
mcp.Description("The identifier of the connector"),
85+
),
86+
WithScope(config, false),
87+
),
88+
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
89+
connectorIdentifier, err := requiredParam[string](request, "connector_identifier")
90+
if err != nil {
91+
return mcp.NewToolResultError(err.Error()), nil
92+
}
93+
94+
scope, err := fetchScope(config, request, false)
95+
if err != nil {
96+
return mcp.NewToolResultError(err.Error()), nil
97+
}
98+
99+
connectorService := client.ConnectorService{Client: c}
100+
data, err := connectorService.GetConnector(ctx, scope, connectorIdentifier)
101+
if err != nil {
102+
return nil, fmt.Errorf("failed to get connector: %w", err)
103+
}
104+
105+
r, err := json.Marshal(data)
106+
if err != nil {
107+
return nil, fmt.Errorf("failed to marshal connector: %w", err)
108+
}
109+
110+
return mcp.NewToolResultText(string(r)), nil
111+
}
112+
}
113+
77114
// InitToolsets initializes and returns the toolset groups
78115
func InitToolsets(config *config.Config) (*toolsets.ToolsetGroup, error) {
79116
// Create a toolset group
@@ -355,6 +392,7 @@ func registerConnectors(config *config.Config, tsg *toolsets.ToolsetGroup) error
355392
connectors := toolsets.NewToolset("connectors", "Harness Connector related tools").
356393
AddReadTools(
357394
toolsets.NewServerTool(ListConnectorCatalogueTool(config, c)),
395+
toolsets.NewServerTool(GetConnectorDetailsTool(config, c)),
358396
)
359397

360398
tsg.AddToolset(connectors)

0 commit comments

Comments
 (0)