OPEN SOURCE / AGENT ORCHESTRATION

Market workflows.
Agentic by design.

Explore how LangGraph, LangChain and the Model Context Protocol (MCP) coordinate tools through conditional routing, ReAct-style loops and local server connections—using fictional stock quotes and simulated trading actions.

Simulation only: No live market feed, exchange connection, investment recommendation or actual brokerage order.

LangGraphStateful graph orchestration
LangChainTools and tool messages
2 MCPSTDIO + HTTP servers
PythonCLI + Jupyter notebook

A practical agentic workflow lab.

From a direct Python tool call to a graph-driven agent loop, the repository demonstrates the moving parts of agent-based applications using intentionally safe, deterministic examples.

LangChain tools

Python tool wrappers for stock-price lookup and simulated buy/sell actions, including manual invocation and tool response messages.

LangGraph workflows

StateGraph, MessagesState, conditional edges, ToolNode and routing patterns that model repeated tool-use decisions.

ReAct-style orchestration

Illustrates the agent → tools → agent cycle, with separate graph examples for basic, manual, conditional and prebuilt execution.

Model Context Protocol

Local STDIO stock tools and an optional Streamable HTTP news service demonstrate MCP tool discovery and invocation.

Market simulation

Fixed illustrative stock prices, deterministic trade responses, and synthetic news and sentiment. No live quote feeds or broker APIs.

Optional live LLM

Explicit --live mode integrates an OpenAI model for tool-call selection when you configure your own API key.

Python 3.12LangChainLangGraphMCPReActStateGraphToolNodeSTDIOStreamable HTTPJupyter

From a request to a tool result.

The workflow separates the agent's routing logic from the tools it can call. The offline mode uses a rule-based stand-in for the model; live mode can use OpenAI instead.

AGENT → TOOL ROUTINGILLUSTRATIVE SYSTEM FLOW

TRANSPORT 01 / STDIO

Stock MCP server

The client launches a local subprocess hosting stock_price, buy_stock and sell_stock. Returned prices and trade messages are fictional.

TRANSPORT 02 / STREAMABLE HTTP

News MCP server

Optional server on 127.0.0.1:8000/mcp exposes market_news and market_sentiment with synthetic results. It should remain local.

When a ReAct graph is selected, a tool result can return to the agent node for the next decision. This diagram summarizes the example paths; specific command flags select different configurations.

Study the flow offline, or connect a model.

API access is optional. The project is designed to let developers explore graph mechanics without sending requests to a commercial model by default.

Offline mode

DEFAULT

A deterministic rule-based object imitates the bind_tools, invoke and ainvoke interface. It is useful for learning tool-routing behavior without a paid API.

  • Predefined examples and rule-based parsing
  • Simulated stock quotes and trades
  • LangGraph control-flow exploration
  • No LLM inference or investment analysis

Optional live mode

API KEY REQUIRED

The --live option can call an OpenAI tool-capable model when properly configured. MCP examples can also connect to local tool servers.

  • Set OPENAI_API_KEY privately
  • Model usage may incur charges
  • Local MCP servers still return fictional data
  • Live integrations are not independently benchmarked

Five inspectable tool interfaces.

The source includes three market-operation tools and two news/sentiment tools. Their examples prioritize control flow and integration boundaries over market realism.

ToolSourceBehavior
stock_price(name)Stock / STDIOReturns a predefined illustrative USD price, not a live market quote.
buy_stock(name, qty)Stock / STDIOReturns a simulated buy message; no brokerage order is created.
sell_stock(name, qty)Stock / STDIOReturns a simulated sell message; no brokerage order is created.
market_news(query)News / HTTPReturns a synthetic headline-style response; does not fetch articles.
market_sentiment(symbol)News / HTTPReturns fictional sentiment availability text, not a recommendation.

From repository to first tool call.

Start with the offline self-test, then explore selected LangGraph and MCP examples. These commands assume Python is installed and your terminal is inside the cloned repository.

01. Clone and install dependencies

POWERSHELL
git clone https://github.com/su394611-del/Stock-market-trading-Application-using-MCP-langchain-langgraph.git
cd Stock-market-trading-Application-using-MCP-langchain-langgraph
py -3.12 -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements.txt

02. Self-test and offline agent examples

NO API KEY
.\.venv\Scripts\python.exe MCP_Langchain_Langraph_Tools.py --self-test
.\.venv\Scripts\python.exe MCP_Langchain_Langraph_Tools.py --list
.\.venv\Scripts\python.exe MCP_Langchain_Langraph_Tools.py --topic react --graph-mermaid

03. Explore MCP integration

LOCAL SERVERS
# Terminal A: start the synthetic news HTTP server
.\.venv\Scripts\python.exe news_mcp_server.py

# Terminal B: client launches the STDIO stock server
.\.venv\Scripts\python.exe MCP_Langchain_Langraph_Tools.py --topic mcp-client --include-news

Read the implementation, not just the summary.

Open the original files to inspect the tool implementations, graph routing, MCP servers, notebook walkthrough and dependency constraints.