girb-mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/CHANGELOG.md +16 -0
  4. data/LICENSE +21 -0
  5. data/README.ja.md +349 -0
  6. data/README.md +351 -0
  7. data/examples/01_simple_bug.rb +43 -0
  8. data/examples/02_data_pipeline.rb +93 -0
  9. data/examples/03_recursion.rb +96 -0
  10. data/examples/RAILS_SCENARIOS.md +350 -0
  11. data/examples/SCENARIOS.md +142 -0
  12. data/examples/rails_test_app/setup.sh +428 -0
  13. data/examples/rails_test_app/testapp/.dockerignore +10 -0
  14. data/examples/rails_test_app/testapp/.ruby-version +1 -0
  15. data/examples/rails_test_app/testapp/Dockerfile +23 -0
  16. data/examples/rails_test_app/testapp/Gemfile +17 -0
  17. data/examples/rails_test_app/testapp/README.md +65 -0
  18. data/examples/rails_test_app/testapp/Rakefile +6 -0
  19. data/examples/rails_test_app/testapp/app/assets/images/.keep +0 -0
  20. data/examples/rails_test_app/testapp/app/assets/stylesheets/application.css +1 -0
  21. data/examples/rails_test_app/testapp/app/controllers/application_controller.rb +4 -0
  22. data/examples/rails_test_app/testapp/app/controllers/concerns/.keep +0 -0
  23. data/examples/rails_test_app/testapp/app/controllers/dashboard_controller.rb +38 -0
  24. data/examples/rails_test_app/testapp/app/controllers/health_controller.rb +11 -0
  25. data/examples/rails_test_app/testapp/app/controllers/orders_controller.rb +100 -0
  26. data/examples/rails_test_app/testapp/app/controllers/posts_controller.rb +82 -0
  27. data/examples/rails_test_app/testapp/app/controllers/sessions_controller.rb +25 -0
  28. data/examples/rails_test_app/testapp/app/controllers/users_controller.rb +44 -0
  29. data/examples/rails_test_app/testapp/app/helpers/application_helper.rb +2 -0
  30. data/examples/rails_test_app/testapp/app/models/application_record.rb +3 -0
  31. data/examples/rails_test_app/testapp/app/models/comment.rb +8 -0
  32. data/examples/rails_test_app/testapp/app/models/concerns/.keep +0 -0
  33. data/examples/rails_test_app/testapp/app/models/order.rb +56 -0
  34. data/examples/rails_test_app/testapp/app/models/order_item.rb +16 -0
  35. data/examples/rails_test_app/testapp/app/models/post.rb +29 -0
  36. data/examples/rails_test_app/testapp/app/models/user.rb +34 -0
  37. data/examples/rails_test_app/testapp/app/services/order_report_service.rb +40 -0
  38. data/examples/rails_test_app/testapp/app/views/layouts/application.html.erb +28 -0
  39. data/examples/rails_test_app/testapp/app/views/pwa/manifest.json.erb +22 -0
  40. data/examples/rails_test_app/testapp/app/views/pwa/service-worker.js +26 -0
  41. data/examples/rails_test_app/testapp/bin/ci +6 -0
  42. data/examples/rails_test_app/testapp/bin/dev +2 -0
  43. data/examples/rails_test_app/testapp/bin/rails +4 -0
  44. data/examples/rails_test_app/testapp/bin/rake +4 -0
  45. data/examples/rails_test_app/testapp/bin/setup +35 -0
  46. data/examples/rails_test_app/testapp/config/application.rb +42 -0
  47. data/examples/rails_test_app/testapp/config/boot.rb +3 -0
  48. data/examples/rails_test_app/testapp/config/ci.rb +14 -0
  49. data/examples/rails_test_app/testapp/config/database.yml +32 -0
  50. data/examples/rails_test_app/testapp/config/environment.rb +5 -0
  51. data/examples/rails_test_app/testapp/config/environments/development.rb +54 -0
  52. data/examples/rails_test_app/testapp/config/environments/production.rb +67 -0
  53. data/examples/rails_test_app/testapp/config/environments/test.rb +42 -0
  54. data/examples/rails_test_app/testapp/config/initializers/content_security_policy.rb +29 -0
  55. data/examples/rails_test_app/testapp/config/initializers/filter_parameter_logging.rb +8 -0
  56. data/examples/rails_test_app/testapp/config/initializers/inflections.rb +16 -0
  57. data/examples/rails_test_app/testapp/config/locales/en.yml +31 -0
  58. data/examples/rails_test_app/testapp/config/puma.rb +39 -0
  59. data/examples/rails_test_app/testapp/config/routes.rb +34 -0
  60. data/examples/rails_test_app/testapp/config.ru +6 -0
  61. data/examples/rails_test_app/testapp/db/migrate/20260216002916_create_users.rb +12 -0
  62. data/examples/rails_test_app/testapp/db/migrate/20260216002919_create_posts.rb +13 -0
  63. data/examples/rails_test_app/testapp/db/migrate/20260216002922_create_comments.rb +11 -0
  64. data/examples/rails_test_app/testapp/db/migrate/20260222000001_create_orders.rb +14 -0
  65. data/examples/rails_test_app/testapp/db/migrate/20260222000002_create_order_items.rb +13 -0
  66. data/examples/rails_test_app/testapp/db/schema.rb +71 -0
  67. data/examples/rails_test_app/testapp/db/seeds.rb +85 -0
  68. data/examples/rails_test_app/testapp/docker-compose.yml +21 -0
  69. data/examples/rails_test_app/testapp/docker-entrypoint.sh +10 -0
  70. data/examples/rails_test_app/testapp/lib/tasks/.keep +0 -0
  71. data/examples/rails_test_app/testapp/log/.keep +0 -0
  72. data/examples/rails_test_app/testapp/public/400.html +135 -0
  73. data/examples/rails_test_app/testapp/public/404.html +135 -0
  74. data/examples/rails_test_app/testapp/public/406-unsupported-browser.html +135 -0
  75. data/examples/rails_test_app/testapp/public/422.html +135 -0
  76. data/examples/rails_test_app/testapp/public/500.html +135 -0
  77. data/examples/rails_test_app/testapp/public/icon.png +0 -0
  78. data/examples/rails_test_app/testapp/public/icon.svg +3 -0
  79. data/examples/rails_test_app/testapp/public/robots.txt +1 -0
  80. data/examples/rails_test_app/testapp/script/.keep +0 -0
  81. data/examples/rails_test_app/testapp/storage/.keep +0 -0
  82. data/examples/rails_test_app/testapp/tmp/.keep +0 -0
  83. data/examples/rails_test_app/testapp/tmp/pids/.keep +0 -0
  84. data/examples/rails_test_app/testapp/tmp/storage/.keep +0 -0
  85. data/examples/rails_test_app/testapp/vendor/.keep +0 -0
  86. data/exe/girb-mcp +39 -0
  87. data/exe/girb-rails +127 -0
  88. data/lib/girb_mcp/client_cleanup.rb +102 -0
  89. data/lib/girb_mcp/code_safety_analyzer.rb +124 -0
  90. data/lib/girb_mcp/debug_client.rb +1109 -0
  91. data/lib/girb_mcp/exit_message_builder.rb +112 -0
  92. data/lib/girb_mcp/pending_http_helper.rb +25 -0
  93. data/lib/girb_mcp/rails_helper.rb +155 -0
  94. data/lib/girb_mcp/server.rb +363 -0
  95. data/lib/girb_mcp/session_manager.rb +436 -0
  96. data/lib/girb_mcp/stop_event_annotator.rb +152 -0
  97. data/lib/girb_mcp/tcp_session_discovery.rb +226 -0
  98. data/lib/girb_mcp/tools/connect.rb +668 -0
  99. data/lib/girb_mcp/tools/continue_execution.rb +161 -0
  100. data/lib/girb_mcp/tools/disconnect.rb +168 -0
  101. data/lib/girb_mcp/tools/evaluate_code.rb +354 -0
  102. data/lib/girb_mcp/tools/finish.rb +84 -0
  103. data/lib/girb_mcp/tools/get_context.rb +217 -0
  104. data/lib/girb_mcp/tools/get_source.rb +193 -0
  105. data/lib/girb_mcp/tools/inspect_object.rb +107 -0
  106. data/lib/girb_mcp/tools/list_debug_sessions.rb +60 -0
  107. data/lib/girb_mcp/tools/list_files.rb +189 -0
  108. data/lib/girb_mcp/tools/list_paused_sessions.rb +108 -0
  109. data/lib/girb_mcp/tools/next.rb +70 -0
  110. data/lib/girb_mcp/tools/rails_info.rb +200 -0
  111. data/lib/girb_mcp/tools/rails_model.rb +362 -0
  112. data/lib/girb_mcp/tools/rails_routes.rb +186 -0
  113. data/lib/girb_mcp/tools/read_file.rb +214 -0
  114. data/lib/girb_mcp/tools/remove_breakpoint.rb +173 -0
  115. data/lib/girb_mcp/tools/run_debug_command.rb +55 -0
  116. data/lib/girb_mcp/tools/run_script.rb +293 -0
  117. data/lib/girb_mcp/tools/set_breakpoint.rb +206 -0
  118. data/lib/girb_mcp/tools/step.rb +67 -0
  119. data/lib/girb_mcp/tools/trigger_request.rb +515 -0
  120. data/lib/girb_mcp/version.rb +5 -0
  121. data/lib/girb_mcp.rb +40 -0
  122. metadata +237 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0ec1d1879baf1246717397a39e5502b67a68b0eeb1c21febb3d8954dbfc107cc
