Skip to content

Commit 7c72046

Browse files
authored
Merge pull request #488 from hookdeck/feat/mcp-list-include-data
feat(gateway): add include=data to event and request listings
2 parents b15780a + 7f11d5f commit 7c72046

21 files changed

Lines changed: 1064 additions & 27 deletions

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,8 @@ The usual flow is plural to find an ID, then singular with that ID. The split ke
698698

699699
`gateway_events_read` and `gateway_requests_read` **list** actions support the same filters as `hookdeck gateway event list` and `hookdeck gateway request list` — including payload search (`body`, `headers`, `parsed_query`, `path`) and date windows via `*_after` / `*_before` (ISO 8601; maps to API `field[gte]` / `field[lte]`). See `gateway_help` with topic `gateway_events_read` or `gateway_requests_read` for the full parameter list.
700700

701+
Both **list** actions also take `include: "data"`, which returns each event's or request's payload (headers, body, path, parsed query) in the list itself, so an agent that needs several payloads makes one call instead of one per record. Payloads make responses much larger, so pair it with a small `limit` and page with `next`. When `include` is set without a `limit`, the tool sends `limit=10` rather than the API's default page size. `list_ignored` does not take it: its route does not declare `include`. On the command line, the same option is `--include data` on `gateway event list`, `gateway request list` and `gateway request events`; it requires `--output json`, and the limit defaults to 10 there too.
702+
701703
The only relationship traversal the API supports is request → events, and `gateway_events_read` owns both directions of it. Pass `request_id` with action `list` for the events a request produced, or action `list_ignored` for the ones a connection filter dropped. `GET /events` declares no `request_id` filter, so the tool queries the request's own events route instead — it takes the same filters, so every argument still applies (`list_ignored`'s route is the exception: it takes `id`, paging and ordering only). There is no `event_id` filter on requests. To go the other way, read `request_id` off an event and call `gateway_request_read` with action `get`.
702704

703705
`gateway_help` reports which mode the session is in and lists only the actions it can perform.

