Skip to content

Commit 871e3d2

Browse files
deepharnessHarness
authored andcommitted
feat: [SSCA-4164]: remove raw result handling from ToolResultBuilder and update service URLs (#98)
* refactor: remove raw result handling from ToolResultBuilder and update service URLs * feat: add taskfile for SCS and STO codegen with OpenAPI specs * feat: implement STO authentication with API key token retrieval * feat: add OpenAPI spec for SSCA service endpoints * feat: add openapi spec and logging improvements for auth and events * refactor: move utility functions to new response package and add SLSA verification endpoints
1 parent 0795881 commit 871e3d2

File tree

9 files changed

+331
-172
lines changed

9 files changed

+331
-172
lines changed

pkg/appseccommons/utility.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

pkg/harness/event/builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ func CreateBaseResponse(eventType string, tool string) map[string]interface{} {
2525
"entity_info": map[string]string{
2626
"entity_type": tool,
2727
},
28-
"type": eventType,
28+
"type": eventType,
29+
"description": "THIS EVENT IS NOT INTENDED TO BE USED BY LLM. IT IS ONLY FOR INTERNAL USE.IGNORE THIS EVENT",
2930
}
3031
}
3132

pkg/harness/event/common/builder.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ const (
1515
GenericTableEvent EventType = "table"
1616
OPAEvent EventType = "opa"
1717
PromptEvent EventType = "prompt"
18+
RawEvent EventType = "raw"
1819
)
1920

2021
var Reg = builder.Registry{
2122
string(GenericTableEvent): GenericTableBuilder{},
2223
string(OPAEvent): OPABuilder{},
2324
string(PromptEvent): PromptBuilder{},
25+
string(RawEvent): RawBuilder{},
2426
}
2527

2628
type GenericTableBuilder struct{}
@@ -94,6 +96,28 @@ func (GenericTableBuilder) Build(raw json.RawMessage, tool string, args ...any)
9496

9597
type OPABuilder struct{}
9698

99+
type RawBuilder struct{}
100+
101+
func (RawBuilder) Build(raw json.RawMessage, tool string, args ...any) string {
102+
eventType := string(RawEvent)
103+
104+
// Create base response with consistent structure
105+
env := builder.CreateBaseResponse(eventType, tool)
106+
env["description"] = "THIS IS A RAW EVENT.INTENDED TO USE BY LLM TO UNDERSTAND THE TOOL RESPONSE. DO NOT CREATE ANY TABLES FROM THIS EVENT"
107+
// Parse the raw JSON into a generic interface
108+
var data interface{}
109+
if err := json.Unmarshal(raw, &data); err != nil {
110+
// Return a safe error response
111+
return fmt.Sprintf(`{"type": "%s", "error": "Failed to parse raw data"}`, eventType)
112+
}
113+
114+
// Add raw data to the response
115+
env["data"] = data
116+
117+
// Format the response using the common formatter
118+
return builder.FormatEventResponse(eventType, env)
119+
}
120+
97121
type PromptBuilder struct{}
98122

99123
func (PromptBuilder) Build(raw json.RawMessage, tool string, args ...any) string {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package response
2+
3+
import (
4+
"encoding/json"
5+
"log/slog"
6+
7+
builder "github.com/harness/harness-mcp/pkg/harness/event/common"
8+
"github.com/mark3labs/mcp-go/mcp"
9+
)
10+
11+
// EventData represents an event with its type, data, and optional arguments
12+
type EventData struct {
13+
EventType string
14+
Event []byte
15+
Args []any
16+
}
17+
18+
// ToolResultBuilder helps build tool results with multiple events
19+
type ToolResultBuilder struct {
20+
module string
21+
events []EventData
22+
}
23+
24+
// NewToolResultBuilder creates a new ToolResultBuilder with the specified module
25+
func NewToolResultBuilder(module string) *ToolResultBuilder {
26+
return &ToolResultBuilder{
27+
module: module,
28+
events: []EventData{},
29+
}
30+
}
31+
32+
// AddEvent adds an event to the builder
33+
func (b *ToolResultBuilder) AddEvent(eventType string, event []byte, args ...any) *ToolResultBuilder {
34+
b.events = append(b.events, EventData{
35+
EventType: eventType,
36+
Event: event,
37+
Args: args,
38+
})
39+
return b
40+
}
41+
42+
// AddStringEvent adds an event with string data to the builder
43+
func (b *ToolResultBuilder) AddStringEvent(eventType string, event string, args ...any) *ToolResultBuilder {
44+
return b.AddEvent(eventType, []byte(event), args...)
45+
}
46+
47+
// AddPrompts adds prompts as an event to the builder
48+
func (b *ToolResultBuilder) AddPrompts(prompts []string) *ToolResultBuilder {
49+
if len(prompts) > 0 {
50+
promptData, err := json.Marshal(prompts)
51+
if err != nil {
52+
slog.Error("Failed to marshal prompts", "error", err)
53+
promptData = []byte("[]")
54+
}
55+
return b.AddEvent(string(builder.PromptEvent), promptData)
56+
}
57+
return b
58+
}
59+
60+
// Build creates a CallToolResult with all the added events
61+
func (b *ToolResultBuilder) Build() *mcp.CallToolResult {
62+
var contents []mcp.Content
63+
64+
for _, eventData := range b.events {
65+
contents = append(contents, mcp.TextContent{
66+
Type: "text",
67+
Text: builder.Reg.Build(eventData.EventType, eventData.Event, b.module, eventData.Args...),
68+
})
69+
}
70+
slog.Info("Building tool result", "module", b.module, "events", len(b.events))
71+
return &mcp.CallToolResult{
72+
Content: contents,
73+
}
74+
}

pkg/harness/tools/filter.go

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

33
import (
44
"fmt"
5+
56
"github.com/harness/harness-mcp/client/scs"
67
generated "github.com/harness/harness-mcp/client/scs/generated"
78
"github.com/mark3labs/mcp-go/mcp"
@@ -28,6 +29,7 @@ func ParseArtifactListParams(request mcp.CallToolRequest) (order string, sort st
2829
}
2930
sort, _ = OptionalParam[string](request, "sort")
3031
page, size, _ = FetchPagination(request)
32+
size = 5
3133
sortVal = interface{}(sort)
3234
return
3335
}

0 commit comments

Comments
 (0)