Skip to content

Commit cc064c0

Browse files
committed
initial apphosting mcp tool
1 parent b86a9a6 commit cc064c0

File tree

6 files changed

+68
-0
lines changed

6 files changed

+68
-0
lines changed

src/gcp/apphosting.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,19 @@ export async function getBackend(
333333
return res.body;
334334
}
335335

336+
/**
337+
* Gets traffic details.
338+
*/
339+
export async function getTraffic(
340+
projectId: string,
341+
location: string,
342+
backendId: string,
343+
): Promise<Traffic> {
344+
const name = `projects/${projectId}/locations/${location}/backends/${backendId}/traffic`;
345+
const res = await client.get<Traffic>(name);
346+
return res.body;
347+
}
348+
336349
/**
337350
* List all backends present in a project and location.
338351
*/

src/mcp/tools/apphosting/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { ServerTool } from "../../tool";
2+
import { list_backends } from "./list_backends";
3+
4+
export const appHostingTools: ServerTool[] = [list_backends];
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { z } from "zod";
2+
import { tool } from "../../tool.js";
3+
import { toContent } from "../../util.js";
4+
import { NO_PROJECT_ERROR } from "../../errors.js";
5+
import {
6+
Backend,
7+
getTraffic,
8+
listBackends,
9+
parseBackendName,
10+
Traffic,
11+
} from "../../../gcp/apphosting.js";
12+
13+
export const list_backends = tool(
14+
{
15+
name: "list_backends",
16+
description:
17+
"Retrieves a list of App Hosting backends in the current project. The `uri` is the public URL of the backend.",
18+
inputSchema: z.object({
19+
location: z
20+
.string()
21+
.optional()
22+
.default("-")
23+
.describe("Limit the listed backends to this region."),
24+
}),
25+
annotations: {
26+
title: "List App Hosting backends.",
27+
readOnlyHint: true,
28+
},
29+
_meta: {
30+
requiresAuth: true,
31+
requiresProject: true,
32+
},
33+
},
34+
async ({ location } = {}, { projectId }) => {
35+
if (!projectId) return NO_PROJECT_ERROR;
36+
if (!location) location = "-";
37+
const data: (Backend & { traffic: Traffic })[] = [];
38+
const backends = await listBackends(projectId, location);
39+
for (const backend of backends.backends) {
40+
const { location, id } = parseBackendName(backend.name);
41+
const traffic = await getTraffic(projectId, location, id);
42+
data.push({ ...backend, traffic: traffic });
43+
}
44+
return toContent(data);
45+
},
46+
);

src/mcp/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { coreTools } from "./core/index.js";
77
import { storageTools } from "./storage/index.js";
88
import { messagingTools } from "./messaging/index.js";
99
import { remoteConfigTools } from "./remoteconfig/index.js";
10+
import { appHostingTools } from "./apphosting/index.js";
1011

1112
/** availableTools returns the list of MCP tools available given the server flags */
1213
export function availableTools(activeFeatures?: ServerFeature[]): ServerTool[] {
@@ -28,6 +29,7 @@ const tools: Record<ServerFeature, ServerTool[]> = {
2829
storage: addFeaturePrefix("storage", storageTools),
2930
messaging: addFeaturePrefix("messaging", messagingTools),
3031
remoteconfig: addFeaturePrefix("remoteconfig", remoteConfigTools),
32+
apphosting: addFeaturePrefix("apphosting", appHostingTools),
3133
};
3234

3335
function addFeaturePrefix(feature: string, tools: ServerTool[]): ServerTool[] {

src/mcp/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ export const SERVER_FEATURES = [
55
"auth",
66
"messaging",
77
"remoteconfig",
8+
"apphosting",
89
] as const;
910
export type ServerFeature = (typeof SERVER_FEATURES)[number];

src/mcp/util.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { dump } from "js-yaml";
44
import { platform } from "os";
55
import { ServerFeature } from "./types";
66
import {
7+
apphostingOrigin,
78
authManagementOrigin,
89
dataconnectOrigin,
910
firestoreOrigin,
@@ -85,6 +86,7 @@ const SERVER_FEATURE_APIS: Record<ServerFeature, string> = {
8586
auth: authManagementOrigin(),
8687
messaging: messagingApiOrigin(),
8788
remoteconfig: remoteConfigApiOrigin(),
89+
apphosting: apphostingOrigin(),
8890
};
8991

9092
/**

0 commit comments

Comments
 (0)