GSP1349
Overview
In this lab, you explore how to build and deploy a Model Context Protocol (MCP) server to extend the capabilities of the Antigravity CLI. To this end, you are building godoctor, a Go-based server that provides custom tools for Go development, transforming Antigravity CLI from a general-purpose coding assistant into a specialized Go development expert.
This lab uses a "prompt-driven" approach. You act as a tech lead, providing prompts to your AI assistant (the Antigravity CLI). Your goal is to learn how to translate project requirements into effective prompts and let the AI handle the implementation details.
At the heart of this project is the Model Context Protocol (MCP). MCP is an open-source protocol that standardizes how large language models (LLMs) like Gemini communicate with external tools and services. It acts as a bridge, allowing the AI to access real-world information and perform actions beyond its built-in knowledge. By building an MCP server, you are creating a custom plugin that Antigravity CLI can discover and use, effectively teaching it new skills.
Explore other content in the Gemini Enterprise Agent Ready (GEAR) program.
What you'll learn
In this lab, you learn how to perform the following tasks:
- Install and configure Antigravity CLI.
- Formulate effective prompts to guide an AI assistant in software development.
- Provide context and guidelines to an AI assistant.
- Create and configure an MCP server to augment Antigravity CLI capabilities.
What you'll need
This lab can be run entirely within the Google Cloud Shell, which comes pre-installed with all the necessary dependencies (gcloud CLI, Go, Docker, and Antigravity CLI).
Key technologies
Here you can find more information about the technologies used in this lab:
Tips for success
Working with an AI assistant is a new way of developing software. Here are some tips to make your experience smooth and successful:
-
Don't be afraid to hit ESC. The AI will sometimes propose actions or code that you don't agree with. Use the ESC key to cancel its proposed action and provide a new prompt to guide it in the right direction. You are the pilot.
-
Encourage tool use. If the AI seems lost or is making up information, encourage it to use its available tools. Prompts like "Can you use Google Search to verify that?" or "Use the read_file tool to understand the current code before making changes" can be very effective.
-
Resist manual changes. Try to have the AI perform all the work. This is the core skill you are practicing. However, if you must make a manual change, tell the AI about it afterward. A prompt like "I have manually updated the README.md file. Please read it again to refresh your knowledge" will ensure the AI stays in sync with your project.
-
Have you tried turning it off and on again? In the rare case that the AI is trying to force a given path against your command, it might be due to context degradation (sometimes also called "context rot"). In this case you can use the Antigravity CLI command "/compress" to reduce the context noise or, in extreme cases, you can use the "/clear" command to clean the entire session history.
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
- Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
-
Click Activate Cloud Shell
at the top of the Google Cloud console.
-
Click through the following windows:
- Continue through the Cloud Shell information window.
- Authorize Cloud Shell to use your credentials to make Google Cloud API calls.
When you are connected, you are already authenticated, and the project is set to your Project_ID, . The output contains a line that declares the Project_ID for this session:
Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
- (Optional) You can list the active account name with this command:
gcloud auth list
- Click Authorize.
Output:
ACTIVE: *
ACCOUNT: {{{user_0.username | "ACCOUNT"}}}
To set the active account, run:
$ gcloud config set account `ACCOUNT`
- (Optional) You can list the project ID with this command:
gcloud config list project
Output:
[core]
project = {{{project_0.project_id | "PROJECT_ID"}}}
Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.
Task 1. Get started with the Antigravity CLI
In this section, you get started with the Antigravity CLI, including its configuration for your environment.
What is Antigravity CLI?
The Antigravity CLI (agy) is an AI-powered command-line interface that can help you with a wide range of development tasks. It can understand your project's context, answer questions, generate code, and use external tools to extend its capabilities.
Note: Antigravity CLI comes pre-installed in Cloud Shell. You will launch it later in the lab.
Configure Antigravity CLI
The Antigravity CLI's behavior is controlled by configuration files and environment variables. There are two key files:
-
AGENTS.md (or GEMINI.md): This file provides natural language guidelines and context to the AI. The CLI reads this file to understand your project's coding standards and conventions.
-
.antigravity/settings.json: This file controls the configuration of the CLI including how to connect to external tools. You use this file to configure the CLI to use the MCP server in this lab.
In this section, you first set up the environment and then proceed to create the settings.json file. You create an AGENTS.md file in the next task.
- Run the following command to create and initialize a project directory:
mkdir godoctor
cd godoctor
go mod init godoctor
mkdir -p .antigravity .gemini
Task 2. Set development guidelines
To ensure the AI assistant generates high-quality, idiomatic Go code, it's essential to provide it with clear guidelines. You do this in the AGENTS.md file.
Note: AGENTS.md can have many other uses, like telling the CLI about the project structure, working practices, testing, and more.
In this task, you create an AGENTS.md file that serves as the set of rules for the AI assistant during this project.
- Run the following command to create
AGENTS.md and GEMINI.md in the root of your godoctor directory:
touch AGENTS.md GEMINI.md
-
On the Cloud Shell toolbar, click Open Editor to open the Cloud Shell Editor.
-
In the Cloud Shell Editor, open the AGENTS.md file that you created in step 1, paste the following content into it, and save your changes (also copy it to GEMINI.md):
# Go Development Guidelines
All code contributed to this project must adhere to the following principles.
## 1. Formatting
All Go code **must** be formatted with `gofmt` before being submitted.
## 2. Naming Conventions
- **Packages:** Use short, concise, all-lowercase names.
- **Variables, Functions, and Methods:** Use `camelCase` for unexported identifiers and `PascalCase` for exported identifiers.
- **Interfaces:** Name interfaces for what they do (e.g., `io.Reader`), not with a prefix like `I`.
## 3. Error Handling
- Errors are values. Do not discard them.
- Handle errors explicitly using the `if err != nil` pattern.
- Provide context to errors using `fmt.Errorf("context: %w", err)`.
- **Use `os.Stderr` or `log` standard library for debug prints.** Do NOT use standard output (`fmt.Println`) for logging, as this pollutes the JSON-RPC stream used for `stdio` transport and crashes the connection.
## 4. Simplicity and Clarity
- "Clear is better than clever." Write code that is easy to understand.
- Avoid unnecessary complexity and abstractions.
- Prefer returning concrete types, not interfaces.
## 5. Documentation
- All exported identifiers (`PascalCase`) **must** have a doc comment.
- Comments should explain the *why*, not the *what*.
## 6. Project structure
- cmd/ contains source code for target binaries (e.g. server, client)
- internal/ contains source code for packages not meant to be exported (e.g. internal/tools/hello)
- bin/ contains the compiled binaries
- At the root place README.md, go.mod and go.sum
You can close the file. Your development environment is now fully set up.
Launch and authenticate Antigravity CLI
-
On the Cloud Shell Editor action bar, click View > Terminal (or press `Ctrl+``) to open the integrated terminal.
Note: You may have to lengthen your browser window to see the View menu option.
-
In the Cloud Shell Editor terminal, ensure you are in the godoctor directory (cd ~/godoctor), then run the following command to launch Antigravity CLI:
agy --model "{{{ project_0.startup_script.gemini_flash_model_id | Model ID }}}"
-
To sign in, select the Use a Google Cloud project option.
-
Open the authorization URL in a new tab in your browser. Sign in with your lab credentials (), click Copy to Clipboard to copy the authorization code, paste it into the terminal prompt, and press Enter.
-
Enter your Google Cloud Project ID () and press Enter.
-
Set Google Cloud Location to global.
-
On the setup wizard screens (Choose your color scheme and Terms of Service & Data Use), use the arrow keys to navigate and press Enter to select Next and then Done to accept the default settings.
Note: Verify that Antigravity CLI is running under your Antigravity Business account. The banner should display something similar to: (Antigravity Business). If Antigravity Business is not shown in the startup banner, exit the CLI and relaunch agy.
Note: You may be prompted with Do you trust this folder? since you are running Antigravity CLI in a new folder. Select 1. Trust folder (godoctor) to continue.
The CLI uses a combination of its own reasoning (via a Gemini model like Gemini Flash or Gemini Pro) and tools to perform the tasks. It uses tools whenever it needs to interact with the filesystem or external services, like APIs, databases, etc. Examples of the tools that come out of the box, or "built-in tools", are read_file, write_file, web_fetch and google_search. The MCP server that you build in this lab also becomes a tool available to the CLI.
The first time Antigravity CLI runs a tool, it asks for your permission. You can give it a one-time permission, a blanket approval for the rest of the session, or deny its request. If it is a file editing operation, you also find the option to edit the file using an external editor, just in case you want to make some adjustments.
Besides prompts, you can also use slash commands. If you type / (forward slash), the CLI automatically shows you the autocomplete options. You can continue to type the full command or select one from the options.
Note: If you encounter an API capacity error during the lab, you can switch to a different model using the /model command.
Task 3. Create the initial build of the "godoctor" server
In this task, you create the initial version of the godoctor server. This version should be a minimal, production-ready application that provides a single tool called godoc that provides the ability to look up Go documentation.
The purpose of this is to create a production-ready MCP server that exposes the go doc command, allowing an LLM to query Go documentation.
Note: Coding with LLMs is a non-deterministic experience, so you are not always guaranteed to have the same exact results even if you run two identical prompts with the same environment. It is therefore key to develop the skill of identifying when the LLM is stuck in a loop or has degraded context. Remember that you are in control and you can interrupt it at any time by pressing ESC.
In addition, if the Antigravity CLI seems stuck or has trouble determining the correct actions on its own, refer to the Useful resources section at the end of this task and prompt it with relevant instructions taken from that section, as needed.
Create a "Hello World" MCP server
One of the best ways to ensure the model builds things more consistently is to break down complex tasks into incremental steps. While the model might be able to figure out a complex task on its own, without the right setup it may take a long time to discover the right implementation.
For a more consistent approach, you are going to first instruct it to build a "Hello World" MCP server before implementing the functionality you want (reading Go documentation).
- Copy and take a look at the following recommended prompt:
Your task is to create a Model Context Protocol (MCP) server that exposes a "hello_world" tool. This tool, when called, should return the message "Hello, MCP world!"
For the MCP implementation, you should use the official Go SDK for MCP (github.com/modelcontextprotocol/go-sdk/mcp) and use the stdio transport.
TODO:
- Create the main.go file in the `./cmd/server` directory
- Download the dependency: `go get github.com/modelcontextprotocol/go-sdk/mcp`
- Inspect the documentation of the SDK: `go doc github.com/modelcontextprotocol/go-sdk/mcp`
- Build a `server` command that supports stdio transport only
- Build a `client` command that connects to the server over command transport to test the server
Acceptance Criteria:
- `./bin/client --list-tools` returns the list of server tools including "hello_world"
- `./bin/client --call-tool "hello_world"` returns the output "Hello, MCP world!"
This prompt is composed of three main segments:
- The problem specification, including what you want to build and the constraints (e.g. use the official SDK instead of any SDK)
- Some reference documentation for the model to help it disambiguate the request
- A testing procedure, which works as the acceptance criteria for the task
Having these three components helps the model to achieve the desired results in a more consistent manner.
- Issue Antigravity CLI the recommended prompt that you've copied to explore its response.
Attention: Even when you are being very precise in your instructions, sometimes the model can deviate from what you told it to do, so it's important to verify its work and stay tuned for potential error loops and hallucinations. If the model gets stuck, please refer to the Useful resources section at the end of this task.
- Whenever Antigravity CLI prompts you for permission to perform an action, press ENTER to confirm 1. Yes, allow once.
You should select this option throughout the lab, because it gives you time to read Antigravity CLI's responses and it allows time for you to respond or remediate problems if necessary.
- When Antigravity CLI completes the task, press CTRL+C twice or CTRL+D to exit the CLI.
Verify your progress
- In the Antigravity chat (or terminal), generate the
summary_task1.md file and upload it to the grading bucket:
Please write a summary_task1.md file in my project directory that lists:
- The creation of the Go MCP server and the "hello_world" tool using github.com/modelcontextprotocol/go-sdk/mcp
- The steps taken to build and test the server and client using stdio transport
- The output of testing `./bin/client --call-tool "hello_world"`
Once written, upload this file to the grading storage bucket by running:
gcloud storage cp summary_task1.md gs://{{{project_0.project_id | project_id}}}-grading/
- When Antigravity proposes the file creation and upload commands, click the Proceed / Run button directly in the chat UI (or allow the command execution).
- Once completed, click Check my progress below to verify the objective.
Create the Hello World MCP server
Implement the "read_docs" tool
Once you have a working implementation, you can move on to implement the real "read_docs" tool.
- Relaunch the CLI:
agy --model "{{{ project_0.startup_script.gemini_flash_model_id | Model ID }}}"
- Give Antigravity CLI a prompt to implement the "read_docs" tool as follows:
Add a new tool to our MCP server called "read_docs" that invokes the "go doc" shell command. The tool will take a mandatory "package" argument and an optional "symbol" argument.
TODO:
- Create a package `./internal/tools/docs`
- Register the tool with the MCP server
- Ensure you do not remove the existing "hello_world" tool
- Update the client to support the "read_docs" tool by providing arguments to the tool call
- Ensure you use `exec.Command` to run the `go doc` command
Acceptance Criteria:
- `./bin/client --list-tools` show both hello_world and read_docs
- `./bin/client --call-tool "read_docs" "fmt"` returns the documentation for the `fmt` package
- `./bin/client --call-tool "read_docs" "fmt.Println"` returns the documentation for the `fmt.Println` function
- `./bin/client --call-tool "read_docs" "github.com/modelcontextprotocol/go-sdk/mcp"` returns documentation for the `mcp` package
- As before, when Antigravity CLI prompts you for permission to perform an action, press ENTER to confirm 1. Yes, allow once.
Feel free to experiment with this prompt or try to come up with your own.
Note: This prompt explicitly encourages the model to use the go doc shell command because the code to retrieve documentation using the standard library is non-trivial and it might take a while for the model to figure it out on its own. Using the compiler built-in go doc tool saves a lot of time.
If the model outputs [API Error: Model stream ended with an invalid chunk or missing finish reason.] you can safely disregard this error, which sometimes occurs due to a temporary Gemini API Server issue that causes the output to be prematurely ended or truncated. The model's actions are unaffected by this but you can prompt the model to repeat its last response if this happens.
- When Antigravity CLI completes the task, press CTRL+C twice or CTRL+D to exit the CLI.
Verify your progress
- In the Antigravity chat (or terminal), generate the
summary_task2.md file and upload it to the grading bucket:
Please write a summary_task2.md file in my project directory that lists:
- The implementation of the "read_docs" tool in `./internal/tools/docs` invoking `go doc`
- The registration of the "read_docs" tool with the MCP server alongside "hello_world"
- The test results from calling the tool via `./bin/client --call-tool "read_docs" "fmt"`
Once written, upload this file to the grading storage bucket by running:
gcloud storage cp summary_task2.md gs://{{{project_0.project_id | project_id}}}-grading/
- When Antigravity proposes the file creation and upload commands, click the Proceed / Run button directly in the chat UI (or allow the command execution).
- Once completed, click Check my progress below to verify the objective.
Create Read Docs Tool
Useful resources
Given that MCP is still a novel concept and that the Go SDK for MCP is a new library, Gemini might take a long time to discover the right implementation on its own. In order to help the model come up with the right solution, you might want to give it the following references:
- You can give the model the following prompt so it discovers the SDK API more consistently:
Use the `go doc` shell command to discover the api for the go-sdk library.
- If the model tries to inspect the source code of the SDK with the
read_file tool, it will fail because Antigravity CLI cannot read files outside its current scope. You can instruct it to use cat and ls commands instead through the run_shell_command tool.
- If the model has trouble debugging the application, instruct it to add more verbose logging and improve the contextual information in error messages.
- If everything else fails, give it a reference implementation: https://github.com/danicat/godoctor.
Task 4. Configure "godoctor" as an MCP Server for Antigravity CLI
- After the AI assistant has generated the code for both the client and the server, you can instruct it to run a few manual tests. Prompt it to do the following:
Retrieve the documentation for the package net/http.
Note: If the model doesn't find the documentation, make sure you instructed it to use the read_docs tool.
- Make sure you also test it with an external dependency (not in the standard library), by giving it the following prompt:
retrieve the documentation for the github.com/modelcontextprotocol/go-sdk/mcp package
- Once you are satisfied with the results, instruct it to write a README.md with instructions on how to use and develop this project as follows:
Now write a detailed README.md file explaining both from a user and a developer perspective how to use and to build this project.
IMPORTANT: Do not modify or delete any other files in the project. Only create the README.md file.
Now you are going to configure the server so that Antigravity CLI can use it during the next phase of development.
- Prompt the CLI to update AGENTS.md (or GEMINI.md) to use
read_docs as the preferred method to read documentation as follows:
update the AGENTS.md file to include instructions to always use the read_docs tool to retrieve documentation about Go packages or symbols. This should be done whenever seeing an import for the first time in a session or after a new dependency is installed to the project (e.g. via `go get`).
IMPORTANT: Do not modify or delete any other files in the project.
Now you need to restart the Antigravity CLI to configure it.
- First, you tell it to save the chat session so you can resume after a restart from where you stopped:
/chat save workshop001
- Exit the CLI by pressing CTRL+D or CTRL+C twice.
Next, you compile the server binary.
- Run the following command to create a
bin directory (if it doesn't already exist) and compile the godoctor server into it:
mkdir -p bin && go build -o ./bin/godoctor ./cmd/server
Note: You might want to use a different folder than the one used for building the server during development because you want this binary to be stable and available to the CLI during the next phase.
Attention: Sometimes the model might get stuck in a loop, repeating the same tasks or commands multiple times without making progress. If you notice this behavior, you should interrupt the model (Ctrl+C or stop button) and clarify your instructions or guide it manually to break the loop.
Now you configure Antigravity CLI for the local tool.
- In Cloud Shell, run the following command to update
.antigravity/settings.json to add the godoctor MCP server configuration:
cat << 'EOF' > .antigravity/settings.json
{
"mcpServers": {
"godoctor": {
"command": "./bin/godoctor"
}
}
}
EOF
cp .antigravity/settings.json .gemini/settings.json
- Return to your terminal session, and run the following command to relaunch Antigravity CLI:
agy --model "{{{ project_0.startup_script.gemini_flash_model_id | Model ID }}}"
- Enter
/mcp to verify that the tool is loaded and you should get the confirmation that the tool is available.
Now it's time to test the integration.
- Ask Antigravity CLI to use your tool with a prompt like the following:
Get the documentation for net/http.
Note: It might happen that the model tries to call the tool via a shell command. If this happens, press ESC and try to redirect Antigravity CLI to use the "read_docs" tool of the "godoctor" MCP server.
If the tool is working correctly you should see the documentation retrieved through the tool call.
Congratulations, you have made an MCP tool!
Verify your progress
- In the Antigravity chat (or terminal), generate the
summary_task3.md file and upload it to the grading bucket:
Please write a summary_task3.md file in my project directory that lists:
- The compilation of the godoctor binary to `./bin/godoctor`
- The configuration of the `godoctor` MCP server in `.antigravity/settings.json`
- The documentation retrieved for `net/http` using the `read_docs` tool
Once written, upload this file to the grading storage bucket by running:
gcloud storage cp summary_task3.md gs://{{{project_0.project_id | project_id}}}-grading/
- When Antigravity proposes the file creation and upload commands, click the Proceed / Run button directly in the chat UI (or allow the command execution).
- Once completed, click Check my progress below to verify the objective.
Get the documentation for net/http
- Exit the CLI by pressing CTRL+C twice or CTRL+D.
Congratulations!
In this lab, you have guided an AI assistant to build and test a custom MCP server for Antigravity CLI. More importantly, you've practiced the essential skill of modern software development: translating requirements into effective prompts. You have also extended Antigravity CLI with a custom tool, making it a more powerful and specialized Go development assistant.
Next steps / Learn more
Manual Last Updated October 26, 2026
Lab Last Tested October 26, 2026
Copyright 2026 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.