Skip to content
Merged
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
121 changes: 121 additions & 0 deletions docs/en/sdks/go-sdk/tbgenkit/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
title: "Genkit Package"
linkTitle: "Genkit"
type: docs
weight: 1
---

![MCP Toolbox Logo](https://raw.githubusercontent.com/googleapis/genai-toolbox/main/logo.png)

# MCP Toolbox For Go Genkit SDK

[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

This package allows you to seamlessly integrate the functionalities of
[MCP Toolbox](https://github.com/googleapis/genai-toolbox) allowing you to load and
use tools defined in the service as standard Genkit Tools within your Genkit Go
applications.

This simplifies integrating external functionalities (like APIs, databases, or
custom logic) managed by the Toolbox into your workflows, especially those
involving Large Language Models (LLMs).

## Installation

```bash
go get github.com/googleapis/mcp-toolbox-sdk-go
```
This SDK is supported on Go version 1.24.4 and higher.

## Quickstart

For more information on how to load a `ToolboxTool`, see [the core package](https://github.com/googleapis/mcp-toolbox-sdk-go/tree/main/core)

## Convert Toolbox Tool to a Genkit Tool

```go
"github.com/googleapis/mcp-toolbox-sdk-go/tbgenkit"

func main() {
// Assuming the toolbox tool is loaded
Comment thread
AnmolShukla2002 marked this conversation as resolved.
// Make sure to add error checks for debugging
ctx := context.Background()
g, err := genkit.Init(ctx)

genkitTool, err := tbgenkit.ToGenkitTool(toolboxTool, g)

}
Comment thread
AnmolShukla2002 marked this conversation as resolved.
```

# Using with Orchestration Frameworks

To see how the MCP Toolbox Go SDK works with orchestration frameworks, check out these end-to-end examples given below.

<details>
<summary>Genkit Go</summary>

```go
//This sample contains a complete example on how to integrate MCP Toolbox Go SDK with Genkit Go using the tbgenkit package.
package main

import (
"context"
"fmt"
"log"

"github.com/googleapis/mcp-toolbox-sdk-go/core"
"github.com/googleapis/mcp-toolbox-sdk-go/tbgenkit"

"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/plugins/googlegenai"
)

func main() {
ctx := context.Background()
toolboxClient, err := core.NewToolboxClient("http://127.0.0.1:5000")
if err != nil {
log.Fatalf("Failed to create Toolbox client: %v", err)
}

// Load the tools using the MCP Toolbox SDK.
tools, err := toolboxClient.LoadToolset("my-toolset", ctx)
if err != nil {
log.Fatalf("Failed to load tools: %v\nMake sure your Toolbox server is running and the tool is configured.", err)
}

// Initialize genkit
g := genkit.Init(ctx,
genkit.WithPlugins(&googlegenai.GoogleAI{}),
genkit.WithDefaultModel("googleai/gemini-1.5-flash"),
)
Comment thread
AnmolShukla2002 marked this conversation as resolved.

// Convert your tool to a Genkit tool.
genkitTools := make([]ai.Tool, len(tools))
for i, tool := range tools {
newTool, err := tbgenkit.ToGenkitTool(tool, g)
if err != nil {
log.Fatalf("Failed to convert tool: %v\n", err)
}
genkitTools[i] = newTool
}

toolRefs := make([]ai.ToolRef, len(genkitTools))

for i, tool := range genkitTools {
toolRefs[i] = tool
}
Comment thread
AnmolShukla2002 marked this conversation as resolved.

// Generate llm response using prompts and tools.
resp, err := genkit.Generate(ctx, g,
ai.WithPrompt("Find hotels in Basel with Basel in it's name."),
Comment thread
AnmolShukla2002 marked this conversation as resolved.
ai.WithTools(toolRefs...),
)
if err != nil {
log.Fatalf("%v\n", err)
}
fmt.Println(resp.Text())
}
```

</details>
Loading