ai-garage

AI Agent using Model Context Protocol (MCP)

Introduction

This project implements an AI agent using the Model Context Protocol (MCP) architecture, providing a flexible interface for LLM-powered interactions with various data sources.

It consists of an MCP Client with a command-line interface that can connect to different MCP Servers, including a Financial Data Server leveraging the Financial Modeling Prep (FMP) API to help answer users’ questions.

What is MCP?

The Model Context Protocol (MCP) is a specification for communication between large language models (LLMs) and external tools/services. Developed by Anthropic, MCP addresses several critical challenges in AI agent development:

Why MCP Matters

Project Architecture

This project implements the MCP architecture in the following manner:

sequenceDiagram
    actor User
    participant Client as MCP Client
    participant Server as MCP Server
    participant API as Financial API Server
    participant LLM as LLM (Azure/OpenAI/Ollama)
    
    %% Initialization
    User->>Client: Start client with server argument
    Client->>Server: Connect (stdio transport)
    Server-->>Client: Connection established
    Client->>Server: list_tools() request
    Server-->>Client: Return available tools
    Client-->>User: Display available tools
    
    %% User query flow
    User->>Client: Submit query
    Client->>LLM: Send query with available tools
    
    %% Tool calling flow with alt section for repeated tool calls
    LLM-->>Client: Response with tool calls
    
    loop while response contains tool calls
        Client->>Server: call_tool(tool_name, args)
        Server->>API: Request financial data
        API-->>Server: Return financial data
        Server-->>Client: Return tool execution results
        Client->>LLM: Send updated context with tool results
        LLM-->>Client: Generate new response
    end

    Client-->>User: Display final response
    
    %% Conversation continues
    User->>Client: Submit new query or 'quit'
    
    %% Cleanup on exit
    User->>Client: 'quit'
    Client->>Server: Close connection
    Client-->>User: Exit application

Components

Implemented Features

MCP Client

Financial Data MCP Server

Provides tools for accessing financial data via the Financial Modeling Prep API:

Setup & Usage

Prerequisites

Before using this AI agent, ensure you have the following:

Installation

  1. Clone the repository & get into the project directory
     git clone https://github.com/tezansahu/ai-garage.git
     cd ai-garage/mcp-agent
    
  2. Create and activate a virtual environment using uv:
     uv venv
     # On Windows
     .\.venv\Scripts\activate
     # On macOS/Linux
     source .venv/bin/activate
    
  3. Install all dependencies
     uv sync
    
  4. Set up environment variables by creating .env files as follows:
    • In mcp_client/.env:
        # For Azure OpenAI
        AZURE_API_KEY=your_azure_api_key
        AZURE_API_BASE=your_azure_endpoint
        AZURE_API_VERSION=your_api_version
        AZURE_API_DEPLOYMENT_NAME=your_deployment_name
      
        # For OpenAI
        OPENAI_API_KEY=your_openai_api_key
      
    • In financial_data_mcp_server/.env:
        FINANCIAL_MODELING_PREP_API_KEY=your_fmp_api_key
      

Usage

[Optional] Feel free to comment out line number 534 (logger.info(f"Processing request of type {type(req).__name__}")) in .venv/Lib/site-packages/mcp/server/lowlevel/server.py

LLM Provider Configurations

The client supports different LLM providers: