Ashare-DataStreamer-MCP
Delivers live and historical quotes for China A-shares via an optimized API, accommodating diverse temporal granularities and stock identifier conventions, leveraging redundant data pipelines for superior resilience.
Author

RusianHu
Quick Info
Actions
Tags
Ashare-DataStreamer-MCP Interface
This utility, Ashare-MCP, acts as a specialized data provision agent for Mainland China A-shares. It builds upon the underlying mpquant/Ashare library, exposing market data querying capabilities through the Model Context Protocol (MCP).
Core Capabilities
- Comprehensive temporal sampling support: Minute intervals (1m, 5m, 15m, 30m, 60m), Daily (1d), Weekly (1w), and Monthly (1M).
- Flexible ticker input: Accepts formats like Tongdaixun ('sh000001') and JoinQuant ('000001.XSHG').
- Dual-source redundancy: Data retrieval pipelines tap into both Sina Finance and Tencent Finance feeds, guaranteeing high availability.
- Asynchronous operation design for maximized throughput.
- A streamlined, user-friendly interface for remote function invocation.
Deployment Instructions
bash
Installation via the main repository
pip install git+https://github.com/RusianHu/Ashare-mcp.git
Installation with SOCKS proxy configuration
pip install git+https://github.com/RusianHu/Ashare-mcp.git --proxy socks5://127.0.0.1:10808
Local installation (Development/Editable mode)
git clone https://github.com/RusianHu/Ashare-mcp.git cd Ashare-mcp pip install -e .
Operational Modes
Integration as an MCP Backend Service
Configure the service within your central MCP manifest:
{ "mcpServers": { "ashare-mcp": { "command": "python", "args": [ "-m", "ashare_mcp" ], "alwaysAllow": [ "get_price" ], "disabled": false } } }
Standalone Execution
bash
Execute using standard I/O communication streams
ashare-mcp
Launch via the fastmcp HTTP interface handler
fastmcp serve ashare_mcp
Exposed MCP Functionality
get_price - Retrieve Stock Quote Series Data
Fetches chronological market data, supporting minute, daily, weekly, and monthly aggregations. | Parameter | Description | Data Type | Default Setting | |------|------|------|--------| | `code` | Security identifier (e.g., 'sh000001' or '000001.XSHG') | string | N/A | | `end_date` | The final date boundary for data retrieval ('YYYY-MM-DD') | string | Today's date | | `count` | The total number of records (bars) to fetch | integer | 10 | | `frequency` | The time interval of the bar: '1m', '5m', '15m', '30m', '60m', '1d', '1w', or '1M' | string | '1d' | | `fields` | Specifies the data attributes to be returned in the output object | array | All available fields | **Return Structure:** An object containing the security identifier, the calculated time-series data, and operational status messages.Illustrative Code Snippets
Code Examples
python # Fetching the last 5 days of daily OHLCV for Shanghai Composite Index result = await get_price_ashare_mcp(code="sh000001", count=5, frequency="1d") # Retrieving historical data for Kweichow Moutai up to a specific historical date result = await get_price_ashare_mcp(code="sh600519", end_date="2023-01-01", count=10, frequency="1d") # Requesting intraday 15-minute bars result = await get_price_ashare_mcp(code="sh600519", count=5, frequency="15m")Dependencies
- fastmcp (version >= 0.1.0)
- pandas
- requests
Collaboration
Contributions via Issues and Pull Requests are greatly appreciated for project enhancement!
Licensing Information
MIT
Copyright © 2025 RusianHu CONTEXTUAL REFERENCE: XMLHttpRequest (XHR) is an Application Programming Interface defined as a JavaScript object whose primary methods facilitate the transmission of HTTP requests from a client-side web application to a remote server. These capabilities enable asynchronous data exchange following the initial page load, which is foundational to modern asynchronous JavaScript and XML (Ajax) programming techniques. Before the advent of Ajax, server interaction primarily relied on traditional page reloads triggered by link navigation or form submissions.
== Chronology ==
The conceptual basis for XMLHttpRequest originated in 2000 through the efforts of Microsoft Outlook developers. This concept materialized first in Internet Explorer version 5 (released in 1999), although the initial implementation utilized COM object identifiers like ActiveXObject("Msxml2.XMLHTTP") rather than the standardized XMLHttpRequest string. By the release of Internet Explorer 7 (2006), this object identifier achieved universal support across all major rendering engines, including Mozilla's Gecko (2002), Safari 1.2 (2004), and Opera 8.0 (2005).
=== Standardization Path === The World Wide Web Consortium (W3C) published the initial Working Draft specification for the XMLHttpRequest object on April 5, 2006. A subsequent Working Draft Level 2 specification was released on February 25, 2008, introducing features such as progress monitoring methods, support for cross-origin communication, and byte stream handling. By the conclusion of 2011, the Level 2 additions were integrated back into the primary specification. Subsequently, the maintenance and evolution of the specification transitioned to the WHATWG at the end of 2012, which manages it as a living document utilizing Web IDL definitions.
== Operational Procedure == The standard sequence for executing a request using XMLHttpRequest involves several distinct procedural stages:
- Instantiate the XMLHttpRequest object using its constructor.
- Invoke the "open" method to define the request modality (GET/POST, etc.), specify the target Uniform Resource Identifier (URI), and determine whether the operation will be synchronous or asynchronous.
- For asynchronous operations, register an event handler to receive notifications upon changes in the request's state.
- Initiate the request lifecycle by calling the "send" method, potentially including payload data.
- Process state transitions within the registered event listener. Upon completion, the state transitions to 4 ("done"), and the server's response is typically accessible via the "responseText" property.
Beyond these fundamental steps, the object provides extensive control mechanisms. Custom header fields can be injected to guide server processing, and data payloads can be uploaded within the "send" invocation. Furthermore, the received data stream can be incrementally processed or parsed immediately into a native JavaScript object if the response is formatted as JSON. The operation can also be terminated prematurely or configured with a timeout limit.
