SORACOM MCP ServerをAmazon Q Developer CLIから利用する

先月に行われたSORACOM Discovery 2025で、生成AIからSORACOMサービスを呼び出せるSORACOM MCP Serverが発表されました。

SORACOM MCP Server で SORACOM API を使いこなそう!- SORACOM公式ブログ
こんにちは、ソラコムのエンジニアリングマネージャー兼バックエンドエンジニアの中西(ニックネーム: kaz)です。 皆さんは、SORACOM API
現在はEarly Accessフェーズにつき、呼び出せるAPIは限定的とのことです

今回はこのSORACOM MCP Serverをお手軽に利用する方法として、Amazon Q Developer CLIから利用する方法を紹介したいと思います。

はじめに

MCPについて

生成AI技術の進化により、私たちのタスクは以前と比較し格段に効率的になりました。

但し生成AIのモデル(LLM)がユーザーのリクエストに対して適切に回答するためには、LLMにて事前に学習済の情報だけではなく、ユーザー固有の情報や最新情報を入力した上でモデルに処理させる必要があります。

このようにユーザー固有の情報や最新情報を入力するためには、AIのアプリケーションに「ツール」として情報の取得機能を実装する必要がありますが、MCP登場前の世界では各々個別に開発がされており共通仕様ではなかったため、ツール間/ユーザー間での共有が困難な状況となっておりました。

そこで、著名なLLMであるClaudeシリーズを提供するAnthropic社にて2024年11月に標準規格として発表されたのがMCP(Model Contect Protocol)となり、現在のデファクトスタンダードとなっています。

Amazon Q Developer CLIについて

Amazon Q Developerは、AWS が提供する生成AIアシスタントで、コード生成やインフラ構築、デバッグまで自然言語による指示が可能となるツールです。

これらの機能を、エディタと必要とせずターミナル上で対話形式にて実行可能としたのが Amazon Q Developer CLIとなり、2025年4月から日本語による指示に対応しています。

主な機能としては以下のようなものがあります。

  • チャット機能
    ターミナル内で対話形式でAWSアカウントの操作、分析等が行える。
  • 自然言語からのコマンド生成
    日本語指示から対応するコマンドを生成し実行できる
  • CLI補完機能
    コマンド入力中に生成AIにてサブコマンド、オプション、ファイル名など続きを提案する

料金は月間50リクエストまでであればFree Tierの範囲で無料です。

料金
Amazon Q Developer 向けの料金オプションをご確認ください。

そして、日本語対応と同じく2025年4月からAmazon Q Developer CLIのMCP対応がされています。

より豊かなコンテキストのための Model Context Protocol (MCP) による Amazon Q Developer CLI の拡張 | Amazon Web Services
本日、Amazon Q Developer はコマンドラインインターフェイス(CLI)での Model Context Protocol (MCP) サポートを発表しました。開発者は MCP サポートを使用して外部データソースを Amazo...

上述の通りMCP対応で外部から情報を取得できるようになったので格段に利用の幅が広がりました。
今回は発表さえれたSORACOM MCP Serverと接続し、Amazon Q Developer CLIからSORACOMアカウントの操作を行ってみたいと思います。

 

インストール・設定

Amazon Q Developer CLIはコマンドラインにつき、クライアントOSとしては各種LinuxディストリビューションとmacOSに対応しています。
今回はmacOS(Sequoia バージョン15.6)上で設定を行いました。

Amazon Q Developer CLIのインストール

Amazon Q Developer CLIのインストール方法は以下URLに記載があります。

コマンドライン用の Amazon Q をインストールする - Amazon Q Developer
macOS、Linux などのさまざまなオペレーティングシステムにコマンドライン用の Amazon Q Developer をインストールする方法について説明します。

今回はmacOSですので、記載の手順の通りインストールしました。

  1. .dmgファイルをダウンロード
  2. dmgファイルをダブルクリックし起動、アプリケーションフォルダにコピー
  3. Amazon Q GUIアプリケーションを起動
  4. シェル統合の有効化
  5. AWS Builder IDログイン
  6. シェル統合のインストール

インストール・設定が正しく完了したかどうかは、q doctorコマンドで確認できます。

[tomotaka ~]$ q doctor

✔ Everything looks good!

 

