Skip to main content
Glama
zaqdaisuki

mahjong-calculator

by zaqdaisuki

麻雀点数計算 MCP サーバー

Claude ProjectsやClaude Desktopから麻雀の点数計算ができるMCPサーバーです。

特徴

  • テキスト形式で牌姿を入力(例: 123m456p789s11z

  • 赤ドラ対応(0で表現、例: 50m = 赤5萬)

  • 点数、役、翻数、符を自動計算

  • Claude Desktopからツールとして直接呼び出し可能

  • stdio/SSE両方のトランスポートに対応

Related MCP server: musescore-mcp

MCPサーバーとは

MCP (Model Context Protocol) は、Claude DesktopとAIツール間の通信プロトコルです。MCPサーバーを作成することで、Claudeに新しい機能(ツール)を追加できます。

このプロジェクトでは、麻雀の点数計算をClaudeから呼び出せるようにしています。

トランスポート方式

MCPサーバーには2つの接続方式があります:

  • stdio(標準入出力): Claude Desktopがサーバープロセスを直接起動・管理(推奨)

  • SSE(Server-Sent Events): HTTPサーバーとして常駐し、Claude Desktopが接続

このプロジェクトでは、安定性と管理の容易さから stdio方式 を推奨しています。

セットアップ

1. 依存関係のインストール

uv sync

2. Claude Desktop での設定

設定ファイルの場所:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Linux/macOS(ネイティブ環境)の場合

{
  "mcpServers": {
    "mahjong-calculator": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/mahjong_calculator",
        "run",
        "python",
        "-m",
        "src.server"
      ]
    }
  }
}

注意: /absolute/path/to/mahjong_calculator の部分は、このプロジェクトの絶対パスに置き換えてください。

Windows + WSL環境の場合(推奨設定)

Windows上のClaude DesktopからWSL内のMCPサーバーを起動する場合:

{
  "mcpServers": {
    "mahjong-calculator": {
      "command": "wsl",
      "args": [
        "-e",
        "bash",
        "-c",
        "export PATH=$HOME/.local/bin:$PATH && cd /home/your-username/projects/mahjong_calculator && exec uv run python -m src.server"
      ]
    }
  }
}

重要:

  • /home/your-username/projects/mahjong_calculator をWSL内の実際のプロジェクトパスに置き換えてください

  • your-username をWSLのユーザー名に置き換えてください

  • この設定は、一行のコマンドとして実行されるため、確実に動作します

3. Claude Desktopを再起動

設定を反映させるため、Claude Desktopを完全に終了してから再起動してください。

使用方法

Claude DesktopやClaude Projectsで以下のように質問してください:

基本的な使い方

手牌: 234m345p456s6677z
和了牌: 7z
の点数を教えて

注意: 手牌(13枚)と和了牌(1枚)の合計14枚が正しい和了形(4面子1雀頭)である必要があります。

立直ツモの場合

手牌: 234m234p234s555z
和了牌: 5z
でツモ和了、立直ありの場合の点数を計算して

ドラありの場合

手牌: 234m456p678s3344s
和了牌: 5s
でロン和了、ドラ表示牌が1mの場合の点数は?

入力形式

