# Japan Fuel Price MCP — METI Weekly Gasoline/Diesel/Kerosene (`fruitful_quintessence/japan-fuel-price-mcp`) Actor

MCP server: Japan official weekly retail fuel prices from METI Agency for Natural Resources and Energy XLSX. Latest price + WoW for 47 prefectures, history, cheapest-prefecture ranking, nationwide inflation trend. Gasoline, diesel, kerosene.

- **URL**: https://apify.com/fruitful\_quintessence/japan-fuel-price-mcp.md
- **Developed by:** [atushi ino](https://apify.com/fruitful_quintessence) (community)
- **Categories:** MCP servers
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 fuel-price-latests

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Japan Fuel Price MCP — METI Weekly Gasoline / Diesel / Kerosene

MCPサーバー: 日本のガソリン・軽油・灯油の週次小売価格を、資源エネルギー庁（METI）公式統計XLSXからAIエージェントに提供します。

- データソース: [資源エネルギー庁 給油所小売価格調査](https://www.enecho.meti.go.jp/statistics/petroleum_and_lpgas/pl007/) 公式XLSX（毎週更新、1990年〜の全国・都道府県別平均現金価格）
- 利用規約: 政府標準利用規約2.0（出典明示で商用利用可）
- 単位: ガソリン・軽油 = 円/L、灯油 = 円/18L（消費税込み）

### Tools

| Tool | 説明 |
|------|------|
| `get_latest_fuel_price(prefecture, product)` | 指定都道府県（または全国）の最新週平均価格 + 前週比 + ガソリン税内訳 |
| `get_fuel_price_history(prefecture, product, weeks)` | 週次履歴（都道府県は直近260週、全国は1990年〜）+ min/max/avg |
| `cheapest_prefectures(product, limit)` | 47都道府県 最安〜最高値ランキング |
| `national_fuel_trend(products, weeks)` | 全国平均の複数製品トレンド（インフレ/マクロ指標用） |
| `list_fuel_regions()` | 照会可能な地域（漢字+ローマ字）・製品・単位のリスト |

`prefecture` は漢字・ローマ字・「都/府/県」付きのいずれでも可（東京 / tokyo / 東京都）。北海道・沖縄はMETI調査の局単位データを都道府県として提供。

### 動作

1. 初回呼び出しで最新 `YYMMDDs5.xlsx` を取得（ブラウザUA必須）、openpyxlでパースしJSONキャッシュ化
2. 以後6時間はキャッシュから即答、TTL切れで新週ファイルをチェック
3. METIのレート制限/障害時はビルド時同梱のシードキャッシュ（`data/fuel_prices.json`）にフォールバック — ツールが500になることはない

### MCP接続

Apify Standby モード（streamable HTTP）:

```
https://api.apify.com/v2/acts/<ACTOR_ID>/mcp
Authorization: Bearer <APIFY_TOKEN>
```

### ローカル開発

```bash
pip install -r requirements.txt
python3 -m pytest tests/ -q          # 14 tests, network-stubbed, seed cache
PORT=3999 python3 -m src.main &      # shim経由でApify SDK不要
python3 tests/http_smoke.py http://localhost:3999/mcp
```

シード更新（週1回、木曜の公開後）:

```bash
python3 scripts/refresh_seed.py          # METIから取得して data/fuel_prices.json 再生成
python3 scripts/refresh_seed.py path/to/YYMMDDs5.xlsx   # 手元DL分から生成（レート制限回避）
git add data/fuel_prices.json && git commit -m "data: seed refresh" && git push
```

### Deploy

GitHub連携 Apify Actor（`usesStandbyMode`, `webServerMcpPath=/mcp`）。push後にビルドAPIを叩く:

```bash
curl -X POST "https://api.apify.com/v2/acts/<ACTOR_ID>/builds?version=0.1&tag=latest&token=$APIFY_TOKEN"
```

### 出典表記

> Source: Agency for Natural Resources and Energy (METI), Petroleum Products Price Survey. Government Standard Terms of Use 2.0.

# Actor input Schema

## Actor input object example

```json
{}
```

# Actor output Schema

## `mcp_endpoint` (type: `string`):

Streamable-HTTP MCP endpoint of this run's Standby container (append /mcp, Bearer Apify token required).

## `run_output` (type: `string`):

Console view of this run (MCP servers return results inline over the protocol, not via dataset).

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("fruitful_quintessence/japan-fuel-price-mcp").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("fruitful_quintessence/japan-fuel-price-mcp").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call fruitful_quintessence/japan-fuel-price-mcp --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,fruitful_quintessence/japan-fuel-price-mcp"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/RdCHlXHphoLsWnyhh/builds/1I2zwBu55WYW0hIm7/openapi.json
