📱

Get Our Mobile App

Take your business learning on the go!

Download on the App StoreGet it on Google Play

Gemini-CLI 🚀: How to Setup and Add MCPs | Full Walkthrough

Prompt Engineer•21:15

Transcription

Okay guys, we have one more CLI which is Gemini CLI, your open-source AI agent. We're going to see what it is and test it on our local system. We're going to use APIs of Gemini and see what it's like to use Gemini CLI.

We had cloud code as well from Entropic. And this is a closed source solution, but we have codec CLI from OpenAI which is an open- source solution. And you can see that it was released uh just like two to 3 months ago. But you can see the number of stars is 30k. Google Gemini was released just before yesterday just 2 days. And you can go ahead and see that in just uh 2 days we have about 40k stars. So let's go ahead and see what this phrase about Gemini CLI is and let's go ahead and install it on your local system and then try to use it. Try to do different things. for example, trying out MCPS.

And for developers, the command line interface isn't just a tool. And it's absolutely right. I agree. It's home. The terminal's efficiency, ubiquity, and portability makes it the go-to utility for getting work done. And as developers reliance on terminal endures, so does the demand for integrated AI assistance cannot be more than true. That's why we're introducing Gemini CLI, command line interface, an open- source AI agent that brings the power of Gemini directly into your terminal. And it's cool. It provides lightweight access to Gemini, giving you the most direct path from your prompts to our models.

Okay. While it excels at coding, we built Gemini CLI to do so much more. It's versatile local utility you can use for a wide range of tasks from content generation and problem solving to deep research and task management. They've also integrated Google Gemini CLI with Google AI coding assistant Gemini code assist so that all developers on standard free or enterprise code assist plans get promdriven approach nor AI coding which is in both VS code and Gemini CLI.

So talking about the limits, usage limits for individuals, you can see that 1k model requests per day. It's open source and 60 model requests per minute. And this is huge 1k model request per minute. I hope many guys won't use that much. Now this free license give you access to Gemini 2.5 Pro and its massive 1 million token context window. Cool. So 60 requests per minute and,000 requests per day at no charge. It's amazing.

So what you can do it comes with ground prompts with Google search. So you can fetch web pages. It extends Gemini CLI capabilities through the built-in support for the model context protocols. We'll see and try to add a GitHub or MCP. Let's see. Customize prompts and instructions to tailor Gemini for your specific needs and workflows and automate task and integrate your existing workflows by invoking Gemini CLI non-interactive within your scripts. Let's go ahead and test this out.

So as you can see that you can make a short videos using VO and imagine as well because it's using MCPS. We have seen it's open source Apache 2.0 license and you can even contribute and clone this code. It's up to you. So let's get started and see what we can do here. Okay.

So let's look at the installations. First thing that we need to do is to have NodeJS installed on your system. So NodeJS we need uh let's say an LTS take this LTS version. I'm on my Windows. I'm going to go and download this for Windows, the MSFi file. Get it installed. And I should have nodejs installed. Go to a command prompt and type node- version. Then you're going to get the version which is 22.16.0. And node is installed.

Next, what you can do is now you can go ahead and execute this command in your terminal which is npx and it's fetching from the Gemini CLI. Okay. Or you can use install this with npm install-g at the red google/gemini/ or cli and then you can start it with gemini. Take a color scheme and then you authenticate. Okay.

So let's go ahead to a particular folder. So this is my folder. I'm going to go ahead and do cmd. I'm going to go ahead and do cursor space enter. This will open up in cursor. And uh let's do it there. So I'm going to go ahead and uh start up a new one. So I going to kill this terminal. So I have a cmd here and what I'm going to do is take that code. So npm install-g and paste it here. It's trying to install Gemini CLI from Google itself. Now I already have installed. I have been playing with this. So you may not get the exact outputs that you would get when you are running this for the first time. But let's see while this is installing. Okay, this is done.