SORACOM MCP Server利用設定

Node.jsのインストール

SORACOM MCP Serverのコードは以下のURLで公開されていますが、Node.jsのv22以降が必要です。

@soracom-labs/soracom-mcp-server
MCP server for SORACOM API. Latest version: 0.1.0, last published: a month ago. Start using @soracom-labs/soracom-mcp-se...

以下URLからダウンロードしインストールします。

Node.js — Node.js®をダウンロードする
Node.js® is a free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web ...
SORACOM認証キーの取得

SORACOM MCP Serverの呼び出しには以下の2方式があります。

  • LLMのMCP設定ファイルから認証キーを利用
  • SORACOM CLI経由

今回は認証キーを利用した方法で進めます。

なお以下手順ではルートユーザーで認証キーを発行しています。
SAMユーザーでも権限の範囲内で利用可能なものと思いますが、未検証です。


SORACOMコンソールにログインし、右上のユーザー情報からセキュリティを選択します。

左側の認証キーメニューから、「認証キーを生成」をクリックします。

認証キーが生成されました。
IDとシークレットをメモしておきます。

Amazon Q Developer CLI の MCP設定

Amazon Q Developer CLIのMCP連携設定は以下の設定ファイルで行うことができます。

  • ~/.aws/amazonq/mcp.json :ログイン中ユーザーのすべてのプロジェクトで適用される
  • ワークスペース内の .amazonq/mcp.json :対象のワークスペースにのみ適用される

今回は ~/.aws/amazonq/mcp.json に以下のようなSORACOM認証キーのID、シークレットを記載した設定ファイルを設置しました。

{
  "mcpServers": 
	{"soracom": {
      "command": "npx",
      "args": ["@soracom-labs/soracom-mcp-server"],
      "env": {
        "SORACOM_AUTH_KEY_ID": "keyId-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
        "SORACOM_AUTH_KEY": "secret-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "SORACOM_COVERAGE_TYPE": "jp"
      }
    }
  }
}

設定が正しくされているかどうかは、q mcp list コマンドで確認できます。

[tomotaka ~]$ q mcp list

 default:

  q_cli_default
    • soracom      npx

 

利用例

さて、設定も終わったので利用してみます。

q chat (qchat) コマンドで起動します。
起動時にMCP Serverとの連携が初期化が走っていることが確認できます。

以下の例ではタイムアウトしており設定の調整が必要そうですが、動作は正常なようです。

今回は過去1年分の利用料金をグラフ化してみたいと思います。

なお、都度MCPサーバの呼び出し内容を確認する仕様のようで、毎度「y」を押して許可するようにします。

> SORACOMの過去1年の料金をグラフ化して

> SORACOMの過去1年の料金データを取得してグラフ化しますね。まず利用可能な請求履歴を確認してから、データを取得してグラフを作成します。

️  Using tool: Billing_getBillingHistory from mcp server soracom
 ⋮ 
 ● Running Billing_getBillingHistory with the param:
 ⋮  {
 ⋮    "name": "Billing_getBillingHistory",
 ⋮    "arguments": {
 ⋮      "coverage": "jp"
 ⋮    }
 ⋮  }

Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:
> y

 ⋮ 
 ● Completed in 0.961s

Amazon Qから?、今月の暫定料金も取得するよう提案がありましたので許可します。

> 過去1年分(2024年8月〜2025年7月)の請求データを取得できました。現在の月(2025年8月)の暫定料金も確認してみましょう。

️  Using tool: Billing_getLatestBilling from mcp server soracom
 ⋮ 
 ● Running Billing_getLatestBilling with the param:
 ⋮  {
 ⋮    "name": "Billing_getLatestBilling",
 ⋮    "arguments": {
 ⋮      "coverage": "jp"
 ⋮    }
 ⋮  }

Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:
> y

 ⋮ 
 ● Completed in 0.115s

今回はCLIから呼び出しているため、LLMのチャットのように画像は表示できません。
そのため、画像ファイルを作成するPythonスクリプトを作成する提案がありました。

> それでは、過去1年分の料金データをグラフ化するPythonスクリプトを作成します。

️  Using tool: fs_write
 ⋮ 
 ● Path: /Users/tomotaka/soracom_billing_chart.py