‎REFERENCE.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,9 @@ List events (processed webhook deliveries). Filter by connection ID, source, des
15931593
Use `--search-term` to find a complete value across the body, headers, parsed query or path
15941594
at once, when you know the value but not which field carries it.
15951595
1596+
Use `--include`=data with `--output`=json to get each event's payload in the results, instead of
1597+
fetching events one at a time. Without `--limit`, the limit is then 10 instead of 100.
1598+
15961599
**Usage:**
15971600
15981601
```bash
@@ -1615,6 +1618,7 @@ hookdeck gateway event list [flags]
16151618
| `--error-code` | `string` | Filter by error code |
16161619
| `--headers` | `string` | Filter by headers (JSON string) |
16171620
| `--id` | `string` | Filter by event ID(s) (comma-separated) |
1621+
| `--include` | `string` | Set to "data" to include each event's payload (headers, body, path, parsed query) in the results. Requires `--output` json. Responses grow with every payload: when `--limit` is not set it defaults to 10 instead of 100 |
16181622
| `--issue-id` | `string` | Filter by issue ID |
16191623
| `--last-attempt-at-after` | `string` | Filter by last_attempt_at after (ISO date-time) |
16201624
| `--last-attempt-at-before` | `string` | Filter by last_attempt_at before (ISO date-time) |
@@ -1642,6 +1646,7 @@ hookdeck gateway event list --connection-id web_abc123
16421646
hookdeck gateway event list --status FAILED --limit 20
16431647
hookdeck gateway event list --search-term cus_1234
16441648
hookdeck gateway event list --status QUEUED --next-attempt-at-before 2026-01-01T00:00:00Z
1649+
hookdeck gateway event list --status FAILED --include data --output json
16451650
```
16461651
### hookdeck gateway event get
16471652
@@ -1743,6 +1748,9 @@ Use `--search-term` to find a complete value across the body, headers, parsed qu
17431748
at once. `--events-count` 0 finds requests that produced no events, which is the usual reason a
17441749
webhook appears to have gone missing.
17451750
1751+
Use `--include`=data with `--output`=json to get each request's payload in the results, instead of
1752+
fetching requests one at a time. Without `--limit`, the limit is then 10 instead of 100.
1753+
17461754
**Usage:**
17471755
17481756
```bash
@@ -1762,6 +1770,7 @@ hookdeck gateway request list [flags]
17621770
| `--headers` | `string` | Filter by headers (JSON string) |
17631771
| `--id` | `string` | Filter by request ID(s) (comma-separated) |
17641772
| `--ignored-count` | `string` | Filter by number of ignored events. A whole number |
1773+
| `--include` | `string` | Set to "data" to include each request's payload (headers, body, path, parsed query) in the results. Requires `--output` json. Responses grow with every payload: when `--limit` is not set it defaults to 10 instead of 100 |
17651774
| `--ingested-at-after` | `string` | Filter by ingested_at after (ISO date-time) |
17661775
| `--ingested-at-before` | `string` | Filter by ingested_at before (ISO date-time) |
17671776
| `--limit` | `int` | Limit number of results (default "100") |
@@ -1784,6 +1793,7 @@ hookdeck gateway request list
17841793
hookdeck gateway request list --source-id src_abc123 --limit 20
17851794
hookdeck gateway request list --search-term cus_1234
17861795
hookdeck gateway request list --events-count 0
1796+
hookdeck gateway request list --source-id src_abc123 --include data --output json
17871797
```
17881798
### hookdeck gateway request get
17891799
@@ -1835,6 +1845,12 @@ List events (deliveries) created from a request.
18351845
Filters match `hookdeck gateway event list`: this command queries the same event
18361846
collection, narrowed to one request.
18371847
1848+
Use `--include`=data with `--output`=json to get each event's payload in the results. Without
1849+
`--limit`, the limit is then 10 instead of 100.
1850+
1851+
When the request has more events than fit on one page, a note on stderr gives the cursor to
1852+
pass to `--next` for the following page.
1853+
18381854
**Usage:**
18391855
18401856
```bash
@@ -1856,6 +1872,7 @@ hookdeck gateway request events <request-id> [flags]
18561872
| `--dir` | `string` | Sort direction (asc, desc) |
18571873
| `--error-code` | `string` | Filter by error code |
18581874
| `--headers` | `string` | Filter by headers (JSON string) |
1875+
| `--include` | `string` | Set to "data" to include each event's payload (headers, body, path, parsed query) in the results. Requires `--output` json. Responses grow with every payload: when `--limit` is not set it defaults to 10 instead of 100 |
18591876
| `--issue-id` | `string` | Filter by issue ID |
18601877
| `--last-attempt-at-after` | `string` | Filter by last_attempt_at after (ISO date-time) |
18611878
| `--last-attempt-at-before` | `string` | Filter by last_attempt_at before (ISO date-time) |
@@ -1881,6 +1898,7 @@ hookdeck gateway request events <request-id> [flags]
18811898
hookdeck gateway request events req_abc123
18821899
hookdeck gateway request events req_abc123 --status FAILED
18831900
hookdeck gateway request events req_abc123 --destination-id des_abc123
1901+
hookdeck gateway request events req_abc123 --include data --output json
18841902
```
18851903
### hookdeck gateway request ignored-events
18861904

‎pkg/cmd/event_list.go‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type eventListCmd struct {
3939
path string
4040
parsedQuery string
4141
searchTerm string
42+
include string
4243
orderBy string
4344
dir string
4445
limit int
@@ -59,12 +60,16 @@ func newEventListCmd() *eventListCmd {
5960
Use --search-term to find a complete value across the body, headers, parsed query or path
6061
at once, when you know the value but not which field carries it.
6162
63+
Use --include=data with --output=json to get each event's payload in the results, instead of
64+
fetching events one at a time. Without --limit, the limit is then 10 instead of 100.
65+
6266
Examples:
6367
hookdeck gateway event list
6468
hookdeck gateway event list --connection-id web_abc123
6569
hookdeck gateway event list --status FAILED --limit 20
6670
hookdeck gateway event list --search-term cus_1234
67-
hookdeck gateway event list --status QUEUED --next-attempt-at-before 2026-01-01T00:00:00Z`,
71+
hookdeck gateway event list --status QUEUED --next-attempt-at-before 2026-01-01T00:00:00Z
72+
hookdeck gateway event list --status FAILED --include data --output json`,
6873
RunE: ec.runEventListCmd,
6974
}
7075

@@ -92,6 +97,7 @@ Examples:
9297
ec.cmd.Flags().StringVar(&ec.path, "path", "", "Filter by path")
9398
ec.cmd.Flags().StringVar(&ec.parsedQuery, "parsed-query", "", "Filter by parsed query (JSON string)")
9499
ec.cmd.Flags().StringVar(&ec.searchTerm, "search-term", "", "Match a whole value in body, headers, parsed query or path. Not a substring (min 3 characters)")
100+
ec.cmd.Flags().StringVar(&ec.include, "include", "", includeFlagUsage("event"))
95101
ec.cmd.Flags().StringVar(&ec.orderBy, "order-by", "", "Sort key (e.g. created_at)")
96102
ec.cmd.Flags().StringVar(&ec.dir, "dir", "", "Sort direction (asc, desc)")
97103
ec.cmd.Flags().IntVar(&ec.limit, "limit", 100, "Limit number of results")
@@ -197,7 +203,11 @@ func (ec *eventListCmd) runEventListCmd(cmd *cobra.Command, args []string) error
197203
if ec.dir != "" {
198204
params["dir"] = ec.dir
199205
}
200-
params["limit"] = strconv.Itoa(ec.limit)
206+
limit, err := applyIncludeData(cmd, ec.include, ec.output, ec.limit, params)
207+
if err != nil {
208+
return err
209+
}
210+
params["limit"] = strconv.Itoa(limit)
201211
if ec.next != "" {
202212
params["next"] = ec.next
203213
}

‎pkg/cmd/gateway_list_filters_test.go‎

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ import (
2626
// filter, because the answer looks right.
2727
func captureListQuery(t *testing.T, args ...string) url.Values {
2828
t.Helper()
29+
got, err := runListQuery(t, args...)
30+
require.NoError(t, err)
31+
require.NotNil(t, got, "the command made no list request")
32+
return got
33+
}
34+
35+
// runListQuery is captureListQuery for a command that may fail: it returns the
36+
// error and the query sent, which is nil when no list request was made.
37+
func runListQuery(t *testing.T, args ...string) (url.Values, error) {
38+
t.Helper()
2939

3040
var got url.Values
3141
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -60,9 +70,8 @@ func captureListQuery(t *testing.T, args ...string) url.Values {
6070
root.SetOut(io.Discard)
6171
root.SetErr(io.Discard)
6272

63-
require.NoError(t, root.Execute())
64-
require.NotNil(t, got, "the command made no list request")
65-
return got
73+
err := root.Execute()
74+
return got, err
6675
}
6776

6877
func TestEventListSendsNewFilters(t *testing.T) {
@@ -128,13 +137,16 @@ func TestListFiltersAreOmittedWhenUnset(t *testing.T) {
128137
// forgot, which is how they would get added — this pins the omission as
129138
// intentional. The MCP side is pinned by
130139
// TestPluralToolsOmitParametersHiddenFromTheAPIDocs.
140+
//
141+
// include is not in this list: the API documents it on these endpoints, and
142+
// the CLI offers it as --include; see TestListIncludeData.
131143
func TestListCommandsOmitFlagsHiddenFromTheAPIDocs(t *testing.T) {
132144
root := &cobra.Command{Use: "hookdeck"}
133145
root.AddCommand(newGatewayCmd().cmd)
134146

135147
cases := map[string][]string{
136-
"event": {"bulk-retry-id", "include", "progressive", "event-data-id", "cli-user-id"},
137-
"request": {"bulk-retry-id", "include", "progressive"},
148+
"event": {"bulk-retry-id", "progressive", "event-data-id", "cli-user-id"},
149+
"request": {"bulk-retry-id", "progressive"},
138150
}
139151

140152
for resource, hidden := range cases {
@@ -151,3 +163,37 @@ func TestListCommandsOmitFlagsHiddenFromTheAPIDocs(t *testing.T) {
151163
})
152164
}
153165
}
166+
167+
// TestListIncludeData covers --include on both list commands, which share
168+
// applyIncludeData but each call it separately, so each is tested.
169+
func TestListIncludeData(t *testing.T) {
170+
for _, resource := range []string{"event", "request"} {
171+
t.Run(resource+" sends include and the smaller default limit", func(t *testing.T) {
172+
query := captureListQuery(t, "gateway", resource, "list", "--include", "data", "--output", "json")
173+
assert.Equal(t, "data", query.Get("include"))
174+
assert.Equal(t, "10", query.Get("limit"),
175+
"a page of payloads must not default to 100")
176+
})
177+
178+
t.Run(resource+" honours an explicit limit", func(t *testing.T) {
179+
query := captureListQuery(t, "gateway", resource, "list", "--include", "data", "--output", "json", "--limit", "50")
180+
assert.Equal(t, "data", query.Get("include"))
181+
assert.Equal(t, "50", query.Get("limit"))
182+
})
183+
184+
t.Run(resource+" without include is unchanged", func(t *testing.T) {
185+
query := captureListQuery(t, "gateway", resource, "list")
186+
assert.NotContains(t, query, "include")
187+
assert.Equal(t, "100", query.Get("limit"))
188+
})
189+
190+
// The list output prints IDs and a summary line, so payloads fetched
191+
// for it would be thrown away. Refused before any request is made.
192+
t.Run(resource+" refuses include without --output json", func(t *testing.T) {
193+
query, err := runListQuery(t, "gateway", resource, "list", "--include", "data")
194+
require.Error(t, err)
195+
assert.Contains(t, err.Error(), "--output json")
196+
assert.Nil(t, query, "no list request should be made")
197+
})
198+
}
199+
}

‎pkg/cmd/list_include.go‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package cmd
2+
3+
import (
4+
"errors"
5+
"strconv"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
// includeDataDefaultLimit is the page size sent when --include is set without
11+
// --limit, matching the MCP list tools.
12+
//
13+
// The usual default of 100 is fine for IDs and metadata. With payloads it is a
14+
// hundred webhook bodies in one response, which is more than a terminal or a
15+
// script piping to jq wants by accident. An explicit --limit is honoured.
16+
const includeDataDefaultLimit = 10
17+
18+
// includeFlagUsage is the --include help for event list and request list.
19+
func includeFlagUsage(resource string) string {
20+
return `Set to "data" to include each ` + resource + `'s payload (headers, body, path, parsed query) in the results. ` +
21+
`Requires --output json. Responses grow with every payload: when --limit is not set it defaults to ` +
22+
strconv.Itoa(includeDataDefaultLimit) + ` instead of 100`
23+
}
24+
25+
// applyIncludeData adds include to the list query and returns the limit to
26+
// send.
27+
//
28+
// The API declares include on GET /events and GET /requests with one value,
29+
// "data"; any other value is left for the API to reject. --include is refused
30+
// without --output json because the list output prints IDs and a summary
31+
// line, so the payloads would be fetched and then not shown.
32+
func applyIncludeData(cmd *cobra.Command, include, output string, limit int, params map[string]string) (int, error) {
33+
if include == "" {
34+
return limit, nil
35+
}
36+
if output != "json" {
37+
return 0, errors.New("--include requires --output json: the list output does not show payloads")
38+
}
39+
params["include"] = include
40+
if !cmd.Flags().Changed("limit") {
41+
return includeDataDefaultLimit, nil
42+
}
43+
return limit, nil
44+
}

‎pkg/cmd/request_events.go‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type requestEventsCmd struct {
4545
parsedQuery string
4646
orderBy string
4747
dir string
48+
include string
4849
}
4950

5051
func newRequestEventsCmd() *requestEventsCmd {
@@ -59,10 +60,17 @@ func newRequestEventsCmd() *requestEventsCmd {
5960
Filters match ` + "`hookdeck gateway event list`" + `: this command queries the same event
6061
collection, narrowed to one request.
6162
63+
Use --include=data with --output=json to get each event's payload in the results. Without
64+
--limit, the limit is then 10 instead of 100.
65+
66+
When the request has more events than fit on one page, a note on stderr gives the cursor to
67+
pass to --next for the following page.
68+
6269
Examples:
6370
hookdeck gateway request events req_abc123
6471
hookdeck gateway request events req_abc123 --status FAILED
65-
hookdeck gateway request events req_abc123 --destination-id des_abc123`,
72+
hookdeck gateway request events req_abc123 --destination-id des_abc123
73+
hookdeck gateway request events req_abc123 --include data --output json`,
6674
RunE: rc.runRequestEventsCmd,
6775
}
6876

@@ -97,6 +105,7 @@ Examples:
97105
rc.cmd.Flags().StringVar(&rc.body, "body", "", "Filter by body (JSON string)")
98106
rc.cmd.Flags().StringVar(&rc.path, "path", "", "Filter by path")
99107
rc.cmd.Flags().StringVar(&rc.parsedQuery, "parsed-query", "", "Filter by parsed query (JSON string)")
108+
rc.cmd.Flags().StringVar(&rc.include, "include", "", includeFlagUsage("event"))
100109
rc.cmd.Flags().StringVar(&rc.orderBy, "order-by", "", "Sort key (e.g. created_at)")
101110
rc.cmd.Flags().StringVar(&rc.dir, "dir", "", "Sort direction (asc, desc)")
102111
rc.cmd.Flags().IntVar(&rc.limit, "limit", 100, "Limit number of results")
@@ -122,7 +131,12 @@ func (rc *requestEventsCmd) runRequestEventsCmd(cmd *cobra.Command, args []strin
122131
requestID := args[0]
123132
client := Config.GetAPIClient()
124133
ctx := context.Background()
125-
params := map[string]string{"limit": strconv.Itoa(rc.limit)}
134+
params := map[string]string{}
135+
limit, err := applyIncludeData(cmd, rc.include, rc.output, rc.limit, params)
136+
if err != nil {
137+
return err
138+
}
139+
params["limit"] = strconv.Itoa(limit)
126140
if rc.next != "" {
127141
params["next"] = rc.next
128142
}
@@ -211,6 +225,15 @@ func (rc *requestEventsCmd) runRequestEventsCmd(cmd *cobra.Command, args []strin
211225
return fmt.Errorf("failed to list request events: %w", err)
212226
}
213227

228+
// The output carries no pagination cursor (the JSON is a bare array), so a
229+
// page the API cut short would look complete. When the API says there is
230+
// more, say so on stderr, which leaves the JSON on stdout intact, and give
231+
// the cursor --next takes. This applies with or without --include: the
232+
// --include default of 10 makes it likelier, but 100 events is also a page.
233+
if next := resp.Pagination.Next; next != nil && *next != "" {
234+
fmt.Fprintf(os.Stderr, "More events exist for this request. Pass --next %s for the next page, or a larger --limit.\n", *next)
235+
}
236+
214237
if rc.output == "json" {
215238
if len(resp.Models) == 0 {
216239
fmt.Println("[]")

0 commit comments

Comments
 (0)