Skip to content

Commit 0cc2f2f

Browse files
committed
more stuff
1 parent 2098e81 commit 0cc2f2f

File tree

5 files changed

+116
-38
lines changed

5 files changed

+116
-38
lines changed

apps/workers-builds/src/tools/builds.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { queryWorkersObservability } from '@repo/mcp-common/src/api/workers-observability'
2-
import { zQueryRunRequest } from '@repo/mcp-common/src/types/workers-logs-schemas'
1+
import { z } from 'zod'
2+
3+
import { getLatestWorkersBuild } from '@repo/mcp-common/src/api/workers-builds.api'
34

45
import type { BuildsMCP } from '../index'
56

@@ -12,15 +13,15 @@ import type { BuildsMCP } from '../index'
1213
export function registerBuildsTools(agent: BuildsMCP) {
1314
// Register the worker logs analysis tool by worker name
1415
agent.server.tool(
15-
'list_workers_builds',
16+
'get_latest_workers_build',
1617
`
17-
Query the Workers Builds API to view builds from your Cloudflare Workers.
18+
Use the Workers Builds API to get the latest build for a Cloudflare Worker.
1819
`.trim(),
1920

2021
{
21-
query: zQueryRunRequest,
22+
scriptId: z.string(),
2223
},
23-
async ({ query }) => {
24+
async ({ scriptId }) => {
2425
const accountId = await agent.getActiveAccountId()
2526
if (!accountId) {
2627
return {
@@ -32,8 +33,13 @@ Query the Workers Builds API to view builds from your Cloudflare Workers.
3233
],
3334
}
3435
}
36+
3537
try {
36-
const res = await queryWorkersObservability(agent.props.accessToken, accountId, query)
38+
const res = await getLatestWorkersBuild({
39+
apiToken: agent.props.accessToken,
40+
accountId,
41+
scriptId,
42+
})
3743
return {
3844
content: [
3945
{
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { fetchCloudflareApi } from '../cloudflare-api'
2+
import { LatestBuildsByScriptResult } from '../types/workers-builds.types'
3+
import { V4Schema } from '../v4-api'
4+
5+
export async function getLatestWorkersBuild({
6+
apiToken,
7+
accountId,
8+
scriptId,
9+
}: {
10+
apiToken: string
11+
accountId: string
12+
scriptId: string
13+
}) {
14+
const data = await fetchCloudflareApi({
15+
endpoint: `/builds/builds/latest?external_script_ids=${scriptId}`,
16+
accountId,
17+
apiToken,
18+
responseSchema: V4Schema(LatestBuildsByScriptResult),
19+
options: {
20+
method: 'GET',
21+
},
22+
})
23+
if (!data.result) {
24+
return null
25+
}
26+
const build = data.result.builds[scriptId]
27+
if (!build) {
28+
return null
29+
}
30+
return build
31+
}

packages/mcp-common/src/api/workers-builds.ts

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

packages/mcp-common/src/tools/worker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ export function registerWorkersTools(agent: CloudflareMcpAgent) {
135135
// Tool to get a specific worker's script content
136136
agent.server.tool(
137137
'worker_get_worker',
138-
'Get the source code of a Cloudflare Worker',
138+
`Get the source code of a Cloudflare Worker
139+
140+
If you need to get the ID of a Worker, use worker_get_worker_details instead.
141+
`.trim(),
139142
{ scriptName: workerNameParam },
140143
async (params) => {
141144
const accountId = await agent.getActiveAccountId()
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { z } from 'zod'
2+
3+
export type LatestBuildsByScriptResult = z.infer<typeof LatestBuildsByScriptResult>
4+
export const LatestBuildsByScriptResult = z.object({
5+
builds: z.record(
6+
z.string(),
7+
z.object({
8+
build_uuid: z.string(),
9+
status: z.string(),
10+
build_outcome: z.string().nullable(),
11+
initializing_on: z.string().nullable(),
12+
running_on: z.string().nullable(),
13+
stopped_on: z.string().nullable(),
14+
created_on: z.string(),
15+
modified_on: z.string(),
16+
trigger: z.object({
17+
trigger_uuid: z.string(),
18+
external_script_id: z.string(),
19+
trigger_name: z.string(),
20+
build_command: z.string(),
21+
deploy_command: z.string(),
22+
root_directory: z.string(),
23+
branch_includes: z.array(z.string()),
24+
branch_excludes: z.array(z.string()),
25+
path_includes: z.array(z.string()),
26+
path_excludes: z.array(z.string()),
27+
build_caching_enabled: z.boolean(),
28+
created_on: z.string(),
29+
modified_on: z.string(),
30+
deleted_on: z.null(),
31+
repo_connection: z.object({
32+
repo_connection_uuid: z.string(),
33+
repo_id: z.string(),
34+
repo_name: z.string(),
35+
provider_type: z.string(),
36+
provider_account_id: z.string(),
37+
provider_account_name: z.string(),
38+
created_on: z.string(),
39+
modified_on: z.string(),
40+
deleted_on: z.null(),
41+
}),
42+
}),
43+
build_trigger_metadata: z.object({
44+
build_trigger_source: z.string(),
45+
branch: z.string(),
46+
commit_hash: z.string(),
47+
commit_message: z.string(),
48+
author: z.string(),
49+
build_command: z.string(),
50+
deploy_command: z.string(),
51+
root_directory: z.string(),
52+
build_token_uuid: z.string(),
53+
environment_variables: z.record(
54+
z.string(),
55+
z.object({
56+
is_secret: z.boolean(),
57+
created_on: z.string(),
58+
value: z.string(),
59+
})
60+
),
61+
repo_name: z.string(),
62+
provider_account_name: z.string(),
63+
provider_type: z.string(),
64+
}),
65+
pull_request: z.unknown(),
66+
})
67+
),
68+
})

0 commit comments

Comments
 (0)