+      1: #!/usr/bin/env python3
+      2: # -*- coding: utf-8 -*-
+      3: """
+      4: SORACOM 過去1年の料金グラフ化スクリプト
+      5: """
+      6: 
+      7: import matplotlib.pyplot as plt
+      8: import matplotlib.dates as mdates
+      9: from datetime import datetime
+     10: import pandas as pd
+     11: import numpy as np
+     12: 
+     13: # 日本語フォント設定
+     14: plt.rcParams['font.family'] = ['Hiragino Sans', 'Yu Gothic', 'Meiryo', 'Takao', 'IPAexGothic', 'IPAPGothic', 'VL PGothic', 'Noto Sans CJK JP']

(略)

 ↳ Purpose: SORACOMの過去1年の料金データをグラフ化するPythonスクリプト

Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:
> y

Creating: /Users/tomotaka/soracom_billing_chart.py
 ⋮ 
 ● Completed in 0.4s

スクリプトの実行にあたって必要なライブラリのインストールがされているか確認するよう提案がありました。

> 必要なPythonライブラリがインストールされているか確認して、スクリプトを実行します。

️  Using tool: execute_bash
 ⋮ 
 ● I will run the following shell command: 
python3 -c "import matplotlib, pandas, numpy" 2>/dev/null && echo "必要なライブラリは既にインストールされています" || echo "ライブラリのインストールが必要です"
 ⋮ 
 ↳ Purpose: 必要なPythonライブラリの確認とインストール

Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:
> y

ライブラリのインストールが必要です
 ⋮ 
 ● Completed in 0.840s

ライブラリのインストールが必要でしたので、提案に任せてインストールします。

> 必要なライブラリをインストールします。

️  Using tool: execute_bash
 ⋮ 
 ● I will run the following shell command: 
pip3 install matplotlib pandas numpy
 ⋮ 
 ↳ Purpose: 必要なPythonライブラリのインストール

Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:
> y