Next we can start it with Gemini. So we can say Gemini and this will start up Gemini CLI on your local system and it's pretty amazing. Now for the first time when you do it, you're going to get uh to choose a color scheme which you can invoke uh using this uh slash I can say themes/ themes. So this is the thing that you'll get and uh what do you select? I like this GitHub dark mode. So I'm going to select the dark mode. Then you need to authenticate. So for the first time you need to authenticate. You can uh run this off as well. AUT and there you're going to get three options to authenticate. First is login with Google. Next is using Gemini API key from the AI studio. And next is using the Vert.ex AI. If you exhaust the thousand uh request per day using your default login with Google, then you can go ahead and put in your Gemini API key. For now, you can just start with login with Google. So I'm going to go and I'm going to login with Google. So I'm going to say take this email. I'm going to say sign in and this will help me login with Google. Okay. So you are now authorized to access this account. The authentication with Google code assist cloud code with Gemini code assist and the Gemini CLI was successful. So this is done. You can go back to cursor now.

Now next what you can do is you can start doing whatever you like. So look at the docs first and then I'm going to go ahead and test. If you need an API key, this is where you would go. You can create an API key. If you exhaust the th,000 tokens or thousand requests uh per day, you can go ahead and create an API key and use that API key so that it goes under your billing and there will be no limits when you do that. I'm going to go to the docs. So you can open the docs from here itself. So you can say slash and uh let's go through each of the commands here.

So about is it gives you the CLI version which is 017. It gives you the model sandbox oss win32 and authentication method is o. Next, what do you have? We have the bug. You can submit a bug report directly from here. Next, uh we can manage the chat conversation history. Of course, there is none. Now, you can for example choose the editor of your preference. So, it supports z vs code, wind surf, cursor, vim. Next, what do you have? We can see help. So, this is the help. Inside the help you can see that uh you can use add the rate to specify files for context. So if you have a main file here for example if you have a main file here then what you can do is you can add the rate main file. So you can take this main file here give it the reference and then you can start asking questions or doing all sorts of things that you like. So you can run in a shell mode as well by putting an exclamation mark here. You can run uh directly shell commands here. So you can run npm rundev. So I can do this.

Next, these are the different commands. So, help is to get help on Gemini CLI. Docs is to open the full Gemini CLI documentation in your browser. And this is what I was trying to show you. So, if I go back and click on / click on docs, type docs and click enter. This is going to take me to the official documentation. I'm going to close everything here and let's go through the documentation together. Before that, let's see what other commands that you have that might be of interest to you. I've already said that you can change the theme, you can change the off method, you can change uh the editor preference here. Check the stats session stats and this is another one interesting one. So I can say stats and you can see that this is the input tokens, output tokens that we've used and you can see that 100% context is left which means 1 million context token is left.

Next uh we can see we have MCP list of MCP list of MCP. So you can go ahead and test MCP and no MCP has been configured yet. And it gives me the way to integrate MCP. So we're going to try and uh test out one MCP. That's pretty much it. So let's go ahead and check the documentation.

Welcome to Gemini CLI documentation. This documentation provides a comprehensive guide to installing, using, and developing Gemini CLI. Gemini CLI brings the capability of Gemini models to your terminal in an interactive RDPL environment. Gemini CLI consists of a client side application which is packages cla communicates with the local server packages.core. So if I go to this repo and if I clone this repo or download the uh zip files and if I open the zip files I have the zip files already fetched here. If I say uh let's open this and try to understand uh the code. So in the packages uh we have core and then we have the CLI. So that's a front end and the back end. So you can see that this is a client application packages/ CLI which is the front end and then it communicates with the local server packages.core uh which is the back end here. Okay.

