Backtest a gold strategy with historical OHLC
Pull daily OHLC history from the goldprice.dev API and run a simple moving-average crossover backtest in Python to evaluate a gold trading strategy.
Read →Add the goldprice.dev MCP server to Claude or Cursor so your agent can fetch the current gold spot price without any hand-rolled tool code.
When you build an agent that needs live market data, the usual path is to write a tool function, register it with the model, handle the response parsing, and then maintain that glue code forever. With MCP (the Model Context Protocol) you skip straight to the result: the MCP server exposes the tools and the model calls them directly. The underlying data is the same live gold spot price available through the REST API.
goldprice.dev ships an MCP server. It is available on the free tier. You configure it once in your agent environment and then just ask the agent for the gold price.
An MCP server is a small process that the model runtime can talk to over a standard protocol. The server declares what tools it offers (names, descriptions, parameter schemas) and the model decides when to call them based on what the user asks. You do not write the invocation logic; the model handles that.
This matters because the alternative is hand-rolled tool calling: you define a function, write a JSON schema for it, register it in the API call, parse the model's tool-call response, run the function, inject the result back, and loop. That is around 50 lines of plumbing per tool. MCP replaces all of it with a config entry.
Open your Claude configuration file. In Claude Code it is ~/.claude/settings.json. In the Claude desktop app, go to Settings > Developer > Edit Config.
Add the goldprice.dev MCP server under mcpServers:
{
"mcpServers": {
"goldprice": {
"command": "npx",
"args": ["-y", "@goldprice/mcp-server"],
"env": {
"GOLDPRICE_API_KEY": "ga_live_YOUR_KEY_HERE"
}
}
}
}
Restart Claude. The server starts automatically when the session opens. You will see the goldprice tools appear in the tool list if your client shows available tools.
In Cursor, open Settings > MCP and add a new server entry. The format is the same command + args + env structure. Paste your key into the env block and save.
Cursor will show a green dot next to the server name when it is connected.
Once the server is connected, no additional code is needed. Ask naturally:
"What is the current gold spot price in USD?"
The agent calls the appropriate MCP tool, gets back the price and timestamp, and reports it. You can also ask for context:
"What's the gold price right now, and how does it compare to yesterday's close?"
The model decides which tools to call and in what order. If the MCP server exposes both spot and history tools, the agent will use both to answer.
The comparison is straightforward. A hand-rolled tool requires code that fetches the API, handles errors, formats the response, and passes it back into the model's context. You maintain that code. When the API adds a field or changes a response shape, you update the code.
With MCP, the server handles all of that. Updates to the goldprice.dev MCP server ship as package updates. You run npx -y @goldprice/mcp-server and it fetches the latest version automatically.
The bigger benefit is composability. Once the server is connected, every agent in that environment can use it: your Claude Code session, a Cursor edit, a background agent running a cron job. You configure the auth once. The tools are available everywhere.
If you are building your own agent with an MCP-compatible runtime (the Anthropic SDK, for example, supports MCP client connections), you can point it at the server the same way:
import anthropic
client = anthropic.Anthropic()
# The SDK's MCP support lets you connect to any stdio MCP server.
# Pass the server config when creating an agent run or a tool list.
# Check the SDK docs for the current client.beta.messages.with_mcp call.
The exact API surface depends on your SDK version. Check the MCP integration docs for your runtime. The server process is the same regardless of host.
You do not need a paid plan to use the MCP server. The free tier gives you 1000 calls per month and 30 requests per minute, which covers the typical agent session easily. If you are running a persistent agent that checks the price frequently, watch the X-RateLimit-Remaining header returned by underlying API calls and add a delay when it gets low.
Get your key via the MCP setup guide and you are one config block away from live gold prices in any MCP-capable agent. If you prefer a hand-rolled approach first, Fetch live gold prices in JavaScript covers the REST equivalent.
// related guides
Pull daily OHLC history from the goldprice.dev API and run a simple moving-average crossover backtest in Python to evaluate a gold trading strategy.
Read →Pull gold and silver spot prices in a single async call, divide them, and display the ratio with a working JavaScript example.
Read →How to convert a USD per troy ounce gold price into other currencies and per-gram units, with a working JavaScript example.
Read →// goldprice.dev
Live gold prices, historical OHLC, and multi-source aggregation — available via REST and SSE.