-
Notifications
You must be signed in to change notification settings - Fork 1k
initial apphosting mcp tool #8605
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
Open
bkendall
wants to merge
6
commits into
master
Choose a base branch
from
bk-mcp-apphosting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cc064c0
initial apphosting mcp tool
bkendall 214d190
Merge branch 'master' into bk-mcp-apphosting
bkendall a51bd5c
Merge branch 'master' of github.com:firebase/firebase-tools into bk-m…
bkendall a4088ba
add fetchServiceLogs function
bkendall 98d42f3
add run tool to fetch logs
bkendall 9cb48c1
add a little more description for location
bkendall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,7 +266,7 @@ | |
done: boolean; | ||
// oneof result | ||
error?: Status; | ||
response?: any; | ||
// end oneof result | ||
} | ||
|
||
|
@@ -333,6 +333,19 @@ | |
return res.body; | ||
} | ||
|
||
/** | ||
* Gets traffic details. | ||
*/ | ||
export async function getTraffic( | ||
projectId: string, | ||
location: string, | ||
backendId: string, | ||
): Promise<Traffic> { | ||
const name = `projects/${projectId}/locations/${location}/backends/${backendId}/traffic`; | ||
const res = await client.get<Traffic>(name); | ||
return res.body; | ||
} | ||
|
||
/** | ||
* List all backends present in a project and location. | ||
*/ | ||
|
@@ -548,14 +561,14 @@ | |
/** | ||
* Ensure that the App Hosting API is enabled on the project. | ||
*/ | ||
export async function ensureApiEnabled(options: any): Promise<void> { | ||
const projectId = needProjectId(options); | ||
return await ensure(projectId, apphostingOrigin(), "app hosting", true); | ||
} | ||
|
||
/** | ||
* Generates the next build ID to fit with the naming scheme of the backend API. | ||
* @param counter Overrides the counter to use, avoiding an API call. | ||
Check warning on line 571 in src/gcp/apphosting.ts
|
||
*/ | ||
export async function getNextRolloutId( | ||
projectId: string, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { ServerTool } from "../../tool"; | ||
import { list_backends } from "./list_backends"; | ||
|
||
export const appHostingTools: ServerTool[] = [list_backends]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,51 @@ | ||||||||
import { z } from "zod"; | ||||||||
import { tool } from "../../tool.js"; | ||||||||
import { toContent } from "../../util.js"; | ||||||||
import { NO_PROJECT_ERROR } from "../../errors.js"; | ||||||||
import { | ||||||||
Backend, | ||||||||
getTraffic, | ||||||||
listBackends, | ||||||||
parseBackendName, | ||||||||
Traffic, | ||||||||
} from "../../../gcp/apphosting.js"; | ||||||||
|
||||||||
export const list_backends = tool( | ||||||||
{ | ||||||||
name: "list_backends", | ||||||||
description: | ||||||||
"Retrieves a list of App Hosting backends in the current project. An empty list means that there are no backends. " + | ||||||||
"The `uri` is the public URL of the backend. " + | ||||||||
"A working backend will have a `managed_resources` array that will contain a `run_service` entry. That `run_service.service` " + | ||||||||
"is the resource name of the Cloud Run service serving the App Hosting backend. The last segment of that name is the service ID.", | ||||||||
inputSchema: z.object({ | ||||||||
location: z | ||||||||
.string() | ||||||||
.optional() | ||||||||
.default("-") | ||||||||
.describe( | ||||||||
"Limit the listed backends to this region. By default, it will list all backends across all regions.", | ||||||||
), | ||||||||
}), | ||||||||
annotations: { | ||||||||
title: "List App Hosting backends.", | ||||||||
readOnlyHint: true, | ||||||||
}, | ||||||||
_meta: { | ||||||||
requiresAuth: true, | ||||||||
requiresProject: true, | ||||||||
}, | ||||||||
}, | ||||||||
async ({ location } = {}, { projectId }) => { | ||||||||
if (!projectId) return NO_PROJECT_ERROR; | ||||||||
if (!location) location = "-"; | ||||||||
const data: (Backend & { traffic: Traffic })[] = []; | ||||||||
const backends = await listBackends(projectId, location); | ||||||||
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. We might want a different message for no backends - ie
Suggested change
Not sure what the LLMs will like more |
||||||||
for (const backend of backends.backends) { | ||||||||
const { location, id } = parseBackendName(backend.name); | ||||||||
const traffic = await getTraffic(projectId, location, id); | ||||||||
data.push({ ...backend, traffic: traffic }); | ||||||||
} | ||||||||
return toContent(data); | ||||||||
}, | ||||||||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { z } from "zod"; | ||
import { tool } from "../../tool.js"; | ||
import { toContent } from "../../util.js"; | ||
import { NO_PROJECT_ERROR } from "../../errors.js"; | ||
import { fetchServiceLogs } from "../../../gcp/run.js"; | ||
|
||
export const fetch_logs = tool( | ||
{ | ||
name: "fetch_logs", | ||
description: | ||
"Fetches recent logs for a Cloud Run service. Includes details such as the message, severity, and timestamp.", | ||
inputSchema: z.object({ | ||
serviceId: z.string().describe("The Cloud Run service ID."), | ||
}), | ||
annotations: { | ||
title: "Fetch recent Cloud Run service logs.", | ||
readOnlyHint: true, | ||
}, | ||
_meta: { | ||
requiresAuth: true, | ||
requiresProject: true, | ||
}, | ||
}, | ||
async ({ serviceId } = {}, { projectId }) => { | ||
if (!projectId) return NO_PROJECT_ERROR; | ||
if (!serviceId) return toContent("A Cloud Run service ID must be provided."); | ||
const data = await fetchServiceLogs(projectId, serviceId); | ||
return toContent(data); | ||
}, | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { ServerTool } from "../../tool"; | ||
import { fetch_logs } from "./fetch_logs"; | ||
|
||
export const runTools: ServerTool[] = [fetch_logs]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is already taken care of by the caller.
firebase-tools/src/mcp/index.ts
Line 189 in 214d190
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.
Sure, but I still have to assert that projectId isn't undefined, otherwise I have to do checks all over the place. Does this hurt that much to bother?
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.
Yeah, it's a bit annoying that
projectId
is nullable even ifrequiresProject
is true above.Maybe we can do a clean up to supply a dummy
projectId: "missing-project"
if there there is no project present.