So this is the documentation execution and deployment. We have already seen how to run we have used this and we have installed and then we use Gemini to run this. Next we can see that uh this is the architecture review. I want to show you the flow structure of how everything happens here. So a typical interaction with the Gemini CLI follows this flow. User input. The user types a prompt or command into the terminal which is managed by the packages/ CLI and request to core. Packages CLI sends the user request to packages core. So from the front end to the back end sends the request. Then the core package what it does it constructs an appropriate prompt for the Gemini API because we are going to call the Gemini API possibly including conversation history and list of available tools definitions that we have. It sends the prompt to the Gemini API. The Gemini ABI response then the Gemini Abi processes the prompt and returns a response. This response might be a direct answer or a request to one of the available tools. Tool execution if applicable if we have tools installed and if the prompt is such that we need tool calling we need to use the tool then this structure is followed. So when the Gemini API requested tool the core package prepares to execute it. If the requested tool can modify the file system or execute shell commands the user is first given details of the tools and its arguments and the user must approve the execution. read only operation may not require explicit user information confirmation to proceed. Okay. So once confirmed and or if information is not required the core package executes the relevant action within the relevant tool and the result is sent back to the Gemini API by the core package. Okay. And then the Gemini API processes the tool result and generates a final response. How cool is that? Then we send the response to the CLI core package. Sends the final response to the CLI package and it is displayed to the user. And that's pretty amazing. It's as simple as that. This is the normal typical flow.

I'm going to go ahead and show you the list of commands that we have already seen. So this is the command. So /bug/ chat clear compress editor help mcp memory uh restore stats claim about tools and quit. I'm going to show you this quit. Looks pretty beautiful. So when we say quit, this is going to show you that agent powering down. Goodbye. And these are the number of input tokens that we've used. output tokens that we use. Of course, we have not used it till now. Uh so I can start it up again using Gemini and this will start up the CLI again.

So you can go through this documentation tools overview, file system tools, file multifile read tool, shell tool, web fetch tool, web search tool, memory tool. There are so many different tools that we have integrated. I'm going to show you the MCP integration. This is going to be an interesting one. Now let's show you the extension here which is of trying to add an MCP uh in your system. But before that let's go ahead and use this. So let's say uh I want to u make a new function. So let's say u write me a complete function showing to calculate the cube root of a number. So you can see that it's reading the files successfully read and concatenated contents from one file and it's trying to write. So it's asking me to apply this change. I can do it yes this only allow this one time or you can always say always allow modify with external editor and no. I'm going to say allow once just to show you the different capabilities that this model has has. So I've written the function to main.py. I could include a few example how you can use it. Um, okay. Try to run this for the number. Let's say 7896. Okay. It read the file main.py and it's initiating the execution. And I can allow it once. Just once for now. I can say allow once. And it's trying to run this. It's outlining the strategy. It's trying to run a shell command which is python main.py. And I can allow it. So it's going to run this shell python uh main.py command. So the cube root of 7896 is approximately 19 91. So I have this. It's pretty good. It's working.

Now if I take this model to a new uh to my already existing code base. So for example, let me go ahead and go to this copilot eggno starter. Uh you can check out my last video. I made a video on this. So I can go ahead and do cmd and I can go ahead and do code space dot enter. So this will open up my cursor here. I would like to delete and kill everything first so that I can uh show you from the start. So Gemini and this will start up the Gemini and I can say that uh read the entire codebase uh and give me the summary. Let's see how much time does it take to read all these files and give me the answer. Now it's uh trying to read the different files here. As you can see readme, agent and this. So here's a breakdown. Readme file is this and you can see agent requirements. This is a Python dependencies. This is a full stack application that combines the Reactbased front end with a Python based back end to create an AI chatbot. The front end is built with Nex.js JS and copilot kit. While the back end is built with Agno and fast API, the agent can access financial data and web search results to answer user questions about investments. And that is pretty pretty much accurate.

