Skip to main content
Glama
twelvedata

Twelve Data MCP Server

Official
by twelvedata

GetMarketState

Check stock exchange operating status, including open/close times and availability across global markets. Retrieve current market state data for trading decisions.

Instructions

Check the state of all available exchanges, time to open, and time to close. Returns all available stock exchanges by default.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • Generic HTTP client handler used by all tools, including GetMarketState, to call the corresponding Twelve Data API endpoint (/market_state). Handles param resolution, API key injection, error handling, and response validation.
    async def _call_endpoint( endpoint: str, params: P, response_model: Type[R], ctx: Context ) -> R: params.apikey = extract_twelve_data_apikey( twelve_data_apikey=twelve_data_apikey, transport=transport, ctx=ctx ) params_dict = params.model_dump(exclude_none=True) resolved_endpoint = resolve_path_params(endpoint, params_dict) async with httpx.AsyncClient( trust_env=False, headers={ "accept": "application/json", "user-agent": "python-httpx/0.24.0" }, ) as client: resp = await client.get( f"{api_base}/{resolved_endpoint}", params=params_dict ) resp.raise_for_status() resp_json = resp.json() if isinstance(resp_json, dict): status = resp_json.get("status") if status == "error": code = resp_json.get('code') raise HTTPException( status_code=code, detail=f"Failed to perform request," f" code = {code}, message = {resp_json.get('message')}" ) return response_model.model_validate(resp_json)
  • Code generator template that creates the specific registration for GetMarketState (and all tools) via @server.tool decorator, mapping operationId to tool name, with generic handler call to /market_state endpoint.
    lines.append('def register_all_tools(server: FastMCP, _call_endpoint):') for op, desc, key in ops: fixed_op = fix_case(op) lines += [ f' @server.tool(name="{op}",', f' description="{desc}")', f' async def {op}(params: {fixed_op}Request, ctx: Context) -> {fixed_op}200Response:', f' return await _call_endpoint("{key}", params, {fixed_op}200Response, ctx)', '' ] return '\n'.join(lines)
  • Where register_all_tools is invoked to register all tools including GetMarketState.
    if vector_db_exists(): register_all_tools(server=server, _call_endpoint=_call_endpoint) u_tool = register_u_tool(
  • Generator for response Pydantic models from OpenAPI spec, used by GetMarketState (though example shows alias for another tool). GetMarketState200Response would be similarly generated.
    alias_lines = [ '', '# Aliases for response models', 'GetMarketMovers200Response = MarketMoversResponseBody',
  • Test pairing confirming GetMarketState tool exists for market status queries.
    ("Is the NASDAQ market currently open?", "GetMarketState"),

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/twelvedata/mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server