**mcp-use** client. By integrating live financial data through the Model Context Protocol (MCP), this guide walks through constructing agents that deliver in-depth market insights and actionable strategies.
In this cookbook, youβll explore:
- LangChain + OpenAI: A modular framework to build LLM-powered applications with support for agents, tools, and memory.
- Dappier MCP: A Model Context Protocol server that connects your agents to real-time, rights-cleared, AI-powered tools such as financial news, live stock data, and market summaries.
- mcp-use: A lightweight Python client that bridges any LLM with any MCP server using standard transports like
stdioandhttpβwithout relying on proprietary SDKs. - Stock Analysis & Investment Strategy: A real-world use case where the assistant performs deep research on a specific stock ticker and generates a strategic investment plan based on current market data.
π¦ Installation
To get started, install the required tools and dependencies:Step 1: Install
uv (required to run the Dappier MCP server)
macOS / Linux:
Step 2: Create a Virtual Environment (Recommended) Create and activate a virtual environment to isolate dependencies. macOS / Linux:
Step 3: Install Python Packages Install the necessary Python dependencies including LangChain and
mcp-use.
π Setting Up API Keys
Youβll need API keys for both Dappier and OpenAI to authenticate your requests and access tools.Dappier API Key Visit Dappier to generate your API key. Dappier provides free credits to help you get started. You can set the API key as an environment variable in your terminal:
.env file at the root of your project:
OpenAI API Key Go to OpenAI to retrieve your API key. Set it in your terminal:
.env file:
.env file:
Python
βοΈ Import Dependencies
Start by importing the required modules to build the stock research agent. This includes components frommcp-use, LangChain, and environment configuration.
Python
- Loading API keys from the environment using
dotenv - Running asynchronous workflows with
asyncio - Accessing OpenAI models via LangChain
- Connecting to the Dappier MCP server and executing tool-augmented financial research using
mcp-use
π Define User Input
Weβll collect the name of the company or stock from the user, which will be used to perform real-time research and analysis.Python
π°οΈ Run the Agent with Dappier MCP
This function sets up the MCP agent usingmcp-use, formulates the stock research query, and executes it using real-time financial tools provided by the Dappier MCP server.
Python
π¦ Initialize and Launch the Workflow
Themain() function collects user input, then launches the asynchronous workflow to run the stock research agent using mcp-use and Dappier MCP.
Python
asyncio:
Python
π Highlights
This cookbook has guided you through building a real-time stock research and investment strategy assistant using LangChain, Dappier MCP, and the**mcp-use** Python client. By connecting your agent to live financial tools via MCP, youβve enabled detailed market analysis and actionable investment recommendations based on up-to-date data.
Key components of this workflow include:
- LangChain + OpenAI: A modular framework for creating LLM-powered applications with agent capabilities.
- Dappier MCP: A Model Context Protocol server that enables access to real-time, rights-cleared financial tools including stock data, news, and market sentiment.
- mcp-use: A lightweight open-source client to connect any LLM to any MCP server using
stdioorhttptransports.