牌の表記

  • 萬子: 1-9m(例: 123m

  • 筒子: 1-9p(例: 456p

  • 索子: 1-9s(例: 789s

  • 字牌: 1-7z

    • 1z = 東

    • 2z = 南

    • 3z = 西

    • 4z = 北

    • 5z = 白

    • 6z = 發

    • 7z = 中

  • 赤ドラ: 0で表現(例: 50m = 赤5萬)

牌姿

説明

123m456p789s1122z

一萬二萬三萬四筒五筒六筒七索八索九索東東南南

1230m456p789s11z

一萬二萬三萬赤五萬四筒五筒六筒七索八索九索東東

234m234p234s55z

二萬三萬四萬二筒三筒四筒二索三索四索白白

パラメータ

MCPツール calculate_mahjong_score は以下のパラメータを受け付けます:

パラメータ

必須

デフォルト

説明

tiles

string

-

手牌

win_tile

string

-

和了牌

dora_indicators

string

""

ドラ表示牌(カンマ区切り)

player_wind

string

"east"

自風(east/south/west/north)

round_wind

string

"east"

場風(east/south/west/north)

is_tsumo

boolean

true

ツモ和了かどうか

is_riichi

boolean

false

立直しているか

is_ippatsu

boolean

false

一発か

is_rinshan

boolean

false

嶺上開花か

is_chankan

boolean

false

搶槓か

is_haitei

boolean

false

海底摸月か

is_houtei

boolean

false

河底撈魚か

トラブルシューティング

Claude Desktopで認識されない

  1. 設定ファイルのパスと形式を確認

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

    • Windows: %APPDATA%\Claude\claude_desktop_config.json

    • JSON構文エラーがないか確認(JSONLintで検証可能)

    • ファイルをUTF-8で保存しているか確認

  2. プロジェクトのパスが絶対パスになっているか確認

    • 相対パスは使用できません

    • WSL環境の場合: /home/username/... 形式

  3. WSL環境での確認事項

    • uv コマンドが正しくインストールされているか確認:

      which uv
      uv --version
    • PATHが正しく設定されているか確認

    • Windows側から手動でコマンドを実行してテスト:

      wsl -e bash -c "export PATH=$HOME/.local/bin:$PATH && cd /home/username/projects/mahjong_calculator && uv run python -m src.server"
  4. Claude Desktopを完全に再起動

    • Windowsの場合: タスクマネージャーでプロセスが完全に終了していることを確認

    • 設定変更後は必ず再起動が必要

サーバーを再起動すると接続できなくなる(WSL環境)

問題: ローカルでSSE形式のサーバーを起動した場合、再起動後にClaude Desktopから接続できなくなる

解決策: stdio形式を使用する(上記の「Windows + WSL環境の場合」の設定)

stdio形式の利点:

  • Claude Desktopがサーバープロセスのライフサイクルを管理

  • ポートの競合や接続問題が発生しない

  • 設定が簡単で安定している

SSE形式を使いたい場合

どうしてもSSE形式を使いたい場合は、以下の手順で起動:

bash /home/miz/projects/mahjong_calculator/start_http_server.sh

設定ファイル:

{
  "mcpServers": {
    "mahjong-calculator": {
      "url": "http://localhost:8000/sse"
    }
  }
}

注意: SSE形式は手動でサーバーを起動・停止する必要があり、管理が煩雑です。

計算結果がおかしい

  1. 入力形式が正しいか確認

    • 萬子: m, 筒子: p, 索子: s, 字牌: z

    • 数字は0-9のみ(0は赤ドラ)

    • 例: 123m456p789s1122z

  2. 手牌が14枚になっているか確認

    • 手牌13枚 + 和了牌1枚 = 合計14枚

    • 正しい和了形(4面子1雀頭)である必要があります

  3. 和了っているか確認

    • 向聴数が-1(テンパイを超えている状態)

Claude Desktopのログを確認

MCPサーバーのログは標準エラー出力に出力されます。Claude Desktopのログで詳細を確認できます:

  • macOS: ~/Library/Logs/Claude/

  • Windows: %APPDATA%\Claude\logs\

ログで以下を確認:

  • サーバーが正常に起動しているか

  • コマンドのパスが正しいか

  • 実行時エラーが発生していないか

開発

ローカルでのテスト

MCPサーバーとして起動せずに、直接Pythonスクリプトとして動作確認できます:

# JSON出力のテスト
uv run python test_json_output.py

# エラーケースのテスト
uv run python test_error_cases.py

MCPサーバーのテスト

stdio形式で手動テスト:

bash start_stdio_server.sh

SSE形式で手動テスト(別ターミナルで実行):

# サーバー起動
bash start_http_server.sh

# 別ターミナルでアクセスを確認
curl http://localhost:8000/sse

テストの実行

uv run pytest

型チェック

uv run mypy src/

コードフォーマット

uv run ruff check src/

依存関係の更新

# 依存関係を追加
uv add package-name

# 依存関係を更新
uv sync --upgrade

プロジェクト構成

mahjong_calculator/
├── pyproject.toml              # プロジェクト設定・依存関係
├── uv.lock                     # 依存関係のロックファイル
├── README.md                   # このファイル
├── main.py                     # スタンドアロン実行用(MCP不使用)
├── start_http_server.sh        # SSE形式でのサーバー起動スクリプト
├── start_stdio_server.sh       # stdio形式でのサーバー起動スクリプト
├── test_json_output.py         # JSON出力のテスト
├── test_error_cases.py         # エラーケースのテスト
└── src/
    ├── __init__.py             # パッケージ初期化
    ├── constants.py            # 定数定義
    ├── tile_parser.py          # 入力解析(テキスト→内部形式)
    ├── calculator.py           # 点数計算ロジック
    └── server.py               # MCPサーバー(エントリーポイント)

ファイルの役割

コアモジュール

  • server.py: MCPサーバーのエントリーポイント。Claude Desktopとの通信を担当

    • calculate_mahjong_score(): MCPツールとして公開される関数

    • stdio/SSE両方のトランスポートに対応

  • calculator.py: 麻雀の点数計算ロジック

    • calculate_hand(): 手牌と和了牌から点数を計算

    • GameContext: 対局状況(自風、場風、リーチなど)を管理

    • 役、符、点数の詳細を返す

  • tile_parser.py: テキスト形式の牌姿を解析

    • 123m456p789s11z のような入力をmahjongライブラリの形式に変換

    • 赤ドラ(0)の処理に対応

  • constants.py: 役名や符の理由の日本語翻訳など、定数を定義

起動スクリプト

  • start_stdio_server.sh: stdio形式でサーバーを起動(Claude Desktop推奨)

  • start_http_server.sh: SSE形式(HTTP)でサーバーを起動

テスト

  • test_json_output.py: 計算結果のJSON形式をテスト

  • test_error_cases.py: エラーハンドリングをテスト

アーキテクチャ

Claude Desktop
    ↓ (MCP stdio/SSE)
server.py (FastMCP)
    ↓
calculator.py (計算ロジック)
    ↓
tile_parser.py (入力解析)
    ↓
mahjong-python (外部ライブラリ)
  1. Claude Desktop が MCP プロトコルでリクエストを送信

  2. server.pycalculate_mahjong_score ツールとしてリクエストを受信

  3. tile_parser.py が牌姿テキストを解析

  4. calculator.py が mahjong-python ライブラリを使って計算

  5. 結果を JSON 形式で Claude Desktop に返却

ライセンス

このプロジェクトは個人用です。

Available Tools

1 tool
calculate_mahjong_scoreA

麻雀の点数を計算します

牌姿と和了牌、対局状況から点数と役を計算します。

Args:
    tiles: 手牌(例: "123m456p789s1122z")
        - 萬子: 1-9m(例: 123m)
        - 筒子: 1-9p(例: 456p)
        - 索子: 1-9s(例: 789s)
        - 字牌: 1-7z(1=東, 2=南, 3=西, 4=北, 5=白, 6=發, 7=中)
        - 赤ドラ: 0で表現(例: 50m = 赤5萬)
    win_tile: 和了牌(例: "2z")
    dora_indicators: ドラ表示牌(カンマ区切り、例: "1m,5p")
    player_wind: 自風(east/south/west/north、デフォルト: east)
    round_wind: 場風(east/south/west/north、デフォルト: east)
    is_tsumo: ツモ和了かどうか(デフォルト: True)
    is_riichi: 立直しているかどうか(デフォルト: False)
    is_ippatsu: 一発かどうか(デフォルト: False)
    is_rinshan: 嶺上開花かどうか(デフォルト: False)
    is_chankan: 搶槓かどうか(デフォルト: False)
    is_haitei: 海底摸月かどうか(デフォルト: False)
    is_houtei: 河底撈魚かどうか(デフォルト: False)

Returns:
    str: 計算結果(役、翻数、符、点数)

Examples:
    calculate_mahjong_score("123m456p789s1122z", "2z")
    → 役牌の計算結果を返す

    calculate_mahjong_score("234m345p456s55z", "5z", is_tsumo=True, is_riichi=True)
    → 立直ツモの計算結果を返す
ParametersJSON Schema
NameRequiredDescriptionDefault
tilesYes
is_tsumoNo
win_tileYes
is_haiteiNo
is_houteiNo
is_riichiNo
is_chankanNo
is_ippatsuNo
is_rinshanNo
round_windNoeast
player_windNoeast
dora_indicatorsNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It thoroughly explains the input format (including red dora notation), all boolean flags, and the exact return format. This makes the tool's behavior highly transparent for a calculation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

While the description is long, it is well-structured into a purpose statement, Args block, Returns, and Examples. Every sentence adds necessary information, and the formatting makes it easy to scan. There is no fluff or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers all 12 parameters, explains the return value in plain terms (yaku, han, fu, points), and provides two examples. Given the tool's complexity, this is a complete and self-contained description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema provides no descriptions for parameters (0% coverage), but the description compensates fully by explaining each parameter in detail, including defaults, examples, and tile encoding conventions. This is exceptional parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states it calculates mahjong score and yaku from tile arrangement and game situation. This is a specific verb+resource that clearly explains what the tool does, and since no siblings are listed, there is no need for further differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context and practical examples of when to use the tool, but it does not explicitly mention when not to use it or alternatives. Given the absence of sibling tools, the guidance is sufficient and clearly implied.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 1 tool updatev0.1.0
    • First observedcalculate_mahjong_score

TDQS

A4.6/5.0
Disambiguation5/5

With only one tool, there is no potential for confusion or overlap. The single tool has a clearly defined purpose: calculating mahjong scores.

Naming Consistency5/5

The tool name 'calculate_mahjong_score' follows a clear verb_noun pattern and is self-explanatory. With a single tool, naming consistency is trivially maintained.

Tool Count2/5

A single tool is too few for a typical MCP server, even for a calculator domain. The tool is comprehensive, but the server feels thin and under-scoped.

Completeness5/5

The tool covers all necessary aspects of mahjong score calculation, including hand tiles, win tile, dora indicators, winds, and various special conditions. It provides a complete solution for its stated purpose.

Maintenance

ActivityInactive
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables Magic: The Gathering players to manage decks and access card information through Claude, supporting gameplay actions like drawing cards and mulligans while providing Scryfall API integration for card lookups.
    15
    -
  • F
    license
    A
    quality
    D
    maintenance
    Enables Claude AI to convert, edit, and analyze MuseScore files (.mscz, .musicxml, MIDI) through natural language commands, supporting format conversion, transposition, harmony analysis, and more.
    20
    1
    -
  • -
    license
    Not graded
    quality
    Not graded
    maintenance
    Enables Claude to send you a Discord message through a Cloudflare Workers MCP server, triggering a notification with your Discord mention.
    -

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/zaqdaisuki/mahjong_calculator'

If you have feedback or need assistance with the MCP directory API, please join our Discord server