Now, what I would like to show you is implementing the MCP's uh GitHub. So, we're going to go back to this and what it does on every startup is it searches um on two locations. So basically Gemini extensions and Gemini extensions or you can see that uh if we have a file known as Gemini extension.json it looks up at that file. Okay. If you go to Gemini do CLI tutorials then you can see that we have the entire process of setting up this model context protocol server. So first and foremost uh we're trying to do a GitHub MCB server. So what we need is an access token from GitHub first. So I can go ahead and say GitHub and then I go to settings here and then I go to developer settings here and then I go to personal access token and you can go and click on fine grain token and create a token for yourself. So once you have that token uh you can generate a new token here and put in a name uh just use public repositories here and you will be ready with the token.

Now once you have that token what you can do is that we need to have docker running. So we can go ahead and install Docker because this is where the server MCP server will be running. So we can download Docker desktop and keep it running. It looks like this. So this is Docker desktop. Next what you can do is we have already created a new token. Next what you can do is that in order to configure the MCP server we can go ahead and go to settings.json file and add this MCP server. So MCP server the name is GitHub command is docker arguments are these and environment variable is this. Now for this part of the environment variable I'm going to add in the actual environment variables for now. Okay. So this looks something like this. So we have MCP GitHub and then we have the actual access token here. Okay. So we're going to add this to uh gemini/ settings.json. Now how to find uh that location where you know you have that gemini file. Of course this is not in the present working directory that we work here. You can run this command basically uh you can run this command like who am who am I and you can see that I am omen np a l. Okay. So if I go to my C drive and if I go to my uh users okay and then I find the list of users. So this is this is the present user and inside that user I have I should have gemini and inside there I should have this settings. So this is the settings file that we need to change. So let me open this up with code lm. This is another editor. Now I'm going to add this thing this MCP thing in that location. So I'm going to copy this and then I'm going to put a comma here and I'm going to add the MCP server here. So you can see it's pretty cool. We have added the MCP server and now we can close this safely.

What I can do now is I can restart Gemini. So this is Gemini. I can control Ctrl + C two three times. This will stop this. And then I can go ahead and click on Gemini or type Gemini. And now you should be able to see uh one MCP server here. And if you want to see the MCP server you can say Ctrl + T. So I say Ctrl T. And you can see this MCB server which is ready. It shows green. It's a GitHub MCB server and it's ready. It has 51 tools and you can see all these tools. Now your access token will decide how many tools you're giving access to this MCP. Okay.

Now what you can do is uh you can go ahead and me the latest repo. Now you can use this MCP to do all sorts of things. So fetch the latest changes from the remote to this repository or find the most updated repository on your GitHub account. It's cool that it's asking me this question. It's two. I want to find the most updated repository on my GitHub account. Now it's trying to do what is my username. So my username is prompt engineer I think. Let me check it once again. So if I go to and if I go I can see this is my name which is prompt engineer 48. Can go ahead and say can delete everything and put in prompt engineer 48. So this is my username is refining the plan. It's trying to fetch different things. So it's asking me that it's trying to search for repository GitHub MCP server and the query is user uh prompt engineer 48 sort is updated and should I allow this for execution? Yes, just allow for once and u it should be able to fetch me the latest uh repository. So let's see and you can see that we have this 99% context left which means for this chat about 94 out of the 1 million uh tokens we have 94% left still. So you can see that this is the latest uh GitHub report that I have hosted. So MCP basic example if I go ahead to my repositories and then you can see there we have MCP basic example. I can go directly to this link as well. it should fetch me or send me to this. Okay, so this MCP works as well.

Now you can add in different MCPS, try uh different examples with this new Gemini CLI. It's an amazing it's an amazing CLI. I've used the other one and I am using this. Of course, there are not many tools as of now. You can add you can see the progress as it's going on just 2 days. You can see that 39.6K stars and it's amazing. If you are feeling confident, you can even contribute to it. I will bring in more interesting videos. But I hope you like this video. Please subscribe to my channel. I will see you in this next one. Thank you.