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
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- src/mcp_server_twelve_data/server.py:88-88 (registration)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)
- scripts/generate_tools.py:61-67 (helper)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)', '' ]
- scripts/split_openapi.py:28-28 (helper)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")