Skip to content

Commit 31ff56f

Browse files
committed
Merge branch 'main' into jh-telemetry
2 parents 868e40e + 56b9e85 commit 31ff56f

File tree

80 files changed

+2551
-730
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2551
-730
lines changed

bin/install_cli

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,37 @@
1111
: Introduction
1212
: ==========================================
1313

14-
# This script allows you to install the latest version of the
15-
# "genkit" command by running:
14+
# This script allows you to install the latest version of the "genkit" command by running:
1615
#
1716
: curl -sL cli.genkit.dev | bash
1817
#
19-
# If you do not want to use this script, you can manually
20-
# download the latest "genkit" binary.
18+
# If you do not want to use this script, you can manually download the latest "genkit" binary.
19+
#
20+
# Linux:
2121
#
2222
: curl -Lo ./genkit_bin https://storage.googleapis.com/genkit-assets-cli/prod/linux-x64/latest
2323
#
24+
# macOS:
25+
#
26+
: curl -Lo ./genkit_bin https://storage.googleapis.com/genkit-assets-cli/prod/darwin-arm64/latest
27+
#
28+
# Windows:
29+
#
30+
: curl -Lo ./genkit_bin.exe https://storage.googleapis.com/genkit-assets-cli/prod/win32-x64/latest.exe
31+
#
2432
# Alternatively, you can download a specific version.
2533
#
26-
: curl -Lo ./genkit_bin https://storage.googleapis.com/genkit-assets-cli/prod/linux-x64/v1.15.5/genkit
34+
: curl -Lo ./genkit_bin https://storage.googleapis.com/genkit-assets-cli/prod/darwin-arm64/v1.15.5/genkit
2735
#
2836
# For Windows append ".exe" to the URL.
2937
#
30-
: curl -Lo ./genkit_bin https://storage.googleapis.com/genkit-assets-cli/prod/win32-x64/v1.15.5/genkit.exe
38+
: curl -Lo ./genkit_bin.exe https://storage.googleapis.com/genkit-assets-cli/prod/win32-x64/v1.15.5/genkit.exe
3139
#
32-
# Note: On Mac, replace "linux" with "darwin" in the URL.
3340
# Supported architectures: darwin-x64, darwin-arm64, linux-x64, linux-arm64, win32-x64
3441
#
3542
# For full details about installation options for the Genkit CLI
3643
# please see our documentation.
37-
# https://genkit.dev
44+
# https://genkit.dev/docs/devtools
3845
#
3946
# Please report bugs / issues with this script on GitHub.
4047
# https://github.com/firebase/genkit

genkit-tools/cli/context/GENKIT.go.md

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,6 @@ This document provides rules and examples for building with the Genkit API in Go
1414

1515
NOTE: For the sake of brevity, the snippets below use the Google AI plugin, but you should follow the user's preference as mentioned above.
1616

17-
## Core Setup
18-
19-
1. **Initialize Project**
20-
21-
```bash
22-
mkdir my-genkit-app && cd my-genkit-app
23-
go mod init my-genkit-app
24-
```
25-
26-
2. **Install Dependencies**
27-
28-
```bash
29-
go get github.com/firebase/genkit/go/genkit
30-
go get github.com/firebase/genkit/go/plugins/googlegenai
31-
go get github.com/firebase/genkit/go/ai
32-
go get google.golang.org/genai
33-
```
34-
35-
3. **Install Genkit CLI**
36-
37-
```bash
38-
curl -sL cli.genkit.dev | bash
39-
```
40-
41-
4. **Configure Genkit**
42-
43-
All code should be in a single `main.go` file or properly structured Go package.
44-
45-
```go
46-
package main
47-
48-
import (
49-
"context"
50-
"github.com/firebase/genkit/go/genkit"
51-
"github.com/firebase/genkit/go/plugins/googlegenai"
52-
)
53-
54-
func main() {
55-
ctx := context.Background()
56-
g := genkit.Init(ctx, genkit.WithPlugins(&googlegenai.GoogleAI{}))
57-
// Your flows and logic here
58-
<-ctx.Done()
59-
}
60-
```
61-
6217
## Best Practices
6318

