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.
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:
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
Provides tools for accessing financial data via the Financial Modeling Prep API:
Before using this AI agent, ensure you have the following:
uv package installer, recommended for Python project management (Reference) git clone https://github.com/tezansahu/ai-garage.git
cd ai-garage/mcp-agent
uv:
uv venv
# On Windows
.\.venv\Scripts\activate
# On macOS/Linux
source .venv/bin/activate
uv sync
.env files as follows:
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
financial_data_mcp_server/.env:
FINANCIAL_MODELING_PREP_API_KEY=your_fmp_api_key
cd mcp_client & start the MCP client, specifying the path to the MCP server script:
python mcp_client.py --server financial_data
python mcp_client.py --server financial_data --llm-provider ollama --model qwen2.5:7b
quit to exit the chat loop.[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
The client supports different LLM providers: