Skip to content

Commit 1e86bcb

Browse files
fix(cloudflare): fetch tunnel connections from dedicated endpoint after API removal
1 parent 733f4e9 commit 1e86bcb

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

‎apps/sim/tools/cloudflare/get_tunnel.ts‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const getTunnelTool: ToolConfig<CloudflareGetTunnelParams, CloudflareTunn
66
id: 'cloudflare_get_tunnel',
77
name: 'Cloudflare Get Tunnel',
88
description:
9-
'Reads a single Cloudflare Tunnel (cloudflared), including its health status and active connector connections. Requires an API token with Account Cloudflare Tunnel Read.',
9+
'Reads a single Cloudflare Tunnel (cloudflared), including its health status and active connector connections (from the dedicated connections endpoint). Requires an API token with Account Cloudflare Tunnel Read.',
1010
version: '1.0.0',
1111

1212
params: {
@@ -37,7 +37,7 @@ export const getTunnelTool: ToolConfig<CloudflareGetTunnelParams, CloudflareTunn
3737
headers: (params) => cloudflareHeaders(params.apiKey),
3838
},
3939

40-
transformResponse: async (response: Response) => {
40+
transformResponse: async (response: Response, params?: CloudflareGetTunnelParams) => {
4141
const data = await response.json()
4242

4343
if (!data.success) {
@@ -63,6 +63,25 @@ export const getTunnelTool: ToolConfig<CloudflareGetTunnelParams, CloudflareTunn
6363
}
6464

6565
const tunnel = data.result
66+
let connections: unknown[] | null = null
67+
if (params?.accountId && params?.tunnelId && params?.apiKey) {
68+
try {
69+
const connectionsUrl = `https://api.cloudflare.com/client/v4/accounts/${params.accountId.trim()}/cfd_tunnel/${params.tunnelId.trim()}/connections`
70+
const connectionsRes = await fetch(connectionsUrl, {
71+
method: 'GET',
72+
headers: cloudflareHeaders(params.apiKey),
73+
})
74+
const connectionsData = await connectionsRes.json()
75+
if (connectionsData?.success && Array.isArray(connectionsData.result)) {
76+
connections = connectionsData.result.flatMap(
77+
(connector: { conns?: unknown[] }) => connector.conns ?? []
78+
)
79+
}
80+
} catch {
81+
connections = null
82+
}
83+
}
84+
6685
return {
6786
success: true,
6887
output: {
@@ -78,7 +97,7 @@ export const getTunnelTool: ToolConfig<CloudflareGetTunnelParams, CloudflareTunn
7897
deleted_at: tunnel?.deleted_at ?? null,
7998
conns_active_at: tunnel?.conns_active_at ?? null,
8099
conns_inactive_at: tunnel?.conns_inactive_at ?? null,
81-
connections: tunnel?.connections ?? null,
100+
connections,
82101
},
83102
}
84103
},
@@ -126,7 +145,8 @@ export const getTunnelTool: ToolConfig<CloudflareGetTunnelParams, CloudflareTunn
126145
},
127146
connections: {
128147
type: 'json',
129-
description: 'Active connector connections for the tunnel',
148+
description:
149+
'Active connector connections for the tunnel (from GET .../cfd_tunnel/{id}/connections)',
130150
optional: true,
131151
},
132152
},

‎apps/sim/tools/cloudflare/list_tunnels.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const listTunnelsTool: ToolConfig<
1818
id: 'cloudflare_list_tunnels',
1919
name: 'Cloudflare List Tunnels',
2020
description:
21-
'Lists the Cloudflare Tunnels (cloudflared) in an account, with their health status and active connections. Requires an API token with Account Cloudflare Tunnel Read.',
21+
'Lists the Cloudflare Tunnels (cloudflared) in an account, with their health status. Connections are no longer included on list responses (Cloudflare API change 2026-10-05); use cloudflare_get_tunnel for a tunnel’s connections. Requires an API token with Account Cloudflare Tunnel Read.',
2222
version: '1.0.0',
2323

2424
params: {
@@ -155,7 +155,7 @@ export const listTunnelsTool: ToolConfig<
155155
deleted_at: tunnel.deleted_at ?? null,
156156
conns_active_at: tunnel.conns_active_at ?? null,
157157
conns_inactive_at: tunnel.conns_inactive_at ?? null,
158-
connections: tunnel.connections ?? null,
158+
connections: null,
159159
})),
160160
total_count: data.result_info?.total_count ?? tunnels.length,
161161
},
@@ -215,7 +215,8 @@ export const listTunnelsTool: ToolConfig<
215215
},
216216
connections: {
217217
type: 'json',
218-
description: 'Active connector connections for the tunnel',
218+
description:
219+
'Always null on list. Use cloudflare_get_tunnel to fetch active connections for a specific tunnel.',
219220
optional: true,
220221
},
221222
},

0 commit comments

Comments
 (0)