4
+ data.tar.gz: ec7109b75b87d39b9cff4323e757e57120e6ea00810deff51ba7080a8b6ef2f5
5
+ SHA512:
6
+ metadata.gz: ee3a99cda1568e92768a77a99d2122e72301afe51557693fca77db8c2ec9e28f00c663ec0ebcb1d7be70c28a1d6add8adddcc15c2ef5bd4fba0f9260c953059d
7
+ data.tar.gz: 223b9cb54c002aa31c3458e1997278be06e4a82c12a08b1c0943c0cdd1eef029821b1e5c101afa2fc149870be893e6087876d8c6f8b97359297cc86fb577abf4
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 — 2026-03-01
4
+
5
+ Initial release.
6
+
7
+ ### Features
8
+
9
+ - **MCP server** with STDIO and Streamable HTTP transports
10
+ - **21 debugging tools**: connect, evaluate_code, inspect_object, get_context, get_source, read_file, list_files, set_breakpoint, remove_breakpoint, continue_execution, step, next, finish, run_script, trigger_request, disconnect, and more
11
+ - **Rails integration**: auto-detected rails_info, rails_routes, rails_model tools
12
+ - **Docker support**: TCP and Unix socket connections with automatic remote file reading
13
+ - **Signal trap context handling**: auto-escape on connect and after trigger_request
14
+ - **Code safety checker**: warns about dangerous operations in evaluate_code
15
+ - **Session management**: multiple concurrent sessions with automatic timeout cleanup
16
+ - **girb-rails CLI**: launch Rails server with debug enabled in one command
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Rira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.ja.md ADDED
@@ -0,0 +1,349 @@
1
+ # girb-mcp
2
+
3
+ LLMエージェントが実行中のRubyプロセスの実行時コンテキストにアクセスするためのMCP (Model Context Protocol) サーバーです。
4
+
5
+ Claude CodeなどのLLMエージェントが、停止中のRubyプロセスに接続し、変数の調査・コード評価・ブレークポイント設定・実行制御をMCPツール呼び出しだけで完結できます。
6
+
7
+ ## できること
8
+
9
+ 既存のRuby/Rails向けMCPサーバーは静的解析やアプリケーションレベルのAPIにとどまっています。girb-mcpはdebug gem経由で**実行中のRubyプロセス**に接続し、その実行時状態をLLMエージェントに公開します。
10
+
11
+ ```
12
+ Claude Code → connect(host: "localhost", port: 12345)
13
+ Claude Code → get_context()
14
+ → ローカル変数、インスタンス変数、コールスタック
15
+ Claude Code → evaluate_code(code: "user.valid?")
16
+ → false
17
+ Claude Code → evaluate_code(code: "user.errors.full_messages")
18
+ → ["Email can't be blank"]
19
+ Claude Code → continue_execution()
20
+ ```
21
+
22
+ ## インストール
23
+
24
+ ```ruby
25
+ gem "girb-mcp"
26
+ ```
27
+
28
+ または直接インストール:
29
+
30
+ ```
31
+ gem install girb-mcp
32
+ ```
33
+
34
+ Ruby >= 3.2.0が必要です。
35
+
36
+ ## クイックスタート
37
+
38
+ ### 1. デバッガ付きでRubyプロセスを起動
39
+
40
+ ```bash
41
+ # スクリプト
42
+ rdbg --open --port=12345 my_script.rb
43
+
44
+ # 環境変数で指定
45
+ RUBY_DEBUG_OPEN=true RUBY_DEBUG_PORT=12345 ruby my_script.rb
46
+
47
+ # コード中に `debugger` / `binding.break` を記述して実行
48
+ rdbg --open my_script.rb
49
+ ```
50
+
51
+ ### 2. Claude Codeの設定
52
+
53
+ `~/.claude/settings.json`(またはプロジェクトの`.claude/settings.json`)に追加:
54
+
55
+ ```json
56
+ {
57
+ "mcpServers": {
58
+ "girb-mcp": {
59
+ "command": "girb-mcp",
60
+ "args": []
61
+ }
62
+ }
63
+ }
64
+ ```
65
+
66
+ Bundler経由の場合:
67
+
68
+ ```json
69
+ {
70
+ "mcpServers": {
71
+ "girb-mcp": {
72
+ "command": "bundle",
73
+ "args": ["exec", "girb-mcp"]
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ ### 3. Claude Codeでデバッグ
80
+
81
+ Claude Codeに接続とデバッグを依頼:
82
+
83
+ > 「ポート12345のデバッグセッションに接続して現在の状態を見せて」
84
+
85
+ > 「app/models/user.rbの42行目にブレークポイントを設定して、/users/1にGETリクエストを送って」
86
+
87
+ ## 使い方
88
+
89
+ ```
90
+ Usage: girb-mcp [options]
91
+ -t, --transport TRANSPORT トランスポート: stdio(デフォルト)または http
92
+ -p, --port PORT HTTPポート(デフォルト: 6029、httpトランスポート時のみ)
93
+ --host HOST HTTPホスト(デフォルト: 127.0.0.1、httpトランスポート時のみ)
94
+ --session-timeout SECONDS セッションタイムアウト秒数(デフォルト: 1800)
95
+ -v, --version バージョン表示
96
+ -h, --help ヘルプ表示
97
+ ```
98
+
99
+ ### STDIOトランスポート(デフォルト)
100
+
101
+ Claude Codeなどの標準的なMCPクライアント向け。追加設定は不要です。
102
+
103
+ ```bash
104
+ girb-mcp
105
+ ```
106
+
107
+ ### HTTPトランスポート(Streamable HTTP)
108
+
109
+ ブラウザベースのクライアントやHTTP対応MCPクライアント向け。
110
+
111
+ ```bash
112
+ girb-mcp --transport http --port 8080
113
+ ```
114
+
115
+ MCPエンドポイントは `http://127.0.0.1:8080/mcp` で利用可能になります。
116
+
117
+ ### セッションタイムアウト
118
+
119
+ デバッグセッションは30分間操作がないと自動的にクリーンアップされます。変更するには:
120
+
121
+ ```bash
122
+ girb-mcp --session-timeout 3600 # 1時間
123
+ ```
124
+
125
+ セッションマネージャーは、対象プロセスが終了したセッションも検出して自動的にクリーンアップします。
126
+
127
+ ## ツール一覧
128
+
129
+ ### 接続・検出
130
+
131
+ | ツール | 説明 |
132
+ |------|------|
133
+ | `list_debug_sessions` | 利用可能なデバッグセッション一覧(Unixソケット) |
134
+ | `connect` | ソケットパスまたはTCPでデバッグセッションに接続 |
135
+ | `list_paused_sessions` | 接続中のセッション一覧 |
136
+
137
+ ### 調査
138
+
139
+ | ツール | 説明 |
140
+ |------|------|
141
+ | `evaluate_code` | 停止中のbindingでRubyコードを実行 |
142
+ | `inspect_object` | オブジェクトのクラス・値・インスタンス変数を取得 |
143
+ | `get_context` | ローカル変数・インスタンス変数・コールスタック・ブレークポイントを一括取得 |
144
+ | `get_source` | メソッドまたはクラスのソースコードを取得 |
145
+ | `read_file` | ソースファイルの読み取り(行範囲指定可) |
146
+ | `list_files` | ディレクトリ内のファイル一覧(globパターンでフィルタ可) |
147
+
148
+ ### 実行制御
149
+
150
+ | ツール | 説明 |
151
+ |------|------|
152
+ | `set_breakpoint` | ブレークポイント設定:行(file + line)、メソッド(`User#save`)、例外クラス |
153
+ | `remove_breakpoint` | file + line、メソッド名、例外クラス、または番号でブレークポイントを削除 |
154
+ | `continue_execution` | 次のブレークポイントまたは終了まで実行を再開 |
155
+ | `step` | ステップイン(メソッド呼び出しに入る) |
156
+ | `next` | ステップオーバー(次の行へ進む) |
157
+ | `finish` | 現在のメソッド/ブロックがreturnするまで実行 |
158
+ | `run_debug_command` | 任意のデバッガコマンドを直接実行 |
159
+ | `disconnect` | セッション切断とプロセス終了 |
160
+
161
+ ### 入口ツール
162
+
163
+ | ツール | 説明 |
164
+ |------|------|
165
+ | `run_script` | rdbg経由でRubyスクリプトを起動して接続 |
166
+ | `trigger_request` | デバッグ中のRailsアプリにHTTPリクエストを送信 |
167
+
168
+ ### Railsツール(自動検出)
169
+
170
+ Railsプロセスを検出すると自動的に登録されます。
171
+
172
+ | ツール | 説明 |
173
+ |------|------|
174
+ | `rails_info` | アプリ名・Rails/Rubyバージョン・環境・ルートパスを表示 |
175
+ | `rails_routes` | ルーティング一覧(verb, path, controller#action)、コントローラ・パスでフィルタ可能 |
176
+ | `rails_model` | モデル構造:カラム・アソシエーション・バリデーション・enum・スコープを表示 |
177
+
178
+ ## ワークフロー例
179
+
180
+ ### Rubyスクリプトのデバッグ
181
+
182
+ ```
183
+ Agent: run_script(file: "my_script.rb")
184
+ Agent: get_context()
185
+ Agent: evaluate_code(code: "result")
186
+ Agent: next()
187
+ Agent: evaluate_code(code: "result")
188
+ Agent: continue_execution()
189
+ ```
190
+
191
+ ### メソッドブレークポイント
192
+
193
+ ```
194
+ Agent: run_script(file: "my_script.rb", breakpoints: ["DataPipeline#validate"])
195
+ → スクリプトが起動し、DataPipeline#validate で停止
196
+ Agent: evaluate_code(code: "records")
197
+ Agent: continue_execution()
198
+ ```
199
+
200
+ ### 例外のキャッチとデバッグ
201
+
202
+ ```
203
+ Agent: run_script(file: "my_script.rb")
204
+ Agent: set_breakpoint(exception_class: "NoMethodError")
205
+ Agent: continue_execution()
206
+ → 例外が伝播する前に実行が停止
207
+ Agent: get_context()
208
+ Agent: evaluate_code(code: "$!.message")
209
+ ```
210
+
211
+ ### クラッシュ後の再起動
212
+
213
+ ```
214
+ → NoMethodError でプログラムがクラッシュ
215
+ Agent: run_script(file: "my_script.rb", restore_breakpoints: true)
216
+ → 前回のブレークポイントが自動復元
217
+ Agent: set_breakpoint(exception_class: "NoMethodError")
218
+ Agent: continue_execution()
219
+ → クラッシュ前に例外をキャッチ
220
+ ```
221
+
222
+ ### Railsリクエストのデバッグ
223
+
224
+ `girb-rails` でデバッグ有効状態のRailsサーバーを起動:
225
+
226
+ ```bash
227
+ girb-rails # RUBY_DEBUG_OPEN=true bin/rails server と同等
228
+ girb-rails s -p 4000 # ポート指定
229
+ girb-rails --debug-port 3333 # TCPデバッグポートを指定(Docker内で便利)
230
+ ```
231
+
232
+ エージェントにデバッグを依頼:
233
+
234
+ ```
235
+ Agent: connect()
236
+ Agent: set_breakpoint(file: "app/controllers/users_controller.rb", line: 15)
237
+ Agent: trigger_request(method: "GET", url: "http://localhost:3000/users/1")
238
+ Agent: get_context()
239
+ Agent: evaluate_code(code: "@user.attributes")
240
+ Agent: continue_execution()
241
+ ```
242
+
243
+ ### Docker内のRailsアプリをデバッグ
244
+
245
+ > **セキュリティ注意:** debug gemには認証機能がありません。デバッグポートにアクセスできれば、誰でもコンテナ内で任意のコードを実行できます。以下のようにアクセスを制限してください。
246
+
247
+ #### Option A: localhost限定TCP(シンプル)
248
+
249
+ デバッグポートを `127.0.0.1` にバインドし、ローカルプロセスのみ接続可能にします:
250
+
251
+ ```yaml
252
+ services:
253
+ web:
254
+ build: .
255
+ ports:
256
+ - "3000:3000"
257
+ - "127.0.0.1:12345:12345" # localhostのみ
258
+ environment:
259
+ - RUBY_DEBUG_OPEN=true
260
+ - RUBY_DEBUG_HOST=0.0.0.0
261
+ - RUBY_DEBUG_PORT=12345
262
+ ```
263
+
264
+ ```
265
+ Agent: connect(port: 12345)
266
+ ```
267
+
268
+ ローカルにソースコードがなくても、エージェントがコンテナ内のファイルを閲覧・読み取りできます。
269
+
270
+ #### Option B: Unixソケットボリュームマウント(推奨)
271
+
272
+ デバッグソケット用の共有ディレクトリをマウントします。ポート公開は不要です:
273
+
274
+ ```yaml
275
+ services:
276
+ web:
277
+ build: .
278
+ ports:
279
+ - "3000:3000"
280
+ environment:
281
+ - RUBY_DEBUG_OPEN=true
282
+ - RUBY_DEBUG_SOCK_PATH=/debug/rdbg.sock
283
+ volumes:
284
+ - debug_sock:/debug
285
+
286
+ volumes:
287
+ debug_sock:
288
+ ```
289
+
290
+ ```
291
+ Agent: connect(path: "/path/to/debug_sock/rdbg.sock")
292
+ ```
293
+
294
+ ### 既存のブレークポイントに接続
295
+
296
+ ```bash
297
+ # ターミナル: アプリが `debugger` 文に到達
298
+ rdbg --open my_app.rb
299
+ ```
300
+
301
+ ```
302
+ Agent: list_debug_sessions()
303
+ Agent: connect(path: "/tmp/rdbg-1000/rdbg-12345")
304
+ Agent: get_context()
305
+ ```
306
+
307
+ ## 仕組み
308
+
309
+ ```
310
+ ┌─────────────┐ STDIO or Streamable HTTP ┌───────────┐ TCP/Unixソケット ┌──────────────┐
311
+ │ Claude Code │ ◄──────────────────────► │ girb-mcp │ ◄──────────────────► │ Rubyプロセス │
312
+ │ (MCPクライアント)│ (JSON-RPC) │(MCPサーバー) │ debug gemプロトコル │ (rdbg) │
313
+ └─────────────┘ └───────────┘ └──────────────┘
314
+ ```
315
+
316
+ 1. girb-mcpはSTDIO(デフォルト)またはStreamable HTTPで通信するMCPサーバーとして動作
317
+ 2. debug gem(`rdbg --open`)が対象Rubyプロセスにソケットを公開
318
+ 3. girb-mcpがdebug gemのワイヤープロトコルでそのソケットに接続
319
+ 4. MCPツール呼び出しがデバッガコマンドに変換され、結果が返される
320
+ 5. アイドル状態のセッションは設定可能なタイムアウト後に自動クリーンアップされる
321
+
322
+ ## セキュリティ
323
+
324
+ girb-mcpはデバッグツールであり、実行中のRubyプロセスへの深いランタイムアクセスを提供します。
325
+
326
+ **専用ツールにより任意コード実行を最小化。** 変数の確認・ソースコードの閲覧・モデル構造の調査など、ほとんどのデバッグ操作は任意コードを実行しない専用ツールで行われます。ランタイム検査用に`evaluate_code`も利用可能で、危険な操作に対しては組み込みの安全性チェッカーが警告します。
327
+
328
+ **debug gemには認証機能がありません。** デバッグソケットにアクセスできれば、対象プロセスで任意のコードを実行できます。必ずlocalhost(`127.0.0.1`)にバインドするか、Unixソケットを使用してください。具体的な設定例は[Docker節](#docker内のrailsアプリをデバッグ)を参照してください。
329
+
330
+ ## girbファミリー
331
+
332
+ girb-mcpは[girb](https://github.com/rira100000000/girb)ファミリーの一員です:
333
+
334
+ - **girb** — AI搭載IRBアシスタント(対話型、人間向け)
335
+ - **girb-mcp** — LLMエージェント向けMCPサーバー(プログラマティック、エージェント向け)
336
+ - **girb-ruby_llm** — ruby_llm経由のLLMプロバイダー
337
+ - **girb-gemini** — Gemini API経由のLLMプロバイダー
338
+
339
+ ## 開発
340
+
341
+ ```bash
342
+ git clone https://github.com/rira100000000/girb-mcp.git
343
+ cd girb-mcp
344
+ bundle install
345
+ ```
346
+
347
+ ## ライセンス
348
+
349
+ MIT