-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs: migration of tbgenkit package samples from go sdk #2394
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 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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,148 @@ | ||
| --- | ||
| title: "tbGenkit Package" | ||
| linkTitle: "tbGenkit" | ||
| type: docs | ||
| weight: 1 | ||
| --- | ||
|
|
||
|  | ||
|
|
||
| # MCP Toolbox TBGenkit Package | ||
|
AnmolShukla2002 marked this conversation as resolved.
Outdated
|
||
|
|
||
| [](https://opensource.org/licenses/Apache-2.0) | ||
|
|
||
| This package allows you to seamlessly integrate the functionalities of | ||
| [Toolbox](https://github.com/googleapis/genai-toolbox) allowing you to load and | ||
|
AnmolShukla2002 marked this conversation as resolved.
Outdated
|
||
| 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). | ||
|
|
||
|
|
||
| <!-- TOC ignore:true --> | ||
| <!-- TOC --> | ||
|
|
||
| - [Installation](#installation) | ||
| - [Quickstart](#quickstart) | ||
| - [Convert Toolbox Tool to a Genkit Tool](#convert-toolbox-tool-to-a-genkit-tool) | ||
| - [Contributing](#contributing) | ||
| - [License](#license) | ||
| - [Support](#support) | ||
| - [Samples for Reference](#samples-for-reference) | ||
| <!-- /TOC --> | ||
|
|
||
| ## 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) | ||
|
AnmolShukla2002 marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## Convert Toolbox Tool to a Genkit Tool | ||
|
|
||
| ```go | ||
| "github.com/googleapis/mcp-toolbox-sdk-go/tbgenkit" | ||
|
|
||
| func main() { | ||
| // Assuming the toolbox tool is loaded | ||
|
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) | ||
|
|
||
| } | ||
|
AnmolShukla2002 marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| For end-to-end example on how to use Toolbox with Genkit Go, check out the [/samples/](https://github.com/googleapis/mcp-toolbox-sdk-go/tree/main/tbgenkit/samples) folder | ||
|
AnmolShukla2002 marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Contributing | ||
|
|
||
| Contributions are welcome! Please refer to the [DEVELOPER.md](/DEVELOPER.md) | ||
| file for guidelines on how to set up a development environment and run tests. | ||
|
|
||
| # License | ||
|
|
||
| This project is licensed under the Apache License 2.0. See the | ||
| [LICENSE](https://github.com/googleapis/mcp-toolbox-sdk-go/blob/main/LICENSE) file for details. | ||
|
|
||
| # Support | ||
|
|
||
| If you encounter issues or have questions, check the existing [GitHub Issues](https://github.com/googleapis/genai-toolbox/issues) for the main Toolbox project. | ||
|
|
||
| # Samples for Reference | ||
|
|
||
| <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"), | ||
| ) | ||
|
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 | ||
| } | ||
|
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."), | ||
|
AnmolShukla2002 marked this conversation as resolved.
|
||
| ai.WithTools(toolRefs...), | ||
| ) | ||
| if err != nil { | ||
| log.Fatalf("%v\n", err) | ||
| } | ||
| fmt.Println(resp.Text()) | ||
| } | ||
| ``` | ||
|
|
||
| </details> | ||
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.