Collecting matplotlib
  Downloading matplotlib-3.10.5-cp310-cp310-macosx_11_0_arm64.whl (8.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.1/8.1 MB 12.5 MB/s eta 0:00:00
Collecting pandas
  Downloading pandas-2.3.1-cp310-cp310-macosx_11_0_arm64.whl (10.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.8/10.8 MB 11.9 MB/s eta 0:00:00
Collecting numpy
  Downloading numpy-2.2.6-cp310-cp310-macosx_14_0_arm64.whl (5.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.3/5.3 MB 11.5 MB/s eta 0:00:00
Collecting python-dateutil>=2.7
  Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 229.9/229.9 KB 10.4 MB/s eta 0:00:00
Collecting fonttools>=4.22.0
  Downloading fonttools-4.59.1-cp310-cp310-macosx_10_9_universal2.whl (2.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.8/2.8 MB 11.5 MB/s eta 0:00:00
Collecting packaging>=20.0
  Downloading packaging-25.0-py3-none-any.whl (66 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 66.5/66.5 KB 5.9 MB/s eta 0:00:00
Collecting cycler>=0.10
  Downloading cycler-0.12.1-py3-none-any.whl (8.3 kB)
Collecting contourpy>=1.0.1
  Downloading contourpy-1.3.2-cp310-cp310-macosx_11_0_arm64.whl (253 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 253.4/253.4 KB 11.0 MB/s eta 0:00:00
Collecting kiwisolver>=1.3.1
  Downloading kiwisolver-1.4.9-cp310-cp310-macosx_11_0_arm64.whl (65 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.3/65.3 KB 5.6 MB/s eta 0:00:00
Collecting pyparsing>=2.3.1
  Downloading pyparsing-3.2.3-py3-none-any.whl (111 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 111.1/111.1 KB 8.4 MB/s eta 0:00:00
Collecting pillow>=8
  Downloading pillow-11.3.0-cp310-cp310-macosx_11_0_arm64.whl (4.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.7/4.7 MB 13.4 MB/s eta 0:00:00
Collecting tzdata>=2022.7
  Downloading tzdata-2025.2-py2.py3-none-any.whl (347 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 347.8/347.8 KB 11.5 MB/s eta 0:00:00
Collecting pytz>=2020.1
  Downloading pytz-2025.2-py2.py3-none-any.whl (509 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 509.2/509.2 KB 12.2 MB/s eta 0:00:00
Collecting six>=1.5
  Downloading six-1.17.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: pytz, tzdata, six, pyparsing, pillow, packaging, numpy, kiwisolver, fonttools, cycler, python-dateutil, contourpy, pandas, matplotlib
Successfully installed contourpy-1.3.2 cycler-0.12.1 fonttools-4.59.1 kiwisolver-1.4.9 matplotlib-3.10.5 numpy-2.2.6 packaging-25.0 pandas-2.3.1 pillow-11.3.0 pyparsing-3.2.3 python-dateutil-2.9.0.post0 pytz-2025.2 six-1.17.0 tzdata-2025.2
WARNING: You are using pip version 22.0.4; however, version 25.2 is available.
You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10 -m pip install --upgrade pip' command.

 ⋮ 
 ● Completed in 26.852s

環境が整いましたので、スクリプトの実行を試してみます。

> ライブラリのインストールが完了しました。スクリプトを実行してグラフを作成します。

️  Using tool: execute_bash
 ⋮ 
 ● I will run the following shell command: 
cd /Users/tomotaka && python3 soracom_billing_chart.py
 ⋮ 
 ↳ Purpose: SORACOMの料金グラフ作成スクリプトを実行

Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:
> y

Matplotlib is building the font cache; this may take a moment.
findfont: Font family 'Yu Gothic' not found.
findfont: Font family 'Meiryo' not found.
findfont: Font family 'Takao' not found.
findfont: Font family 'IPAexGothic' not found.
findfont: Font family 'IPAPGothic' not found.

(略)

Traceback (most recent call last):
  File "/Users/tomotaka/soracom_billing_chart.py", line 102, in 
    plt.savefig('/Users/tomotaka/soracom_billing_chart.pdf', bbox_inches='tight')
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/pyplot.py", line 1251, in savefig
    res = fig.savefig(*args, **kwargs)  # type: ignore[func-returns-value]
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/figure.py", line 3490, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 2186, in print_figure
    result = print_method(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 2042, in 
    print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/backends/backend_pdf.py", line 2786, in print_pdf
    self.figure.draw(renderer)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/artist.py", line 94, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/artist.py", line 71, in draw_wrapper
    return draw(artist, renderer)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/figure.py", line 3257, in draw
    mimage._draw_list_compositing_images(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/image.py", line 134, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/artist.py", line 71, in draw_wrapper
    return draw(artist, renderer)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 3226, in draw
    mimage._draw_list_compositing_images(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/image.py", line 134, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/artist.py", line 71, in draw_wrapper
    return draw(artist, renderer)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/axis.py", line 1412, in draw
    self.label.draw(renderer)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/artist.py", line 71, in draw_wrapper
    return draw(artist, renderer)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/text.py", line 808, in draw
    textrenderer.draw_text(gc, x, y, clean_line,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/backends/backend_pdf.py", line 2422, in draw_text
    self._draw_xobject_glyph(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/backends/backend_pdf.py", line 2434, in _draw_xobject_glyph
    Name(name), Op.use_xobject,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/backends/backend_pdf.py", line 423, in __init__
    self.name = name.translate(self._hexify).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-13: ordinal not in range(128)

 ⋮ 
 ● Completed in 18.938s

フォントがmacOSに対応していなかったようです。
提案に基づきPythonコードの修正を受け入れます。

> 日本語フォントの問題とPDF出力でのエラーが発生しました。macOSで利用可能なフォントを使用し、PDF出力を削除した修正版を作成します。

️  Using tool: fs_write
 ⋮ 
 ● Path: /Users/tomotaka/soracom_billing_chart_fixed.py

+      1: #!/usr/bin/env python3
+      2: # -*- coding: utf-8 -*-
+      3: """
+      4: SORACOM 過去1年の料金グラフ化スクリプト(macOS対応版)
+      5: """
+      6: 
+      7: import matplotlib.pyplot as plt
+      8: import matplotlib.dates as mdates
+      9: from datetime import datetime
+     10: import pandas as pd
+     11: import numpy as np
+     12: 
+     13: # macOSで利用可能なフォント設定
+     14: plt.rcParams['font.family'] = ['Arial Unicode MS', 'DejaVu Sans']
+     15: 
+     16: # 過去1年分のデータ(2024年8月〜2025年7月)+ 2025年8月の暫定料金
+     17: billing_data = [
+     18:     {"yearMonth": "202408", "amount": 1936},
+     19:     {"yearMonth": "202409", "amount": 1909},
+     20:     {"yearMonth": "202410", "amount": 1837},
+     21:     {"yearMonth": "202411", "amount": 2261},
+     22:     {"yearMonth": "202412", "amount": 0},      # クーポン適用で0円
+     23:     {"yearMonth": "202501", "amount": 0},      # クーポン適用で0円
+     24:     {"yearMonth": "202502", "amount": 732},    # 一部クーポン適用
+     25:     {"yearMonth": "202503", "amount": 973},
+     26:     {"yearMonth": "202504", "amount": 963},
+     27:     {"yearMonth": "202505", "amount": 973},
+     28:     {"yearMonth": "202506", "amount": 2695},
+     29:     {"yearMonth": "202507", "amount": 1133},
+     30:     {"yearMonth": "202508", "amount": 822},    # 暫定料金(8月16日時点)
+     31: ]
+     32: 
+     33: # データを整理
+     34: dates = []
+     35: amounts = []
+     36: labels = []
+     37: 
+     38: for data in billing_data:
+     39:     year = int(data["yearMonth"][:4])
+     40:     month = int(data["yearMonth"][4:])
+     41:     date = datetime(year, month, 1)
+     42:     dates.append(date)
+     43:     amounts.append(data["amount"])
+     44:     labels.append(f"{year}/{month:02d}")
+     45: 
+     46: # DataFrameを作成
+     47: df = pd.DataFrame({
+     48:     'date': dates,
+     49:     'amount': amounts,
+     50:     'label': labels
+     51: })
+     52: 
+     53: # グラフを作成
+     54: fig, ax = plt.subplots(figsize=(14, 8))
+     55: 
+     56: # 棒グラフを作成
+     57: bars = ax.bar(df['date'], df['amount'], width=25, alpha=0.8, color='steelblue', edgecolor='navy', linewidth=1)
+     58: 
+     59: # 2025年8月(暫定料金)を異なる色で表示
+     60: bars[-1].set_color('orange')
+     61: bars[-1].set_alpha(0.7)
+     62: 
+     63: # 各棒の上に金額を表示
+     64: for i, (date, amount) in enumerate(zip(df['date'], df['amount'])):
+     65:     if i == len(df) - 1:  # 最後の月(暫定料金)
+     66:         ax.text(date, amount + 50, f'¥{amount:,}\n(Provisional)', ha='center', va='bottom', fontsize=9, color='darkorange', weight='bold')
+     67:     else:
+     68:         ax.text(date, amount + 50, f'¥{amount:,}', ha='center', va='bottom', fontsize=9)
+     69: 
+     70: # グラフの設定
+     71: ax.set_title('SORACOM Monthly Billing Trend (Past 12 Months)', fontsize=16, fontweight='bold', pad=20)
+     72: ax.set_xlabel('Year/Month', fontsize=12)
+     73: ax.set_ylabel('Amount (JPY)', fontsize=12)
+     74: 
+     75: # Y軸の範囲を設定
+     76: ax.set_ylim(0, max(amounts) * 1.2)
+     77: 
+     78: # X軸の日付フォーマット
+     79: ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y/%m'))
+     80: ax.xaxis.set_major_locator(mdates.MonthLocator())
+     81: 
+     82: # X軸のラベルを回転
+     83: plt.xticks(rotation=45)
+     84: 
+     85: # グリッドを追加
+     86: ax.grid(True, alpha=0.3, linestyle='--')
+     87: 
+     88: # 統計情報を追加
+     89: total_amount = sum(amounts[:-1])  # 暫定料金を除く
+     90: avg_amount = total_amount / (len(amounts) - 1)
+     91: 
+     92: # 統計情報をテキストボックスで表示
+     93: stats_text = f'Past 12 months total: ¥{total_amount:,}\nMonthly average: ¥{avg_amount:,.0f}'
+     94: ax.text(0.02, 0.98, stats_text, transform=ax.transAxes, fontsize=10,
+     95:         verticalalignment='top', bbox=dict(boxstyle='round', facecolor='lightgray', alpha=0.8))
+     96: 
+     97: # レイアウトを調整
+     98: plt.tight_layout()
+     99: 
+    100: # グラフを保存(PNG形式のみ)
+    101: plt.savefig('/Users/tomotaka/soracom_billing_chart.png', dpi=300, bbox_inches='tight')
+    102: 
+    103: # グラフを表示
+    104: plt.show()
+    105: 
+    106: print("Graph has been created:")
+    107: print("- PNG format: /Users/tomotaka/soracom_billing_chart.png")
+    108: print(f"\nStatistics:")
+    109: print(f"Past 12 months total: ¥{total_amount:,}")
+    110: print(f"Monthly average: ¥{avg_amount:,.0f}")
+    111: print(f"Highest amount: ¥{max(amounts[:-1]):,} ({labels[amounts[:-1].index(max(amounts[:-1]))]})")
+    112: print(f"Lowest amount: ¥{min(amounts[:-1]):,} ({labels[amounts[:-1].index(min(amounts[:-1]))]})")
+    113: print(f"August 2025 provisional: ¥{amounts[-1]:,}")
+    114: 
+    115: # 月別データの詳細表示
+    116: print(f"\nMonthly breakdown:")
+    117: for i, (label, amount) in enumerate(zip(labels, amounts)):
+    118:     if i == len(labels) - 1:
+    119:         print(f"{label}: ¥{amount:,} (Provisional)")
+    120:     else:
+    121:         print(f"{label}: ¥{amount:,}")

 ⋮ 
 ↳ Purpose: macOS対応版のSORACOM料金グラフ作成スクリプト

Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:
> y

Creating: /Users/tomotaka/soracom_billing_chart_fixed.py

 ⋮ 
 ● Completed in 0.3s

生成された修正版のスクリプトを実行します。

> 修正版のスクリプトを実行します。

️  Using tool: execute_bash
 ⋮ 
 ● I will run the following shell command: 
cd /Users/tomotaka && python3 soracom_billing_chart_fixed.py
 ⋮ 
 ↳ Purpose: 修正版のSORACOM料金グラフ作成スクリプトを実行

Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:
> y

すると以下のような画像が表示されました。素晴らしい。

作成したグラフの分析までしてくれました。

> グラフが正常に作成されました!作成されたファイルを確認してみましょう。

️  Using tool: execute_bash (trusted)
 ⋮ 
 ● I will run the following shell command: 
ls -la /Users/tomotaka/soracom_billing_chart.png
 ⋮ 
 ↳ Purpose: 作成されたグラフファイルの確認

-rw-r--r--@ 1 tomotaka  staff  243255  8 16 17:06 /Users/tomotaka/soracom_billing_chart.png

 ⋮ 
 ● Completed in 0.34s

> SORACOMの過去1年の料金データをグラフ化しました!

## 作成されたグラフの概要

ファイル: /Users/tomotaka/soracom_billing_chart.png

## 主要な統計情報

• **過去12ヶ月の合計料金**: ¥15,412
• **月平均料金**: ¥1,284
• **最高料金**: ¥2,695(2025年6月)
• **最低料金**: ¥0(2024年12月、2025年1月)
• **2025年8月暫定料金**: ¥822

## 料金推移の特徴

1. 2024年12月〜2025年1月: クーポン適用により料金が0円
2. 2025年6月: 最高額の¥2,695を記録
3. 2025年2月: 一部クーポン適用で¥732に減額
4. 全体的な傾向: 月額1,000円前後で推移

グラフには以下の要素が含まれています:
• 月別の棒グラフ(青色)
• 2025年8月の暫定料金(オレンジ色で区別)
• 各棒の上に具体的な金額を表示
• 統計情報のサマリー
• グリッド線で読みやすさを向上

このグラフを使って、SORACOMの利用料金の推移を視覚的に把握できます。

 

まとめ

Amazon Q Developer CLIとSORACOM MCP Serverを組み合わせて利用することで、お手軽にSORACOMアカウントの管理を行うことができることがお解り頂けたかと思います。

現在、色々なサービスにおいてMCP Serverの提供が始まっていますので、他のMCP Serverとの組み合わせでも可能性を探りたいと思います。

コメント