6419
1. **Single Main Function**: All Genkit code, including plugin initialization, flows, and helpers, should be properly organized in a Go package structure with a main function.
@@ -216,23 +171,24 @@ func main() {
216171

217172
## Running and Inspecting Flows
218173

219-
1. **Start Genkit**: Run this command from your terminal to start the Genkit Developer UI.
174+
**Start Genkit**: Genkit can be started locally by using the `genkit start` command, along with the process startup command:
220175

221-
```bash
222-
genkit start -- <command to run your code>
223-
```
176+
```bash
177+
genkit start -- <command to run your code>
178+
```
224179

225-
For Go applications:
180+
For e.g.:
226181

227-
```bash
228-
# Running a Go application directly
229-
genkit start -- go run main.go
182+
```bash
183+
genkit start -- go run main.go
184+
```
230185

231-
# Running a compiled binary
232-
genkit start -- ./my-genkit-app
233-
```
186+
You can can automate starting genkit using the following steps:
234187

235-
The command should output a URL for the Genkit Dev UI. Direct the user to visit this URL to run and inspect their Genkit app.
188+
1. Identify the command to start the user's project's (e.g., `go run main.go`)
189+
2. Use the `start_runtime` tool to start the runtime process. This is required for Genkit to discover flows.
190+
- Example: If the project uses `go run main.go`, call `start_runtime` with `{ command: "go", args: ["run", "main.go"] }`.
191+
3. After starting the runtime, instruct the user to run `genkit start` in their terminal to launch the Developer UI.
236192

237193
## Suggested Models
238194

genkit-tools/cli/context/GENKIT.js.md

Lines changed: 13 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,6 @@ This document provides rules and examples for building with the Genkit API in No
1414

1515
NOTE: For the sake of brevity, the snippets below use the Google AI plugin, but you should follow the user's preference as mentioned above.
1616

17-
## Core Setup
18-
19-
1. **Initialize Project**
20-
21-
```bash
22-
mkdir my-genkit-app && cd my-genkit-app
23-
npm init -y
24-
npm install -D typescript tsx \@types/node
25-
```
26-
27-
2. **Install Dependencies**
28-
29-
```bash
30-
npm install genkit \@genkit-ai/google-genai data-urls node-fetch
31-
```
32-
33-
3. **Install Genkit CLI**
34-
35-
```bash
36-
npm install -g genkit-cli
37-
```
38-
39-
4. **Configure Genkit**
40-
41-
All code should be in a single `src/index.ts` file.
42-
43-
```ts
44-
// src/index.ts
45-
import { genkit, z } from 'genkit';
46-
import { googleAI } from '@genkit-ai/google-genai';
47-
48-
export const ai = genkit({
49-
plugins: [googleAI()],
50-
});
51-
```
52-
5317
## Best Practices
5418

5519
1. **Single File Structure**: All Genkit code, including plugin initialization, flows, and helpers, must be placed in a single `src/index.ts` file. This ensures all components are correctly registered with the Genkit runtime.
@@ -289,29 +253,24 @@ export const videoGenerationFlow = ai.defineFlow(
289253

290254
## Running and Inspecting Flows
291255

292-
1. **Start Genkit**: Run this command from your terminal to start the Genkit Developer UI.
256+
**Start Genkit**: Genkit can be started locally by using the `genkit start` command, along with the process startup command:
293257

294-
```bash
295-
genkit start -- <command to run your code>
296-
```
297-
298-
The <command to run your code> will vary based on the project’s setup and
299-
the file you want to execute. For e.g.:
258+
```bash
259+
genkit start -- <command to run your code>
260+
```
300261

301-
```bash
302-
# Running a typical development server
303-
genkit start -- npm run dev
262+
For e.g.:
304263

305-
# Running a TypeScript file directly
306-
genkit start -- npx tsx --watch src/index.ts
264+
```bash
265+
genkit start -- npm run dev
266+
```
307267

308-
# Running a JavaScript file directly
309-
genkit start -- node --watch src/index.js
310-
```
268+
You can can automate starting genkit using the following steps:
311269

312-
Analyze the users project and build tools to use the right command for the
313-
project. The command should output a URL for the Genkit Dev UI. Direct the
314-
user to visit this URL to run and inspect their Genkit app.
270+
1. Identify the command to start the user's project's (e.g., `npm run dev`)
271+
2. Use the `start_runtime` tool to start the runtime process. This is required for Genkit to discover flows.
272+
- Example: If the project uses `npm run dev`, call `start_runtime` with `{ command: "npm", args: ["run", "dev"] }`.
273+
3. After starting the runtime, instruct the user to run `genkit start` in their terminal to launch the Developer UI.
315274

316275
## Suggested Models
317276

genkit-tools/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "genkit-cli",
3-
"version": "1.24.0",
3+
"version": "1.25.0",
44
"description": "CLI for interacting with the Google Genkit AI framework",
55
"license": "Apache-2.0",
66
"keywords": [

genkit-tools/cli/src/commands/mcp.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import { findProjectRoot, forceStderr } from '@genkit-ai/tools-common/utils';
1818
import { Command } from 'commander';
1919
import { startMcpServer } from '../mcp/server';
20-
import { startManager } from '../utils/manager-utils';
2120

2221
interface McpOptions {
2322
projectRoot?: string;
@@ -29,9 +28,5 @@ export const mcp = new Command('mcp')
2928
.description('run MCP stdio server (EXPERIMENTAL, subject to change)')
3029
.action(async (options: McpOptions) => {
3130
forceStderr();
32-
const manager = await startManager(
33-
options.projectRoot ?? (await findProjectRoot()),
34-
true
35-
);
36-
await startMcpServer(manager);
31+
await startMcpServer(options.projectRoot ?? (await findProjectRoot()));
3732
});

genkit-tools/cli/src/mcp/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## 🚀 Genkit MCP Server: Model Context Protocol Integration
2+
3+
The **Genkit MCP (Model Context Protocol) Server** bridges your Genkit projects with external AI tools and development environments. It exposes Genkit flows and functionalities via the Model Context Protocol, allowing **LLM agents** and **IDEs** to discover, interact with, and monitor your application.
4+
5+
> **Note:** The Genkit MCP server is an experimental feature and may change.
6+
7+
---
8+
9+
### What It Does
10+
11+
The MCP Server enables external tools to:
12+
13+
* **Discover Flows:** List all available Genkit flows, including their input schemas.
14+
* **Run Flows:** Execute Genkit flows by providing inputs and receiving outputs.
15+
* **Access Traces:** Retrieve and analyze detailed execution traces for performance insights.
16+
* **Look up Documentation:** Access Genkit documentation directly.
17+
18+
---
19+
20+
### Available MCP Tools
21+
22+
The following tools allow MCP-aware environments to interact with the Genkit server:
23+
24+
| Tool Name | Description |
25+
| :--- | :--- |
26+
| **`get_usage_guide`** | Fetches the Genkit AI framework usage guide (specifiable by language). Intended for AI assistants. |
27+
| **`lookup_genkit_docs`** | Retrieves Genkit documentation (specifiable by language and files). |
28+
| **`list_flows`** | Discovers and lists all defined Genkit flows with their input schemas. |
29+
| **`run_flow`** | Executes a specified Genkit flow, requiring `flowName` and a JSON `input` conforming to the flow's schema. |
30+
| **`get_trace`** | Retrieves the detailed execution trace for a flow using a `traceId`. |

genkit-tools/cli/src/mcp/flows.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { RuntimeManager } from '@genkit-ai/tools-common/manager';
1817
import { record } from '@genkit-ai/tools-common/utils';
1918
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
2019
import z from 'zod';
2120
import { McpRunToolEvent } from './analytics.js';
21+
import { McpRuntimeManager } from './util.js';
2222

23-
export function defineFlowTools(server: McpServer, manager: RuntimeManager) {
23+
export function defineFlowTools(server: McpServer, manager: McpRuntimeManager) {
2424
server.registerTool(
2525
'list_flows',
2626
{
@@ -30,8 +30,8 @@ export function defineFlowTools(server: McpServer, manager: RuntimeManager) {
3030
},
3131
async () => {
3232
await record(new McpRunToolEvent('list_flows'));
33-
34-
const actions = await manager.listActions();
33+
const runtimeManager = await manager.getManager();
34+
const actions = await runtimeManager.listActions();
3535

3636
let flows = '';
3737
for (const key of Object.keys(actions)) {
@@ -70,7 +70,8 @@ export function defineFlowTools(server: McpServer, manager: RuntimeManager) {
7070
await record(new McpRunToolEvent('run_flow'));
7171

7272
try {
73-
const response = await manager.runAction({
73+
const runtimeManager = await manager.getManager();
74+
const response = await runtimeManager.runAction({
7475
key: `/flow/${flowName}`,
7576
input: input !== undefined ? JSON.parse(input) : undefined,
7677
});

0 commit comments

Comments
 (0)