Repository navigation
fix(cloudflare): fetch tunnel connections from dedicated endpoint after API removal #8623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cb05f50
1056845
733f4e9
1e86bcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ export const getTunnelTool: ToolConfig<CloudflareGetTunnelParams, CloudflareTunn | |
| id: 'cloudflare_get_tunnel', | ||
| name: 'Cloudflare Get Tunnel', | ||
| description: | ||
| 'Reads a single Cloudflare Tunnel (cloudflared), including its health status and active connector connections. Requires an API token with Account Cloudflare Tunnel Read.', | ||
| '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.', | ||
| version: '1.0.0', | ||
|
|
||
| params: { | ||
|
|
@@ -37,7 +37,7 @@ export const getTunnelTool: ToolConfig<CloudflareGetTunnelParams, CloudflareTunn | |
| headers: (params) => cloudflareHeaders(params.apiKey), | ||
| }, | ||
|
|
||
| transformResponse: async (response: Response) => { | ||
| transformResponse: async (response: Response, params?: CloudflareGetTunnelParams) => { | ||
| const data = await response.json() | ||
|
|
||
| if (!data.success) { | ||
|
|
@@ -63,6 +63,25 @@ export const getTunnelTool: ToolConfig<CloudflareGetTunnelParams, CloudflareTunn | |
| } | ||
|
|
||
| const tunnel = data.result | ||
| let connections: unknown[] | null = null | ||
| if (params?.accountId && params?.tunnelId && params?.apiKey) { | ||
| try { | ||
| const connectionsUrl = `https://api.cloudflare.com/client/v4/accounts/${params.accountId.trim()}/cfd_tunnel/${params.tunnelId.trim()}/connections` | ||
| const connectionsRes = await fetch(connectionsUrl, { | ||
| method: 'GET', | ||
| headers: cloudflareHeaders(params.apiKey), | ||
| }) | ||
| const connectionsData = await connectionsRes.json() | ||
| if (connectionsData?.success && Array.isArray(connectionsData.result)) { | ||
| connections = connectionsData.result.flatMap( | ||
| (connector: { conns?: unknown[] }) => connector.conns ?? [] | ||
| ) | ||
|
Comment on lines
+75
to
+78
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new flattening of connector responses has no regression test, and the existing Cloudflare tests cover block parameter defaults rather than this response. A response-shape mistake or silently empty Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| } | ||
| } catch { | ||
| connections = null | ||
| } | ||
|
Comment on lines
+74
to
+82
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If Cloudflare rejects the connections request or it fails, the tool still reports success with |
||
| } | ||
|
|
||
| return { | ||
| success: true, | ||
| output: { | ||
|
|
@@ -78,7 +97,7 @@ export const getTunnelTool: ToolConfig<CloudflareGetTunnelParams, CloudflareTunn | |
| deleted_at: tunnel?.deleted_at ?? null, | ||
| conns_active_at: tunnel?.conns_active_at ?? null, | ||
| conns_inactive_at: tunnel?.conns_inactive_at ?? null, | ||
| connections: tunnel?.connections ?? null, | ||
| connections, | ||
| }, | ||
| } | ||
| }, | ||
|
|
@@ -126,7 +145,8 @@ export const getTunnelTool: ToolConfig<CloudflareGetTunnelParams, CloudflareTunn | |
| }, | ||
| connections: { | ||
| type: 'json', | ||
| description: 'Active connector connections for the tunnel', | ||
| description: | ||
| 'Active connector connections for the tunnel (from GET .../cfd_tunnel/{id}/connections)', | ||
| optional: true, | ||
| }, | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a workflow is cancelled or its deadline expires while Cloudflare's connections request is pending, this new
fetchhas neither the execution signal nor a timeout. Unlike the initial tunnel request, it can keepcloudflare_get_tunnelpending after cancellation. Pass the signal supplied totransformResponseand bound the request.