CryptoAnalysisMCP icon indicating copy to clipboard operation
CryptoAnalysisMCP copied to clipboard

Free base URL + query-param auth: paid CoinPaprika features unreachable

Open donbagger opened this issue 6 months ago • 1 comments

Hi, I'm Mateusz from CoinPaprika. We're listed in your README as a data source, so flagging two things in Sources/CryptoAnalysisMCP/CryptoDataProvider.swift that prevent paid CoinPaprika users from getting paid-tier features through this MCP:

1. Free base URL is hardcoded

CryptoDataProvider.swift:12

private let coinPaprikaBaseURL = "https://api.coinpaprika.com/v1"

Paid plans (Starter / Pro / Business / Ultimate / Enterprise) live on a different host:

https://api-pro.coinpaprika.com/v1

Even if a user sets COINPAPRIKA_API_KEY, requests still go to the free base, where paid endpoints like /tickers/{id}/historical, /coins/{id}/ohlcv/historical, /coins/mappings, and /key/info either 402 or omit fields like circulating_supply.

2. Query-param auth instead of Authorization header

CryptoDataProvider.swift:256-257

if let apiKey = apiKey {
    urlString += "&apikey=\(apiKey)"
}

CoinPaprika's documented auth path is the Authorization header (bare key, no Bearer prefix):

Authorization: <api-key>

?apikey= query-param auth isn't part of the documented REST API surface. Header auth is the canonical way and works on every endpoint.

Suggested fix

private var coinPaprikaBaseURL: String {
    apiKey != nil
        ? "https://api-pro.coinpaprika.com/v1"
        : "https://api.coinpaprika.com/v1"
}

// ... and on the URLRequest construction:
var request = URLRequest(url: url)
if let apiKey = apiKey {
    request.setValue(apiKey, forHTTPHeaderField: "Authorization")
}
let (data, response) = try await URLSession.shared.data(for: request)

Drop the &apikey= concatenation while you're at it.

References

  • Auth: https://docs.coinpaprika.com/api-reference/rest-api/introduction
  • Plans / base URLs: https://docs.coinpaprika.com/api-plans
  • /key/info endpoint (useful for self-throttling): https://docs.coinpaprika.com/api-reference/key/get-api-key-info

Happy to send a PR if it'd be useful, or you can take it from here. Either way, thanks for building this.

donbagger avatar May 05 '26 13:05 donbagger

Following up with the live wire trace — I should have included this when I filed.

I cloned the repo, replicated the exact request shape from CryptoDataProvider.swift (free base URL + &apikey= query param), and compared it against the correct pattern (api-pro + Authorization header). The two responses confirm the auth never lands:

# What the MCP actually sends — free host with ?apikey= query param
$ curl -sS "https://api.coinpaprika.com/v1/coins/btc-bitcoin/ohlcv/historical?start=2026-04-01&end=2026-04-07&interval=1d&apikey=<key>"
{"error":"Getting historical OHLCV data before 2026-05-05 ... is not allowed in this plan. Check plans on coinpaprika.com/api"}

# Correct pattern — api-pro + Authorization header, same date range, same key
$ curl -sS -H "Authorization: <key>" "https://api-pro.coinpaprika.com/v1/coins/btc-bitcoin/ohlcv/historical?start=2026-04-01&end=2026-04-07&interval=1d"
{"error":"Getting historical OHLCV data with '1d' interval is not allowed in this plan. Check plans on coinpaprika.com/api"}

The error messages diverge on purpose — they come from different code paths:

  • The first one is the free-plan restriction (only the last 24h of historical data on free). The ?apikey= param is silently ignored, so the server thinks the caller is on free.
  • The second one is an authenticated-but-plan-limited response (different interval restriction kicks in based on the actual plan tier identified from the header).

So both findings in the issue body are confirmed live: the query-param auth doesn't authenticate at all, and even if it did, the request still has to go to api-pro.coinpaprika.com, not api.coinpaprika.com.

The fix in the issue body holds — switch base URL when key is set, send Authorization: <key> header instead of &apikey=.

donbagger avatar May 06 '26 08:05 donbagger