Skip to main content
This cookbook demonstrates how to build a real-time Stock Analyst Agent using OpenAI Agents and the Dappier MCP. By combining structured agent workflows with live financial data, this notebook walks you through building a dynamic assistant that analyzes a chosen tech sector, summarizes key news and trends, and recommends a tailored investment strategy. In this cookbook, you’ll explore:
  • OpenAI Agents SDK: A powerful toolkit that enables large language models to operate as autonomous agents, use tools, and execute multi-step workflows with memory and structured decision-making.
  • Dappier MCP: A Model Context Protocol server that connects your agents to real-time, rights-cleared tools β€” including live search, financial data, stock tickers, content recommendations, AI-powered summaries, and more. Dappier MCP acts as a gateway to trusted data and intelligent utilities your agent can use dynamically.
  • Real-Time Stock Analysis: A practical use case where the agent analyzes a user-selected tech sector, pulls live financial signals, and generates a smart, explainable investment strategy with top stock picks.
This cookbook offers a foundation for building real-time, data-augmented AI agents that operate with current financial context, and can be extended to support any domain where market conditions matter.

πŸ“¦ Installation

To get started, install the required tools and dependencies: Step 1: Install uv (required to run the Dappier MCP server) macOS / Linux:
Windows:

Step 2: Install Python Packages Install the the OpenAI Agents SDK:

πŸ”‘ Setting Up API Keys

You’ll need API keys for both Dappier and OpenAI to authenticate your requests and access real-time tools. Dappier API Key Head to Dappier to sign up and generate your API key. Dappier offers free credits to get started. You can set your API key as an environment variable in your terminal:
Or programmatically in your Python script:
Python

OpenAI API Key Visit OpenAI to retrieve your API key. Set it in your terminal:
Or in your Python script:
Python

βš™οΈ Import Dependencies

Start by importing all required modules to build the stock analyst agent. This includes components from the OpenAI Agents SDK and the Dappier MCP server.
Python
These imports enable:
  • Running the MCP server locally via MCPServerStdio
  • Tracing and managing the agent’s execution with Runner and trace
  • Streaming the assistant’s output using ResponseTextDeltaEvent

πŸ“ Define User Input

We’ll collect the tech sector the user is interested in analyzing.
Python

πŸ›°οΈ Run the Agent with Dappier MCP

This function sets up the agent, formulates the user query, and streams the response using tools served via Dappier MCP.
Python

🚦 Initialize and Launch the Workflow

The main() function sets up the Dappier MCP server, enables tracing for observability, and runs the stock analysis agent.
Python

πŸ§ͺ Run the Stock Analyst Agent

This block checks for the required uvx binary and launches the full async workflow. Make sure uvx is installed and available in your system path.
Python

🌟 Highlights

This cookbook has guided you through setting up and running a real-time stock analyst using OpenAI Agents and the Dappier MCP Server. By connecting your agent to real-time tools via MCP, you’ve created an assistant capable of analyzing sector-specific trends and recommending investment strategies grounded in live data. Key components of this workflow include:
  • OpenAI Agents SDK: A powerful toolkit that enables large language models to operate as autonomous agents, use tools, and execute multi-step workflows with memory and structured decision-making.
  • Dappier MCP: A Model Context Protocol server that connects your agents to real-time, rights-cleared, AI-powered tools such as financial news, stock tickers, earnings data, live search, and content recommendations.
  • AI Stock Analysis: A real-world use case where the assistant analyzes a user-selected tech sector, gathers current financial signals, and returns a detailed, data-backed investment strategy with top stock picks.
This architecture can be adapted to other use cases requiring live data integration, intelligent tool use, and context-aware decision-making using the Agents SDK and MCP ecosystem.