-
Notifications
You must be signed in to change notification settings - Fork 1.2k
docs: migration of core package samples from go sdk #2330
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
base: migrate-go-sdk
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @AnmolShukla2002, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the documentation for the MCP Toolbox Go SDK's core package. It provides developers with a centralized and comprehensive resource for understanding the SDK's capabilities, from basic setup and tool interaction to advanced topics like secure authentication mechanisms and flexible parameter binding. Furthermore, it offers ready-to-use integration samples for leading AI orchestration frameworks, streamlining the development of intelligent applications using the Toolbox. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds extensive documentation and samples for the Go SDK core package. The documentation is comprehensive, but I've found several issues in the code samples, including incomplete examples, incorrect API usage, unhandled errors, and typos. These issues could confuse users or cause their code to fail if they copy the examples. I've left specific comments with suggestions for fixes. Addressing these will greatly improve the quality and usability of the documentation.
|
|
||
|
|
||
| ```go | ||
| import "github.com/googleapis/mcp-toolbox-sdk-go/core" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code example is incomplete as it uses the oauth2 package without importing it. Please add the import for golang.org/x/oauth2 to make the example runnable.
| import "github.com/googleapis/mcp-toolbox-sdk-go/core" | |
| import ( | |
| "github.com/googleapis/mcp-toolbox-sdk-go/core" | |
| "golang.org/x/oauth2" | |
| ) |
| token, err := core.GetGoogleIDToken(ctx, URL) | ||
|
|
||
| client, err := core.NewToolboxClient( | ||
| URL, | ||
| core.WithClientHeaderString("Authorization", token), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code snippet has a couple of issues:
- The
URLvariable is used but not defined. It should be replaced with a placeholder to make it clear to the user. - The
Authorizationheader for a bearer token should be in the format"Bearer <token>". The current example is missing the"Bearer "prefix, which will lead to authentication failures.
| token, err := core.GetGoogleIDToken(ctx, URL) | |
| client, err := core.NewToolboxClient( | |
| URL, | |
| core.WithClientHeaderString("Authorization", token), | |
| token, err := core.GetGoogleIDToken(ctx, "your-cloud-run-url") | |
| client, err := core.NewToolboxClient( | |
| "your-cloud-run-url", | |
| core.WithClientHeaderString("Authorization", "Bearer "+token), |
| tool, err := client.LoadTool("my-tool", ctx) | ||
|
|
||
| AuthTool, err := tool.ToolFrom( | ||
| core.WithAuthTokenSource("my-auth", headerTokenSource), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| log.Fatal("Could not invoke tool", err) | ||
| } | ||
|
|
||
| params.Messages = append(params.Messages, openai.ToolMessage(result.(string), toolCall.ID)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type assertion result.(string) is unsafe and will cause a panic if the result from tool.Invoke is not a string. The Invoke method returns any, so its type is not guaranteed. It's safer to convert the result to a string using fmt.Sprintf to avoid a panic.
| params.Messages = append(params.Messages, openai.ToolMessage(result.(string), toolCall.ID)) | |
| params.Messages = append(params.Messages, openai.ToolMessage(fmt.Sprintf("%v", result), toolCall.ID)) |
| // Make initial chat completion request | ||
| completion, err := openAIClient.Chat.Completions.New(ctx, params) | ||
| if err != nil { | ||
| panic(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example uses panic(err) for error handling, which is generally discouraged in Go applications unless it's a truly unrecoverable state during initialization. It's also inconsistent with other parts of the example that use log.Fatal. Using log.Fatalf would be more idiomatic and consistent for a main function.
| panic(err) | |
| log.Fatalf("Chat completion failed: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have major sections added as separate pages under the SDKs' sections?
|
There seem to be links to the READMEs of individual packages in the top-level doc (screenshot). Can we have them linked to this docsite? |
I guess docs reorganization strategy states that we will "treat each SDK repository as the source of truth for its own API reference". While the docsite serves as the "one-stop-shop" for conceptual guides, the github links serve as the technical reference point until our auto-generated API subdomains are fully live. I am not sure on this, let me know your thoughts? |
Sounds good! Let’s link directly to the github source files until we have the API ref docsite up. However for links like those under “Which package should I use?”, I guess I was assuming the links from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, given we address the bot comments and link checker error as well. Optionally, adding a PR description might help as well.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
yes made these changes! |
Bot's comments are mostly regarding the sample...I am not sure If I should make these changes as it would then defer from the sample in the Sdk repos? |
|
|
||
| Before using the SDKs, you need the MCP Toolbox server running. Follow | ||
| the instructions here: [**Toolbox Getting Started | ||
| Guide**](https://github.com/googleapis/genai-toolbox?tab=readme-ov-file#getting-started) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update links like these to also point to the main docsite now that we have migrated all the SDKs guidance as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once these sub branches are merged I will update all the links
| Closing the `ToolboxClient` also closes the underlying network session shared by all tools loaded from that client. As a result, any tool instances you have loaded will cease to function and will raise an error if you attempt to invoke them after the client is closed. | ||
| {{< /notice >}} | ||
|
|
||
| ## Transport Protocols |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to my comment from some of the previous PRs, can we have all the major sections from this guide broken into multiple pages in the menu?
This might make the docs a bit more intuitive and easier to read and share.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we maintain the single-page structure to make sure a cohesive experience for developers during the setup phase. Breaking down these readmes into separate pages for every minor technical section would create content fragments that lack the necessary "big-picture" context.....requiring a user to read 17 other documents just to understand a single proposal. This approach keeps the navigation sidebar clean and focused on our three core package offerings Core, TBADK, and TBGenkit rather than cluttering the menu with excessive sub-levels that can overwhelm both developers and reviewers. By making this sure we are allowing readers to scan through the document quickly to understand what the package represents and how to use it efficiently.
Co-authored-by: Anubhav Dhawan <[email protected]>
This PR migrates the Go SDK documentation and core technical samples from the [mcp-toolbox-sdk-go] repository to the main genai-toolbox documentation site. This consolidation ensures that conceptual guides, package overviews, and interactive code examples are available in a centralized "one-stop-shop".