Skip to main content
Glama
bank-of-japan-mcp-server

bank-of-japan-mcp-server

by cyanheads
README.md
<div align="center">
  <h1>@cyanheads/bank-of-japan-mcp-server</h1>
  <p><b>Search Bank of Japan statistics and retrieve time series, Tankan surveys, and policy rates via MCP. STDIO or Streamable HTTP.</b></p>
  <div>7 Tools (+1 opt-in)</div>
</div>

<div align="center">

[![npm](https://img.shields.io/npm/v/@cyanheads/bank-of-japan-mcp-server?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@cyanheads/bank-of-japan-mcp-server) [![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg?style=flat-square)](./LICENSE) [![Docker](https://img.shields.io/badge/Docker-ghcr.io-2496ED?style=flat-square&logo=docker&logoColor=white)](https://github.com/users/cyanheads/packages/container/package/bank-of-japan-mcp-server) [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-^2.4.0-green.svg?style=flat-square)](https://modelcontextprotocol.io/) [![TypeScript](https://img.shields.io/badge/TypeScript-^7.0.2-3178C6.svg?style=flat-square)](https://www.typescriptlang.org/) [![Bun](https://img.shields.io/badge/Bun-v1.4.4-blueviolet.svg?style=flat-square)](https://bun.sh/)

[![Install in Claude Desktop](https://img.shields.io/badge/Install_in-Claude_Desktop-D97757?style=for-the-badge&logo=anthropic&logoColor=white)](https://github.com/cyanheads/bank-of-japan-mcp-server/releases/latest/download/bank-of-japan-mcp-server.mcpb) [![Install in Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en/install-mcp?name=bank-of-japan-mcp-server&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBjeWFuaGVhZHMvYmFuay1vZi1qYXBhbi1tY3Atc2VydmVyIl19) [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_Server-0098FF?style=for-the-badge&logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect?url=vscode:mcp/install?%7B%22name%22%3A%22bank-of-japan-mcp-server%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40cyanheads%2Fbank-of-japan-mcp-server%22%5D%7D)

[![Framework](https://img.shields.io/badge/Built%20on-@cyanheads/mcp--ts--core-67E8F9?style=flat-square)](https://www.npmjs.com/package/@cyanheads/mcp-ts-core)

</div>

## Overview

Search series metadata in English or Japanese across the Bank of Japan's 50 statistical databases. Retrieve observations in their published frequencies, filter Tankan surveys by industry and firm size, or look up realized overnight call rates and basic discount and loan rate changes. No API key required.

### Tools

| Tool | Description |
|:---|:---|
| `boj_search_series` | Find series by text, code, database, or frequency |
| `boj_get_series_observations` | Fetch observations by series code or database branch |
| `boj_get_tankan` | Retrieve Tankan observations by survey dimension |
| `boj_get_policy_rates` | Get realized call rates and basic discount and loan rate history |
| `boj_list_reference` | Browse databases, layers, period formats, Tankan codes, rate codes, coverage, and attribution |
| `boj_dataframe_describe` | Inspect staged tables, columns, and series metadata |
| `boj_dataframe_query` | Run read-only SQL on staged tables |
| `boj_dataframe_drop` | Delete one staged table. Opt-in via `BOJ_DATAFRAME_DROP_ENABLED=true` |

## Capability reference

### `boj_search_series` <sub>tool</sub>

- Pass `query` (literal words or a series code), `db`, and/or `frequency`. Set `active_only: false` to include discontinued series. Page with `limit` (default 25, cap 100) and `next_cursor`.
- Global result pages omit Tankan (`CO`) and report `excluded_co_matches` when available. Set `db: "CO"` for Tankan catalog matches.
- A cold catalog may return `catalog_loading`. Repeat the query after loading progresses. A stale result identifies the databases served from older catalog data.

### `boj_get_series_observations` <sub>tool</sub>

- Pass `codes` using qualified IDs from search, for example `{"codes":["IR01'MADR1Z@D"],"start_date":"2024-01","limit":10}` for the basic discount and loan rate. Or pass a `branch` with `db`, `layer`, and `frequency` from the layer reference. A code request resolves up to 250 unique identifiers and reports additional ones in `unprocessed_codes`.
- `start_date` and `end_date` are inclusive. Accepts calendar dates, months, quarters, halves, or years. Returned periods retain the series' native frequency and calendar convention.
- `series_limit` counts series per roster page (default 1, cap 250). `limit` counts inline observations per series (default 25, cap 1,000). Use `include_nulls: true` for dated nulls inline.
- If temporary observation storage reaches capacity, start without a cursor and narrow the date range or reduce `series_limit`. For contention with other active windows, retry after they expire.
- On `collecting`, resend the original request with the returned `cursor`. When ready, `next_cursor` visits earlier observations on the same page and `next_selection_cursor` moves to the next roster page. Pass either as `cursor` with the original filters and limits. Restart the original call if its cursor expires or the source revision changes.
- When a response includes `staged`, its table contains the complete roster-page window, including dated nulls. Carry the returned `canvas_id` to the next roster page to stage another table on the same canvas.

### `boj_get_tankan` <sub>tool</sub>

- `{}` requests the business conditions DI for large manufacturers and nonmanufacturers, actual and forecast. Browse `tankan_codes` to select `item`, `industries`, `sizes`, `horizons`, `series_type`, `frequency`, `aggregation`, or `detail_item`.
- Observation windows and continuations work as above, with `series_limit` default 4 and cap 25. The `unavailable` list reports unpublished combinations and their available frequencies.

### `boj_get_policy_rates` <sub>tool</sub>

- Returns the latest daily overnight call-rate average, high and low, the latest monthly average, and the latest basic discount and loan rate.
- The basic rate's effective-date changes are derived from the published series and sorted newest first. Page through changes with `limit` (default 25, cap 100) and `next_cursor` passed as `cursor`.

### `boj_list_reference` <sub>tool</sub>

- For example, call with `{"topic":"layers","db":"IR01"}` to browse the basic discount and loan rate database hierarchy. Use `topic: "tankan_codes"` with an optional `dimension` for the codebook.
- Other topics are `databases`, `frequencies`, `policy_rates`, `coverage_gaps`, and `attribution`. Page with `limit` (default 25, cap 100) and `next_cursor` passed as `cursor`.

### `boj_dataframe_describe` <sub>tool</sub>

- Pass `canvas_id` from a staged result. The response includes table schema, row count, expiration, and each series' recorded and staged date ranges.
- Continue a table's series manifest with its `table_name`, cursor, and the same `limit` (default 25, cap 100).

### `boj_dataframe_query` <sub>tool</sub>

- Pass `canvas_id` and a single read-only SELECT, optionally with CTEs. Use the names from `boj_dataframe_describe`. For stable paging, add an `ORDER BY` that uniquely orders the rows.
- SQL is limited to 65,536 UTF-16 code units. The 30-second query deadline includes time waiting for the canvas. DuckDB may need to finish preparing a statement before it can honor cancellation.
- `limit` defaults to 25 rows and caps at 1,000. Pass `next_cursor` as `cursor` with the same canvas, SQL, and limit.

### `boj_dataframe_drop` <sub>tool</sub>

- Pass `canvas_id` and `table_name` to remove a staged table. Requires DuckDB and `BOJ_DATAFRAME_DROP_ENABLED=true`.

## Features

- The catalog is cached locally and populated on demand. Start with a database-scoped search for a faster cold lookup. Allow roughly 1 GB of disk space for all 50 databases. Requests to BOJ are paced, so loading the full catalog takes time.
- Native installs default to DuckDB for SQL. The portable Claude Desktop bundle uses inline observation continuation and a portable catalog cache.
- For Japanese Government Bond yields, use the [Ministry of Finance's JGB yield series](https://www.mof.go.jp/english/policy/jgbs/reference/interest_rate/index.htm). For announced policy targets, decisions, and meeting records, use the [BOJ Monetary Policy Meetings archive](https://www.boj.or.jp/en/mopo/mpmsche_minu/index.htm).

## Getting started

For Claude Code, using Node.js 24 or later:

```sh
claude mcp add bank-of-japan-mcp-server -- npx -y @cyanheads/bank-of-japan-mcp-server
```

For another stdio client, add this to its MCP config:

```json
{
  "mcpServers": {
    "bank-of-japan-mcp-server": {
      "command": "npx",
      "args": ["-y", "@cyanheads/bank-of-japan-mcp-server"]
    }
  }
}
```

With Bun 1.4.4 or later, use `"command": "bunx"` and `"args": ["--bun", "@cyanheads/bank-of-japan-mcp-server"]`. Or download and open the `.mcpb` using the Claude Desktop badge above.

## Configuration

| Variable | Description | Default |
|:---|:---|:---|
| `BOJ_CATALOG_DIR` | Writable directory for the persisted series catalog | `$XDG_CACHE_HOME/bank-of-japan-mcp-server` or `~/.cache/bank-of-japan-mcp-server` |
| `BOJ_DATAFRAME_DROP_ENABLED` | Set `true` to expose the staged-table drop tool | `false` |
| `CANVAS_PROVIDER_TYPE` | Canvas engine. Set `none` to disable SQL staging | `duckdb`, fixed to `none` in the Desktop bundle |
| `MCP_TRANSPORT_TYPE` | `stdio` or `http` | `stdio` |
| `MCP_HTTP_HOST` / `MCP_HTTP_PORT` / `MCP_HTTP_ENDPOINT_PATH` | Local HTTP address, port, and route | `127.0.0.1` / `3010` / `/mcp` |
| `MCP_PUBLIC_URL` | Public origin for a TLS-terminating proxy | Unset |
| `MCP_AUTH_MODE` | `none`, `jwt`, or `oauth` | `none` |
| `MCP_LOG_LEVEL` | Minimum log level | `info` |

See [`.env.example`](./.env.example) for framework overrides. Claude Code prompts for the two BOJ options when enabling the plugin. For the Codex plugin, set the BOJ variables in the environment that launches Codex.

## Running the server

### Local development

```sh
git clone https://github.com/cyanheads/bank-of-japan-mcp-server.git
cd bank-of-japan-mcp-server
bun install
bun run rebuild
bun run start:http
```

Connect your client to `http://localhost:3010/mcp`, or use `bun run start:stdio`. To preload the catalog, use its CLI after installing the npm package globally:

```sh
npm install -g @cyanheads/bank-of-japan-mcp-server
boj-catalog init
boj-catalog verify
boj-catalog refresh
```

`init` loads missing or stale databases, `verify` checks coverage on disk, and `refresh` forces a reload. Use the same `BOJ_CATALOG_DIR` as the server. From a source build, use `bun run mirror:init`, `bun run mirror:verify`, and `bun run mirror:refresh`. The HTTP server schedules a refresh for 00:01 UTC each day.

### Docker

```sh
docker run --rm -p 127.0.0.1:3010:3010 \
  -v boj-catalog:/usr/src/app/.mirror \
  ghcr.io/cyanheads/bank-of-japan-mcp-server:latest
```

The image runs HTTP on port 3010 and persists the catalog in the mounted volume. To run it over stdio, use `docker run -i --rm -e MCP_TRANSPORT_TYPE=stdio` followed by the image name.

## Project structure

| Path | Purpose |
|:---|:---|
| `src/index.ts` | Server registration, canvas setup, HTTP catalog refresh, and shutdown |
| `src/catalog-cli.ts` | Catalog initialization, refresh, and verification |
| `src/mcp-server/tools/definitions/` | MCP tool input, output, and error contracts |
| `src/services/` | BOJ transport, catalog backends, observation traversal, rate and Tankan lookups, and canvas |
| `tests/` | Unit and integration tests |

## Development guide

See [developer rules](./AGENTS.md), the [design notes](./docs/design.md), and the [repository tree](./docs/tree.md).

## Contributing

Run `bun run devcheck` and `bun run test` before submitting changes.

## License and data attribution

The server code is licensed under [Apache 2.0](./LICENSE). The Bank of Japan's terms govern reuse of its data. The site notice requires source credit when copying data and prior permission for commercial reproduction, designated materials, and images. See the [Time-Series Data Search site notice](https://www.stat-search.boj.or.jp/info/notice_en.html), [API notice](https://www.stat-search.boj.or.jp/info/api_notice_en.pdf), [API manual](https://www.stat-search.boj.or.jp/info/api_manual_en.pdf), and [Tankan codebook](https://www.stat-search.boj.or.jp/info/tankan_code_en.html).

> This service uses the API provided by the "Bank of Japan Time-Series Data Search." The Bank of Japan does not guarantee the content of the service.