VNStock MCP Server

VNStock MCP Server

By gahoccode GitHub

MCP server for fetching historical stock prices using vnstock

vnstock stock-prices
Overview

what is VNStock MCP Server?

VNStock MCP Server is a Message Communication Protocol server designed to fetch historical stock prices for multiple Vietnamese companies using the vnstock library.

how to use VNStock MCP Server?

To use the VNStock MCP Server, set up the server by configuring the stock data service and starting the server. Clients can then request stock data within a specified date range via API endpoints.

key features of VNStock MCP Server?

  • Fetch historical stock data for multiple Vietnamese companies
  • Configure stocks to track via a JSON configuration file
  • Request stock data within a specific date range
  • MCP protocol support for integration with clients like Claude Desktop
  • Direct API endpoint for stock data retrieval

use cases of VNStock MCP Server?

  1. Retrieving historical stock prices for analysis and reporting.
  2. Integrating with financial applications to provide real-time stock data.
  3. Supporting trading algorithms that require historical data for decision-making.

FAQ from VNStock MCP Server?

  • What programming language is VNStock MCP Server written in?

VNStock MCP Server is written in Python.

  • How do I install the VNStock MCP Server?

You can install it using a virtual environment or Poetry as described in the installation section.

  • Can I customize the stock data I want to track?

Yes! You can customize the stocks to track by editing the stock configuration JSON file.

Content

VNStock MCP Server

An MCP (Message Communication Protocol) server that fetches historical stock prices for multiple companies using the vnstock library. The server reads a configuration file and allows clients (e.g., Claude Desktop) to request stock data within a specific date range.

Features

  • Fetch historical stock data for multiple Vietnamese companies
  • Configure stocks to track via a JSON configuration file
  • Request stock data within a specific date range
  • MCP protocol support for integration with Claude Desktop
  • Direct API endpoint for stock data retrieval

Requirements

  • Python 3.10 or higher
  • vnstock 3.2.2
  • fastapi 0.115.12
  • uvicorn 0.34.0
  • pydantic 2.10.6
  • python-dotenv 1.0.1

Installation

# Create virtual environment
python -m venv venv

# Activate virtual environment (Windows)
venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

Using Poetry

# Install poetry if not already installed
pip install poetry

# Install dependencies
poetry install

Using UV

# Install uv if not already installed
pip install uv

# Install dependencies
uv pip install -r requirements.txt

Configuration

The application uses two separate configuration files:

1. Stock Configuration (stock_config.json)

This file contains the configuration for the stock data service, including which stocks to track and server settings:

{
  "stocks": [
    {
      "symbol": "VNM",
      "name": "Vietnam Dairy Products Joint Stock Company"
    },
    {
      "symbol": "VHM",
      "name": "Vinhomes Joint Stock Company"
    }
  ],
  "server": {
    "host": "0.0.0.0",
    "port": 8000
  },
  "default_days": 30,
  "max_days": 365
}

2. Claude Desktop Configuration (claude_desktop_config.json)

This file is used by Claude Desktop to register and communicate with the MCP server:

{
  "mcpServers": {
    "stock_prices": {
      "command": "python",
      "args": [
        "path/to/vnstock_mcp_server/main.py"
      ]
    }
  }
}

You should place this file in the Claude Desktop configuration directory, typically:

  • Windows: %APPDATA%\Claude Desktop\claude_desktop_config.json
  • macOS: ~/Library/Application Support/Claude Desktop/claude_desktop_config.json
  • Linux: ~/.config/Claude Desktop/claude_desktop_config.json

Usage

Starting the Server

# Activate virtual environment (if using)
venv\Scripts\activate

# Start the server with default configuration
python main.py

# Start the server with custom configuration
python main.py --config path/to/config.json

# Override host and port
python main.py --host 127.0.0.1 --port 8080

API Endpoints

MCP Protocol Endpoints

  • GET /get-tools: Get available tools for the MCP protocol
  • POST /tool-call: Call a tool in the MCP protocol

Direct Endpoints

  • GET /: Health check endpoint
  • GET /stock-data: Get historical stock data for one or more symbols

Example Requests

Using the MCP Protocol

// POST /tool-call
{
  "tool": "vnstock",
  "method": "get_stock_data",
  "parameters": {
    "symbols": ["VNM", "VHM"],
    "start_date": "2023-01-01",
    "end_date": "2023-01-31"
  }
}

Using the Direct Endpoint

GET /stock-data?symbols=VNM&symbols=VHM&start_date=2023-01-01&end_date=2023-01-31

License

This project is licensed under the MIT License - see the LICENSE file for details.

No tools information available.
No content found.