Metadata-Version: 2.5
Name: sl-economy-mcp
Version: 0.1.0
Summary: Unofficial MCP server for live Sri Lankan economic data from the Central Bank of Sri Lanka (CBSL).
Project-URL: Homepage, https://github.com/Akashwim/sl-economy-mcp
Project-URL: Issues, https://github.com/Akashwim/sl-economy-mcp/issues
Project-URL: Changelog, https://github.com/Akashwim/sl-economy-mcp/blob/main/CHANGELOG.md
Author: Akash Wimalananda
License-Expression: MIT
License-File: LICENSE
Keywords: cbsl,central-bank,economics,exchange-rates,inflation,mcp,sri-lanka
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Office/Business :: Financial
Requires-Python: >=3.10
Requires-Dist: mcp<3,>=2
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Description-Content-Type: text/markdown

# sl-economy-mcp

[![tests](https://github.com/Akashwim/sl-economy-mcp/actions/workflows/tests.yml/badge.svg)](https://github.com/Akashwim/sl-economy-mcp/actions/workflows/tests.yml)
[![live check](https://github.com/Akashwim/sl-economy-mcp/actions/workflows/live-check.yml/badge.svg)](https://github.com/Akashwim/sl-economy-mcp/actions/workflows/live-check.yml)

An unofficial [MCP](https://modelcontextprotocol.io) server that lets Claude and other AI assistants fetch live, official Sri Lankan economic data from the [Central Bank of Sri Lanka](https://www.cbsl.gov.lk) (CBSL).

Several MCP servers already cover Colombo Stock Exchange share prices. This one covers the macro side: interest rates, inflation and the rupee.

Every call fetches fresh data from CBSL, and every answer says where the data came from, when it was fetched and which date it refers to.

![A table Claude produced with these tools: policy rate, inflation, lending rates, Treasury bill yield and the rupee, each with its date and the value a year earlier](https://raw.githubusercontent.com/Akashwim/sl-economy-mcp/main/docs/briefing-example.png)

*Claude's answer to "Give me a Sri Lanka macro briefing", 9 October 2026. Every figure came from these tools; the layout and the year-earlier comparison are Claude's.*

## Tools

| Tool | What it returns |
| --- | --- |
| `get_snapshot` | Today's policy rate, inflation, real policy rate (policy rate minus inflation), and USD/LKR bank buying and selling rates, each with the date it refers to |
| `get_exchange_rate` | The rupee rate for one currency on one date (latest if no date is given). About 55 currencies, plus gold |
| `get_exchange_rate_history` | Daily or month-end rupee rates over a date range, with percentage change, high, low and average |
| `get_inflation_history` | Monthly headline and core inflation for the Colombo (CCPI) and national (NCPI) price indices |
| `get_interest_rates` | One of four groups: the Central Bank's policy rates with the date of each change, bank lending and deposit rates (weekly prime lending rate from 2007), Treasury bill yields, or Treasury bond yields. Lending rates and bill yields include the real rate after inflation |

All exchange rates are rupees per 1 unit of the foreign currency, so a rising number means a weaker rupee.

There is also one ready-made prompt, **Sri Lanka macro briefing**. Choose it from your assistant's prompt menu and it calls all the tools and writes a one-page briefing with sources.

## Example questions

- "What is Sri Lanka's policy rate and inflation right now? Is the real rate positive?"
- "How much did the rupee move against the dollar during 2022?"
- "When did the Central Bank last change interest rates, and by how much?"
- "How did the prime lending rate change between 2021 and today? What is it in real terms?"
- "Show monthly inflation since January 2024. When did it turn negative?"
- "What is the one-year Treasury bill yield, and how does it compare with a year ago?"
- "What is the price of gold in rupees today?"

## Install

The package is on [PyPI](https://pypi.org/project/sl-economy-mcp/) as `sl-economy-mcp`. In each case below, quit Claude completely before changing its settings file, because the running app can overwrite it. **Settings → Developer → Edit Config** shows you where the file is.

### If you have uv

With [uv](https://docs.astral.sh/uv/) installed there is nothing to install by hand. Add this to the settings file:

```json
{
  "mcpServers": {
    "sl-economy": {
      "command": "uvx",
      "args": ["sl-economy-mcp"]
    }
  }
}
```

### With plain Python

You need Python 3.10 or newer.

```bash
python3 -m venv ~/sl-economy-mcp-env
~/sl-economy-mcp-env/bin/pip install sl-economy-mcp
```

Then add this to the settings file, with your own username in the path:

```json
{
  "mcpServers": {
    "sl-economy": {
      "command": "/Users/YOUR-NAME/sl-economy-mcp-env/bin/sl-economy-mcp"
    }
  }
}
```

Save the file and open Claude again. The five tools should appear in the tools menu.

### From the source code

To read or change the code, clone the repository and install it from the folder:

```bash
git clone https://github.com/Akashwim/sl-economy-mcp.git
cd sl-economy-mcp
python3 -m venv .venv
.venv/bin/pip install ".[dev]"
```

## How it works

```
src/sl_economy_mcp/
  server.py          what the assistant can see: five tools and one prompt
  snapshot.py        reads CBSL's headline "rate window"
  exchange_rates.py  submits CBSL's exchange rate search forms and reads the results
  inflation.py       reads the monthly table on CBSL's inflation page
  interest_rates.py  picks lending rates and Treasury yields out of the Data Library
  data_library.py    searches CBSL's Data Library, which needs a cookie and hidden form fields
  fetch.py           downloads pages: 5-minute cache, honest User-Agent, clear errors
  series.py          first, last, high, low, average and month-ends of a series
  tables.py          turns an HTML table into rows of text
  dates.py           Sri Lanka's clock and reading typed dates
  errors.py          the problems we expect, each with a plain-English message
```

Design choices:

- **Live, not stored.** Nothing is saved between runs. A short cache stops repeated questions from hitting CBSL again and again: 5 minutes for most pages, an hour for the slow Data Library tables, which change weekly at most.
- **One outside dependency**, the official MCP Python SDK. Downloading and reading pages uses Python's standard library.
- **Fail loudly.** If a CBSL page changes shape, the tool says so. It never guesses a number.
- **Honest about gaps.** Where CBSL's data is missing or running behind, the answer says so.
- **Read only what is needed.** CBSL's tables contain the odd typo. A bad cell in a column the tool does not use is ignored; a bad cell in one it does use is an error.
- **Tested offline.** The tests run against saved copies of real CBSL pages, so they need no internet and always give the same result.

## Data sources and limits

| Data | CBSL source |
| --- | --- |
| Policy rate, inflation, USD buy/sell | [Rate window](https://www.cbsl.gov.lk/cbsl_custom/param/ratewindow.php) |
| Daily indicative rates | [Daily Indicative Exchange Rates](https://www.cbsl.gov.lk/en/rates-and-indicators/exchange-rates/daily-indicative-exchange-rates) |
| Bank buying and selling rates | [Daily Buy and Sell Exchange Rates](https://www.cbsl.gov.lk/en/rates-and-indicators/exchange-rates/daily-buy-and-sell-exchange-rates) |
| Monthly inflation | [Measures of Consumer Price Inflation](https://www.cbsl.gov.lk/en/measures-of-consumer-price-inflation) |
| Lending and deposit rates | [Data Library: Commercial Banks Lending and Deposit Rates](https://www.cbsl.lk/eResearch/MoneyMarketRatesDefault.aspx?ReportId=6277) |
| Treasury bill and bond yields | [Data Library: Rates on Government Securities](https://www.cbsl.lk/eResearch/MoneyMarketRatesDefault.aspx?ReportId=6169) |
| Policy rates | [Data Library: Daily Operations](https://www.cbsl.lk/eResearch/MoneyMarketRatesDefault.aspx?ReportId=1059) |

- The rate window shows no dates, so `get_snapshot` matches each figure against CBSL's dated tables. If they disagree it says "not confirmed" and does not guess.
- Exchange rates are published on business days. Ask for a weekend or holiday and you get the most recent earlier rate, clearly labelled.
- CBSL's online exchange rate lookup starts on 7 May 2010. It is complete from 2014 onwards and has many missing days before that.
- Bank buying and selling rates exist for nine currencies: AUD, CAD, CHF, CNY, EUR, GBP, JPY, SGD and USD.
- CBSL's inflation table covers about six years and currently skips 2023. The tool points out the gap.
- Treasury and policy rate searches are slow, and CBSL's speed varies from day to day: about 30 seconds for 6 months and up to a minute for 12. To keep ordinary questions quicker, the tool looks at the last 6 months of policy rates and Treasury yields unless you ask for a longer range. If that short look finds nothing, because CBSL is running behind, it looks back a full year. It waits up to 90 seconds and tries twice before reporting a failure.
- The Data Library's Treasury figures sometimes run months behind. The tool reports the date of the latest figure it found.
- Policy rate history is limited to 12 months per request because CBSL's source is slow.
- Treasury bond yields exist only for weeks in which CBSL auctioned that maturity, so they are sparse.
- Real rates are given two ways: the rate minus inflation, and the Fisher equation, which is more exact when inflation is high. Both use past inflation (the latest year-on-year figure), so they are a rough guide, not a forecast.

## Running the tests

From a copy of the source code (see above):

```bash
.venv/bin/python -m pytest
```

## Live check

The tests above use saved pages, so they cannot notice CBSL changing its website. A second check does: every weekday GitHub calls each tool against the real CBSL site and checks the answers are plausible (for example, a buying rate below the selling rate, and a prime lending rate no more than three weeks old). If a page has changed shape, the check fails and the maintainer is emailed. If one or two tools cannot reach CBSL, it only warns. If more than that are unreachable it fails, so a green tick always means the tools were really tested.

CBSL's site sometimes refuses GitHub's servers ("HTTP 403") while working normally for everyone else. A red live check with that message means GitHub was blocked that day, not that the tool is broken. The check can be run from any ordinary connection:

```bash
.venv/bin/python checks/live_check.py
```

## Disclaimer

This is an unofficial project. It is not affiliated with, endorsed by or supported by the Central Bank of Sri Lanka. The data is read from CBSL's public websites and may contain errors or be out of date. Nothing here is investment advice. For anything that matters, check the figure with CBSL.

## Credit

All data belongs to the [Central Bank of Sri Lanka](https://www.cbsl.gov.lk), which publishes it freely.

## Licence

[MIT](LICENSE)
