-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtool_attempts.go
More file actions
61 lines (52 loc) · 1.72 KB
/
tool_attempts.go
File metadata and controls
61 lines (52 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package mcp
import (
"context"
"fmt"
mcpsdk "github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/hookdeck/hookdeck-cli/pkg/hookdeck"
)
func handleAttempts(client *hookdeck.Client) mcpsdk.ToolHandler {
return func(ctx context.Context, req *mcpsdk.CallToolRequest) (*mcpsdk.CallToolResult, error) {
if r := requireAuth(client); r != nil {
return r, nil
}
in, err := parseInput(req.Params.Arguments)
if err != nil {
return ErrorResult(err.Error()), nil
}
action := in.String("action")
switch action {
case "list", "":
return attemptsList(ctx, client, in)
case "get":
return attemptsGet(ctx, client, in)
default:
return ErrorResult(fmt.Sprintf("unknown action %q; expected list or get", action)), nil
}
}
}
func attemptsList(ctx context.Context, client *hookdeck.Client, in input) (*mcpsdk.CallToolResult, error) {
params := make(map[string]string)
setIfNonEmpty(params, "event_id", in.String("event_id"))
setInt(params, "limit", in.Int("limit", 0))
setIfNonEmpty(params, "order_by", in.String("order_by"))
setIfNonEmpty(params, "dir", in.String("dir"))
setIfNonEmpty(params, "next", in.String("next"))
setIfNonEmpty(params, "prev", in.String("prev"))
result, err := client.ListAttempts(ctx, params)
if err != nil {
return ErrorResult(TranslateAPIError(err)), nil
}
return JSONResultEnvelopeForClient(result, client)
}
func attemptsGet(ctx context.Context, client *hookdeck.Client, in input) (*mcpsdk.CallToolResult, error) {
id := in.String("id")
if id == "" {
return ErrorResult("id is required for the get action"), nil
}
attempt, err := client.GetAttempt(ctx, id)
if err != nil {
return ErrorResult(TranslateAPIError(err)), nil
}
return JSONResultEnvelopeForClient(attempt, client)
}