MCP ExplorerExplorer

Gemini Mcp Client Ts

@EnigmaticHarveston 20 days ago
1 MIT
FreeCommunity
AI Systems
typescript implementation of an MCP client using gemini as LLM using gemini sdk and model context protocol sdk

Overview

What is Gemini Mcp Client Ts

gemini-mcp-client-ts is a TypeScript implementation of an MCP client that utilizes Google’s Gemini model through the Gemini SDK and Model Context Protocol SDK.

Use cases

Use cases include developing chatbots, integrating AI capabilities into applications, and utilizing advanced language models for research and development purposes.

How to use

To use gemini-mcp-client-ts, clone the repository, install dependencies using npm, set up environment variables including your Gemini API key, and configure MCP servers for tool access.

Key features

Key features include a command-line interface for chatting with the Gemini model, the ability to connect to multiple MCP servers, and customizable server configurations for tool discovery.

Where to use

gemini-mcp-client-ts can be used in various fields such as AI development, natural language processing, and any application that requires interaction with the Gemini model and MCP tools.

Content

MCP Chat CLI

A command-line interface to chat with Google’s Gemini model, with the ability to connect to and utilize tools from Model Context Protocol (MCP) servers.

Prerequisites

  • Node.js (version 18 or higher recommended)
  • npm (comes with Node.js)

Setup

  1. Clone the repository (if you haven’t already):

    git clone <repository_url>
    cd mcp-chat-cli
    
  2. Install dependencies:

    npm install
    
  3. Set up environment variables:
    Create a .env file in the root of the project directory. Add the following lines, replacing the placeholder with your actual Gemini API key:

    GEMINI_API_KEY=YOUR_GEMINI_API_KEY
    # Optional: Specify a Gemini model name. Defaults to a standard one if not set.
    # GEMINI_MODEL_NAME=gemini-1.5-flash-latest 
    

    You can obtain a Gemini API key from Google AI Studio.

Configuration

MCP Servers

This CLI can connect to MCP servers to make tools available to the Gemini model. You need to configure these servers first.

  • Add an MCP Server:

    npm run cli -- servers add <serverName> <serverUrl>
    
    • <serverName>: A unique name you choose for this server (e.g., my-mcp-server).
    • <serverUrl>: The full URL of the MCP server (e.g., http://localhost:8080).

    The first server you add will automatically become the default server used for tool discovery.

  • List Configured Servers:

    npm run cli -- servers list
    

    This will show all configured servers and indicate which one is the default.

  • Set a Default Server:
    If you have multiple servers, you can specify which one should be used by default for tool discovery.

    npm run cli -- servers default <serverName>
    
  • Remove a Server:

    npm run cli -- servers remove <serverName>
    

Usage

Chatting with Gemini

Once your environment variables are set up (and MCP servers are configured if you want to use tools), you can start a chat session:

npm run cli -- chat

During the chat:

  • Type your message and press Enter.
  • To reference a local file in your message, use the format localfile(path/to/your/file.ext). The content of the file will be read, base64 encoded, and sent to Gemini.
  • If MCP servers are configured and tools are discovered, Gemini may use these tools to respond to your queries.
  • Type exit or quit to end the chat session.

Managing MCP Servers

Use the servers commands as described in the “Configuration” section to manage your MCP server list.

Command Structure:
npm run cli -- <command> [subcommand] [options]

Examples:

# Add a local MCP server
npm run cli -- servers add local-tools http://localhost:3000

# List all configured MCP servers
npm run cli -- servers list

# Set 'local-tools' as the default server
npm run cli -- servers default local-tools

# Start a chat session
npm run cli -- chat

Development

  • Build the project (compile TypeScript to JavaScript):

    npm run build
    

    This will output JavaScript files to the dist directory.

  • Run in development mode (watches for changes and restarts):

    npm run dev -- <command> 
    

    For example, to run the chat in dev mode:

    npm run dev -- chat
    

Tools

No tools

Comments