
Getting the most out of the new Code Assist agent mode and Gemini CLI and integrate them with your Gitlab environment.

11 hours ago
On June 25th Google released a preview of Gemini Code Assist agent mode for VS Code powered by Gemini CLI.
Gemini code Assist agent mode enables an agentic flow in Gemini Code Assist chat in VS Code. I wrote about moving your first steps with agent mode in a previous medium article.
In this article I want to add to the tasks shown in the above mentioned article more things you can do with Gemini Code Assist agent mode, its underlying power unit: Gemini CLI and integration with Gitlab through an MCP Server.
I will use the same example application: gemini-bank. This is an example of a fictitious online bank application written in Python and using Flask and SQLAlchemy. The example app allows users to register, login, create bank accounts, make transactions (deposits or transfers) and list transactions for each account.
This time the repo is hosted on Gitlab rather than on Github.
Specifically I will run through:
- Generate a readme file (already covered in the previous article).
- Get issues from Gitlab through an MCP server
- Add a new feature from the project issue and prompt (partially covered in the previous article)
- Implement coding guidelines through context files
- Generate and run unit tests (already covered in the previous article).
- Get your agent reviewing merge requests in Gitlab with Gemini CLI.
As you see I already covered some of these tasks in my previous article, if you have already run these tasks in some cases you can skip them as described in the following sections.
- Install the Gitlab MCP Server from https://gitlab.com/fforster/gitlab-mcp following the instructions
- Add the MCP server configuration in your ~/.gemini/settings.json (where ~ is your home directory) as follows (adjust the command based on your machine’s path):
"mcpServers": {
"gitlab": {
"command": "/opt/homebrew/bin/gitlab-mcp"
}
}
git clone https://gitlab.com//gemini-bank.git
- Open VS Code, and open the gemini-bank folder
- Open the Gemini Code Assist panel and click the Agent toggle to enter agent mode as shown below:
- Check that the MCP server works with the /mcp command in the chat
I already described this task in my previous article, however, if you want to follow along and don’t already have a readme file from a previous run, with the steps below I suggest running this to provide further context to Gemini.
- First of all let’s create a new branch to work on all the things we want to add to our app:
git checkout -b new-feature
- The repo doesn’t contain a readme file, let’s ask Gemini to generate one, type a prompt like this in the chat panel (Use “@” to select the gemini-bank folder):
@gemini-bank Generate a README.md file for this application that explains the application functionalities, structure and how an user can run and use it
- The Gemini Code Assist agent will start to analyze the repository files in order to create the readme file. The agent uses embedded tools to read and write files and execute commands. For tool requests that modify the file system, or perform mutating operations on any resources, Gemini will ask you for permission to allow the operation before running it, you can choose to allow the operation only for one time or any time is needed in the current chat as in the pwd example below:
- When Gemini completes the operation it will prompt you to review, accept or reject changes with a prompt similar to the one in the picture below.
- Click View Changes to review the README file content, it should provide info on the application, if you are happy with the content, save and close the diff file and click Accept. Open the README.md file in the root of your repo.
I described how to implement a similar feature in my previous article. This time, you will implement it from an existing Gitlab issue rather than describing the feature in the prompt.
- Follow the steps described in the readme to run the application locally. The steps will typically involve the creation of a virtual environment, installation of dependencies and running the app using the command listed below in a terminal:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python app.py
- The readme file should also describe a usage flow to register a new user, login, create a new account and make transactions. Try to do that to see how the app works:
– Click on Register in the upper right corner and register a new user
– Click Login in the upper right corner and log in using the new user credentials
– Click Create Account to create a new account for the user
– Click New Transaction and perform a transaction of type “Transfer” - As you can see, there is a single button leading to a single form for transactions, which can be either ‘Deposit’ or ‘Transfer.’ The ‘Deposit’ option allows you to virtually deposit money into your account, while ‘Transfer’ lets you transfer money out of your account (without specifying the destination).
- The example application Gitlab repository contains an issue to improve this behavior and split the transaction function into 2 different ones:
- Let’s pull this issue in our context using the Gitlab MCP server (change
to your Gitlab account):
list the issues in /gemini-bank project
- Gemini will ask for permission to run Gitlab MCP tools, and then show the issue:
- Now let’s ask Gemini to implement the changes described in the issue:
change the code in @gemini-bank to implement what is requested in the
"Split transactions in 2 different functions" issue
- Gemini will then start to implement changes, and ask you to View/Accept/Reject as done before for the readme file:
- Click View Changes, review the changes, if everything seems okay, save and close the diff file , and then Accept them. You can decide if you want to review all the changes before accepting or “blindly accept” some of them.
- Gemini will do the same for all the files requiring a change and will ask your permission if it needs to run commands that change or delete files.
- Gemini will inform you when all the changes are complete, check that now you can choose from the 2 transaction types (restart the application if has been stopped):
- To see the payment form destination dropdown populated you need to register at least a 2nd user and create an account for her:
- The above pictures are examples from an execution, your results may vary. If you get any issue, error, the result is not satisfactory or you simply want to further improve it, just submit a prompt to Gemini asking for that. One thing you can do, for example, is customizing the transaction description with the following prompt:
Can you change the code so when a payment is made to a destination account,
the transaction recorded in the destination account has a description like
"payment from "sender account owner" with description: "original description
written by the sender account owner"
- You will get a flow similar to the previous ones with requests to review/accept changes and ask for permissions to execute commands if needed. Follow the same process for any further improvement or change you want to make.
Now you will experiment how context files can be used to set rules and guidelines on how Gemini agent mode should behave. We will use a context file to refactor how the application interacts with the Database, moving from the legacy Flask-SQLAlchemy to the modern SQLAlchemy 2.0 style.
Read the documentation for more info on context files.
- Copy the file named context from the assets folder to the root of your local copy of the repository and rename it to GEMINI.md
cp assets/context GEMINI.md
- Open the GEMINI.md file and review the content: this is a coding style guide for DB interactions.
- After you have copied the file, Gemini is ready to use it in his memory, type the following prompt:
Change the code so that SQLAlchemy model definition, database queries
and operations are compliant with my coding style guide
- Gemini will start to plan and execute changes as done before, review changes before applying if you want:
- After Gemini finishes to apply his changes, check that everything (login, transactions…) works as before the changes.
I already described this task in my previous article, you can completely skip it if you have already seen this.
- Now that you have your app documented and with the features and code you want, let’s implement (and run) some unit tests, type the following prompt:
Generate unit tests for all the application functions and run them
to verify that everything works as expected.
Keep test code so i can run tests myself.
- Gemini will display the plan and propose changes as done before.
- After it creates all the needed files, it will ask permission to run tests and execute them
- If it will get any error, Gemini will try to find the cause and implement the needed changes autonomously to get to successful tests, as in the example shown below, this is an interactive process that will end once Gemini will be able to run the tests successfully:
- Once Gemini will get the tests to run successfully it will complete the task and instruct you on how to run the tests yourself as in the picture below:
- Try to run the test yourself (you may need to install pytest or any other tool Gemini needs for the tests)
After all the changes we have made thanks to Gemini, we can open a Merge Request to merge them.
After you open a Merge Request, you will learn how to use Gemini CLI to perform a code review of the changes and post the output to the MR thread in Gitlab. This can be important because Gemini CLI can also be run in a non-interactive mode, so this example could lead to further developments to integrate Gemini CLI in a script or pipeline to automate AI based code reviews.
- Commit your changes to the new branch
git add .
git commit -m "NewFeature-Refactoring-Tests"
git push origin new-feature
- Follow the link, or go to Gitlab -> your account -> gemini-bank to open a merge request
- From a terminal, launch the Gemini CLI
- Check that the Gitlab MCP server works with the /mcp command
- Submit the following prompt to the CLI (replace
with your Gitlab account)
get opened merge requests in /gemini-bank
- After asking for the permission to run Gitlab MCP tools, the Gemini CLI should return the info on the merge request you have created, continue with the following prompt:
do a code review of the changes in this merge request,
write the review in the merge request comment thread
- When Gemini finishes (depending on your previous response it can ask permission again to write in the Gitlab comments thread) you should get the code review in the MR discussion on Gitlab, as shown below:
As said, this can be a first step to automate AI based code reviews with Gemini CLI
You saw how to use Gemini Code Assist agent mode and Gemini CLI mode to generate documentation, add new features, generate and run unit tests, provide coding guidelines and integrate with Gitlab through an MCP server.
There are still a lot of things that you can do with Code Assist and Gemini CLI, check the documentation to find out more !
Source Credit: https://medium.com/google-cloud/improve-your-coding-flow-with-gemini-code-assist-gemini-cli-and-gitlab-debef0985d08?source=rss—-e52cf94d98af—4