-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add MCP tool to list functions #9369
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ae5995c
add list_functions tool for mcp
brittanycho 8224d4a
adds list_function to index.ts
brittanycho 35aa5a8
fix linting errors
brittanycho 75c1831
switch readOnlyHint to true
brittanycho 8a4118b
Merge branch 'master' into feat/mcp-functions-list
brittanycho 5cbe3bb
Merge branch 'master' into feat/mcp-functions-list
brittanycho e0584f2
Update src/mcp/tools/functions/list_functions.ts
brittanycho fa35279
Update src/mcp/tools/functions/list_functions.ts
brittanycho ca7af54
update changelog
brittanycho 5e3e9d2
cleaned up formatting errors with prettier
brittanycho 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Added `functions.list_functions` as a MCP tool (#9369) |
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import type { ServerTool } from "../../tool"; | ||
|
|
||
| import { get_logs } from "./get_logs"; | ||
| import { list_functions } from "./list_functions"; | ||
|
|
||
| export const functionsTools: ServerTool[] = [get_logs]; | ||
| export const functionsTools: ServerTool[] = [get_logs, list_functions]; |
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,58 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| import { tool } from "../../tool"; | ||
| import { mcpError, toContent } from "../../util"; | ||
| import * as backend from "../../../deploy/functions/backend"; | ||
| import { getErrMsg } from "../../../error"; | ||
| import * as args from "../../../deploy/functions/args"; | ||
|
|
||
| export const list_functions = tool( | ||
| "functions", | ||
| { | ||
| name: "list_functions", | ||
| description: "List all deployed functions in your Firebase project.", | ||
| inputSchema: z.object({}), | ||
| annotations: { | ||
| title: "List Deployed Functions", | ||
| readOnlyHint: true, | ||
| openWorldHint: true, | ||
| }, | ||
| _meta: { | ||
| requiresAuth: true, | ||
| requiresProject: true, | ||
| }, | ||
| }, | ||
| async (_, { projectId }) => { | ||
| const context = { | ||
| projectId, | ||
| } as args.Context; | ||
|
|
||
| try { | ||
| // fetches info about all currently deployed functions for the project | ||
| const existing = await backend.existingBackend(context); | ||
| // extracts all the function endpoints and sorts them | ||
| const endpointsList = backend.allEndpoints(existing).sort(backend.compareFunctions); | ||
|
|
||
| // below format differs from Firebase CLI command output to be more suitable format for agents | ||
brittanycho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const formattedList = endpointsList.map((endpoint) => ({ | ||
| function: endpoint.id, | ||
| version: endpoint.platform === "gcfv2" ? "v2" : "v1", | ||
| trigger: backend.endpointTriggerType(endpoint), | ||
| location: endpoint.region, | ||
| memory: endpoint.availableMemoryMb || "---", | ||
brittanycho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| runtime: endpoint.runtime, | ||
| })); | ||
|
|
||
| if (!formattedList.length) { | ||
| return toContent([], { | ||
| contentPrefix: "No functions found in this project.\n\n", | ||
| }); | ||
| } | ||
|
|
||
| return toContent(formattedList); | ||
| } catch (err) { | ||
| const errMsg = getErrMsg((err as any)?.original || err, "Failed to list functions."); | ||
|
Check warning on line 54 in src/mcp/tools/functions/list_functions.ts
|
||
| return mcpError(errMsg); | ||
| } | ||
| }, | ||
| ); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.