Skip to main content
Glama
twelvedata

Twelve Data MCP Server

Official
by twelvedata

GetForexPairs

Access daily-updated forex pairs data via API. Filter by symbol, base currency, or quote currency to retrieve real-time forex market information.

Instructions

This API call returns an array of forex pairs available at Twelve Data API. This list is updated daily.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • Calls register_all_tools which registers all tools, including GetForexPairs.
    register_all_tools(server=server, _call_endpoint=_call_endpoint)
  • Generic handler logic used by GetForexPairs tool to call the /forex_pairs endpoint on Twelve Data API.
    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 that produces the specific @server.tool(name='GetForexPairs') handler function for the tool in tools_autogen.py.
    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)', '' ]
  • Includes /forex_pairs endpoint in allowed_endpoints list used for tool generation.
    "/forex_pairs",
  • Generates Pydantic request models like GetForexPairsRequest used by the tool.
    request_models.append(code) request_names.add(class_name) # Write all generated models to the target file header = ( "from pydantic import BaseModel, Field\n" "from typing import Any, List, Optional\n\n" ) Path(REQUESTS_FILE).write_text(header + "\n\n".join(request_models), encoding="utf-8")

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