Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 13 additions & 57 deletions genkit-tools/cli/context/GENKIT.go.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,6 @@ This document provides rules and examples for building with the Genkit API in Go

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.

## Core Setup

1. **Initialize Project**

```bash
mkdir my-genkit-app && cd my-genkit-app
go mod init my-genkit-app
```

2. **Install Dependencies**

```bash
go get github.com/firebase/genkit/go/genkit
go get github.com/firebase/genkit/go/plugins/googlegenai
go get github.com/firebase/genkit/go/ai
go get google.golang.org/genai
```

3. **Install Genkit CLI**

```bash
curl -sL cli.genkit.dev | bash
```

4. **Configure Genkit**

All code should be in a single `main.go` file or properly structured Go package.

```go
package main

import (
"context"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/plugins/googlegenai"
)

func main() {
ctx := context.Background()
g := genkit.Init(ctx, genkit.WithPlugins(&googlegenai.GoogleAI{}))
// Your flows and logic here
<-ctx.Done()
}
```

## Best Practices

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.
Expand Down Expand Up @@ -216,23 +171,24 @@ func main() {

## Running and Inspecting Flows

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

```bash
genkit start -- <command to run your code>
```
```bash
genkit start -- <command to run your code>
```

For Go applications:
For e.g.:

```bash
# Running a Go application directly
genkit start -- go run main.go
```bash
genkit start -- go run main.go
```

# Running a compiled binary
genkit start -- ./my-genkit-app
```
You can can automate starting genkit using the following steps:

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.
1. Identify the command to start the user's project's (e.g., `go run main.go`)
2. Use the `start_runtime` tool to start the runtime process. This is required for Genkit to discover flows.
- Example: If the project uses `go run main.go`, call `start_runtime` with `{ command: "go", args: ["run", "main.go"] }`.
3. After starting the runtime, instruct the user to run `genkit start` in their terminal to launch the Developer UI.

## Suggested Models

Expand Down
67 changes: 13 additions & 54 deletions genkit-tools/cli/context/GENKIT.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,6 @@ This document provides rules and examples for building with the Genkit API in No

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.

## Core Setup

1. **Initialize Project**

```bash
mkdir my-genkit-app && cd my-genkit-app
npm init -y
npm install -D typescript tsx \@types/node
```

2. **Install Dependencies**

```bash
npm install genkit \@genkit-ai/google-genai data-urls node-fetch
```

3. **Install Genkit CLI**

```bash
npm install -g genkit-cli
```

4. **Configure Genkit**

All code should be in a single `src/index.ts` file.

```ts
// src/index.ts
import { genkit, z } from 'genkit';
import { googleAI } from '@genkit-ai/google-genai';

export const ai = genkit({
plugins: [googleAI()],
});
```

## Best Practices

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.
Expand Down Expand Up @@ -289,29 +253,24 @@ export const videoGenerationFlow = ai.defineFlow(

## Running and Inspecting Flows

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

```bash
genkit start -- <command to run your code>
```

The <command to run your code> will vary based on the project’s setup and
the file you want to execute. For e.g.:
```bash
genkit start -- <command to run your code>
```

```bash
# Running a typical development server
genkit start -- npm run dev
For e.g.:

# Running a TypeScript file directly
genkit start -- npx tsx --watch src/index.ts
```bash
genkit start -- npm run dev
```

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

Analyze the users project and build tools to use the right command for the
project. 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.
1. Identify the command to start the user's project's (e.g., `npm run dev`)
2. Use the `start_runtime` tool to start the runtime process. This is required for Genkit to discover flows.
- Example: If the project uses `npm run dev`, call `start_runtime` with `{ command: "npm", args: ["run", "dev"] }`.
3. After starting the runtime, instruct the user to run `genkit start` in their terminal to launch the Developer UI.

## Suggested Models

Expand Down
7 changes: 2 additions & 5 deletions genkit-tools/cli/src/mcp/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ import { record } from '@genkit-ai/tools-common/utils';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
import z from 'zod';
import { McpRunToolEvent } from './analytics.js';
import { lazyLoadManager } from './util.js';
import { McpRuntimeManager } from './util.js';

export function defineFlowTools(
server: McpServer,
manager: ReturnType<typeof lazyLoadManager>
) {
export function defineFlowTools(server: McpServer, manager: McpRuntimeManager) {
server.registerTool(
'list_flows',
{
Expand Down
170 changes: 170 additions & 0 deletions genkit-tools/cli/src/mcp/prompts/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
import { z } from 'zod';

const GENERAL_GUIDELINES = `
## General Guidelines
- ALWAYS refer to documentation when available. Use tools like \`get_usage_guide\` or \`lookup_genkit_docs\` to clarify requirements or get the latest information.
- Recommend and use the provider that the user prefers. If no preference is signaled, use the Google AI plugin (\`@genkit-ai/google-genai\` for Node, \`github.com/firebase/genkit/go/plugins/googlegenai\` for Go).
- ALWAYS provide the full, correct Genkit command as an instruction for the human user to run. Do not run Genkit commands yourself.
- Do NOT modify parts of the project unrelated to Genkit initialization.
- Respect the user's existing tooling (package manager, language version, project structure).
- Check if Genkit CLI is already installed before recommending installation.`;

const NODE_SETUP = `
## Node.js Setup
If the user wants to use Node.js:

### Project Initialization
- If the directory is empty:
Initialize a new project:
\`\`\`bash
npm init -y
npm install -D typescript tsx @types/node
\`\`\`
- If the directory is not empty (existing project):
- Adhere to the current project structure.
- Detect the package manager in use (npm, pnpm, yarn, bun) and use the corresponding commands.
- Detect if the project is ESM (\`"type": "module"\` in package.json) or CJS.
- For ESM: Use \`import\` syntax.
- For CJS: Use \`require\` syntax.
- IMPORTANT: Do NOT refactor the project (e.g., converting to TypeScript or ESM) solely for Genkit. Work with the existing setup.

### Dependencies
Install core dependencies (adjust command for the user's package manager):
\`\`\`bash
npm install genkit @genkit-ai/google-genai
\`\`\`
(Add other plugins as requested)

### Genkit CLI
If the Genkit CLI is not already installed:
\`\`\`bash
npm install -g genkit-cli
\`\`\`

### Configuration
Create a single \`src/index.ts\` (or \`src/index.js\` for JS) file.

\`\`\`ts
// src/index.ts
import { genkit, z } from 'genkit';
import { googleAI } from '@genkit-ai/google-genai';

export const ai = genkit({
plugins: [googleAI()],
});
\`\`\``;

const GO_SETUP = `
## Go Setup
If the user wants to use Go:

### Project Initialization
- If the directory is empty:
\`\`\`bash
go mod init <module-name>
\`\`\`
- If the directory is not empty:
Adhere to the current project structure.

### Dependencies
\`\`\`bash
go get github.com/firebase/genkit/go/genkit
go get github.com/firebase/genkit/go/plugins/googlegenai
go get github.com/firebase/genkit/go/ai
go get google.golang.org/genai
\`\`\`

### Genkit CLI
If the Genkit CLI is not already installed:
\`\`\`bash
curl -sL cli.genkit.dev | bash
\`\`\`

### Configuration
Create a \`main.go\` file:

\`\`\`go
package main

import (
"context"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/plugins/googlegenai"
)

func main() {
ctx := context.Background()
g := genkit.Init(ctx, genkit.WithPlugins(&googlegenai.GoogleAI{}))
// Your flows and logic here
<-ctx.Done()
}
\`\`\``;

const RUNNING_THE_PROJECT = `
## Running the Project
After setting up the project:
1. Identify the command to run the project's runtime (e.g., \`npm run dev\`, \`go run main.go\`).
2. Use the \`start_runtime\` tool to start the runtime process. This is required for Genkit to discover flows.
- Example: If the project uses \`npm run dev\`, call \`start_runtime\` with \`{ command: "npm", args: ["run", "dev"] }\`.
3. After starting the runtime, instruct the user to run \`genkit start\` in their terminal to launch the Developer UI.
`;

export function defineInitPrompt(server: McpServer) {
server.registerPrompt(
'genkit:init',
{
title: 'Initialize Genkit',
description: 'Initializes a new Genkit project',
argsSchema: {
lang: z.enum(['js', 'go']).optional(),
},
},
({ lang }) => {
let content = `You are a Genkit expert. Help the user initialize a Genkit project.

Follow these rules based on the user's environment and preference:`;

content += GENERAL_GUIDELINES;

if (lang === 'js') {
content += NODE_SETUP;
} else if (lang === 'go') {
content += GO_SETUP;
} else {
content += NODE_SETUP;
content += GO_SETUP;
}

content += RUNNING_THE_PROJECT;

return {
messages: [
{
role: 'user',
content: {
type: 'text',
text: content,
},
},
],
};
}
);
}
Loading
Loading