recce-nightly 1.15.0.20250806__py3-none-any.whl → 1.26.0.20251124__py3-none-any.whl

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.

Potentially problematic release.


This version of recce-nightly might be problematic. Click here for more details.

Files changed (167) hide show
  1. recce/VERSION +1 -1
  2. recce/__init__.py +5 -0
  3. recce/adapter/dbt_adapter/__init__.py +12 -3
  4. recce/artifact.py +74 -1
  5. recce/cli.py +642 -101
  6. recce/config.py +2 -2
  7. recce/connect_to_cloud.py +1 -1
  8. recce/core.py +2 -2
  9. recce/data/404.html +1 -1
  10. recce/data/__next.__PAGE__.txt +10 -0
  11. recce/data/__next._full.txt +23 -0
  12. recce/data/__next._head.txt +8 -0
  13. recce/data/__next._index.txt +8 -0
  14. recce/data/__next._tree.txt +5 -0
  15. recce/data/_next/static/52aV_JrNUZU6dMFgvTQEO/_buildManifest.js +11 -0
  16. recce/data/_next/static/52aV_JrNUZU6dMFgvTQEO/_clientMiddlewareManifest.json +1 -0
  17. recce/data/_next/static/chunks/02b996c7f6a29a06.js +4 -0
  18. recce/data/_next/static/chunks/19c10d219a6a21ff.js +1 -0
  19. recce/data/_next/static/chunks/2df9ec28a061971d.js +11 -0
  20. recce/data/_next/static/chunks/3098c987393bda15.js +1 -0
  21. recce/data/_next/static/chunks/393dc43e483f717a.css +2 -0
  22. recce/data/_next/static/chunks/399e8d91a7e45073.js +2 -0
  23. recce/data/_next/static/chunks/4d0186f631230245.js +1 -0
  24. recce/data/_next/static/chunks/5794ba9e10a9c060.js +11 -0
  25. recce/data/_next/static/chunks/715761c929a3f28b.js +110 -0
  26. recce/data/_next/static/chunks/71f88fcc615bf282.js +1 -0
  27. recce/data/_next/static/chunks/80d2a95eaf1201ea.js +1 -0
  28. recce/data/_next/static/chunks/9979c6109bbbee35.js +1 -0
  29. recce/data/_next/static/chunks/99d638224186c118.js +1 -0
  30. recce/data/_next/static/chunks/d003eb36240e92f3.js +1 -0
  31. recce/data/_next/static/chunks/d3167cdfec4fc351.js +1 -0
  32. recce/data/_next/static/chunks/e124bccf574a3361.css +1 -0
  33. recce/data/_next/static/chunks/f40141db1bdb46f0.css +6 -0
  34. recce/data/_next/static/chunks/fcc53a88741a52f9.js +1 -0
  35. recce/data/_next/static/chunks/turbopack-b1920d28cfb1f28d.js +3 -0
  36. recce/data/_next/static/media/favicon.a8d38d84.ico +0 -0
  37. recce/data/_next/static/media/montserrat-cyrillic-800-normal.d80d830d.woff2 +0 -0
  38. recce/data/_next/static/media/{montserrat-cyrillic-800-normal.bd5c9f50.woff → montserrat-cyrillic-800-normal.f9d58125.woff} +0 -0
  39. recce/data/_next/static/media/montserrat-cyrillic-ext-800-normal.076c2a93.woff2 +0 -0
  40. recce/data/_next/static/media/montserrat-latin-800-normal.cde454cc.woff2 +0 -0
  41. recce/data/_next/static/media/{montserrat-latin-800-normal.fc315020.woff → montserrat-latin-800-normal.d5761935.woff} +0 -0
  42. recce/data/_next/static/media/montserrat-latin-ext-800-normal.40ec0659.woff2 +0 -0
  43. recce/data/_next/static/media/{montserrat-latin-ext-800-normal.2e5381b2.woff → montserrat-latin-ext-800-normal.b671449b.woff} +0 -0
  44. recce/data/_next/static/media/{montserrat-vietnamese-800-normal.20c545e6.woff → montserrat-vietnamese-800-normal.9f7b8541.woff} +0 -0
  45. recce/data/_next/static/media/montserrat-vietnamese-800-normal.f9eb854e.woff2 +0 -0
  46. recce/data/_not-found/__next._full.txt +17 -0
  47. recce/data/_not-found/__next._head.txt +8 -0
  48. recce/data/_not-found/__next._index.txt +8 -0
  49. recce/data/_not-found/__next._not-found.__PAGE__.txt +5 -0
  50. recce/data/_not-found/__next._not-found.txt +4 -0
  51. recce/data/_not-found/__next._tree.txt +3 -0
  52. recce/data/_not-found.html +1 -0
  53. recce/data/_not-found.txt +17 -0
  54. recce/data/index.html +1 -1
  55. recce/data/index.txt +21 -23
  56. recce/event/__init__.py +9 -8
  57. recce/event/collector.py +3 -1
  58. recce/event/track.py +10 -0
  59. recce/github.py +1 -1
  60. recce/mcp_server.py +716 -0
  61. recce/models/types.py +35 -2
  62. recce/pull_request.py +1 -1
  63. recce/run.py +2 -2
  64. recce/server.py +105 -3
  65. recce/state/__init__.py +31 -0
  66. recce/state/cloud.py +632 -0
  67. recce/state/const.py +26 -0
  68. recce/state/local.py +56 -0
  69. recce/state/state.py +119 -0
  70. recce/state/state_loader.py +174 -0
  71. recce/summary.py +21 -1
  72. recce/tasks/dataframe.py +63 -1
  73. recce/tasks/rowcount.py +4 -1
  74. recce/tasks/schema.py +4 -1
  75. recce/util/api_token.py +9 -2
  76. recce/util/breaking.py +1 -1
  77. recce/util/io.py +2 -2
  78. recce/util/lineage.py +14 -18
  79. recce/util/recce_cloud.py +187 -7
  80. recce/yaml/__init__.py +2 -2
  81. recce_cloud/__init__.py +24 -0
  82. recce_cloud/api/__init__.py +17 -0
  83. recce_cloud/api/base.py +111 -0
  84. recce_cloud/api/client.py +150 -0
  85. recce_cloud/api/exceptions.py +26 -0
  86. recce_cloud/api/factory.py +63 -0
  87. recce_cloud/api/github.py +76 -0
  88. recce_cloud/api/gitlab.py +82 -0
  89. recce_cloud/artifact.py +57 -0
  90. recce_cloud/ci_providers/__init__.py +9 -0
  91. recce_cloud/ci_providers/base.py +82 -0
  92. recce_cloud/ci_providers/detector.py +147 -0
  93. recce_cloud/ci_providers/github_actions.py +136 -0
  94. recce_cloud/ci_providers/gitlab_ci.py +130 -0
  95. recce_cloud/cli.py +245 -0
  96. recce_cloud/upload.py +214 -0
  97. {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/METADATA +54 -28
  98. recce_nightly-1.26.0.20251124.dist-info/RECORD +180 -0
  99. {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/top_level.txt +1 -0
  100. tests/adapter/dbt_adapter/test_dbt_cll.py +4 -2
  101. tests/recce_cloud/__init__.py +0 -0
  102. tests/recce_cloud/test_ci_providers.py +351 -0
  103. tests/recce_cloud/test_cli.py +372 -0
  104. tests/recce_cloud/test_client.py +273 -0
  105. tests/recce_cloud/test_platform_clients.py +333 -0
  106. tests/test_cli.py +106 -3
  107. tests/test_cli_mcp_optional.py +45 -0
  108. tests/test_cloud_listing_cli.py +324 -0
  109. tests/test_core.py +147 -0
  110. tests/test_mcp_server.py +332 -0
  111. tests/test_server.py +6 -6
  112. tests/test_summary.py +14 -6
  113. recce/data/_next/static/Q_5ThPsmamd4VAGXuqwgi/_buildManifest.js +0 -1
  114. recce/data/_next/static/chunks/0376eeba-3db2196398d62270.js +0 -1
  115. recce/data/_next/static/chunks/068b80ea-833a129468ee1622.js +0 -1
  116. recce/data/_next/static/chunks/0ddaf06c-c7961285f66460f6.js +0 -1
  117. recce/data/_next/static/chunks/1268aea1-6dc1251c01bd724b.js +0 -54
  118. recce/data/_next/static/chunks/12f8fac4-16838e42d28d45c3.js +0 -1
  119. recce/data/_next/static/chunks/235b8375-8c84c51d7bd4f6aa.js +0 -1
  120. recce/data/_next/static/chunks/2541941f-2cd3a7c2d629bd33.js +0 -1
  121. recce/data/_next/static/chunks/273-f3fa401bd2b6fc91.js +0 -10
  122. recce/data/_next/static/chunks/2fc37c1e-910deebeb3d77c90.js +0 -1
  123. recce/data/_next/static/chunks/338-2e7eed5135c64550.js +0 -30
  124. recce/data/_next/static/chunks/367-ab8b16dd5f8586ca.js +0 -1
  125. recce/data/_next/static/chunks/3a92ee20-0400ffe460c7c803.js +0 -1
  126. recce/data/_next/static/chunks/62446465-423c03bb8c1f59b6.js +0 -1
  127. recce/data/_next/static/chunks/6af7f9e9-60aa8706f49dae45.js +0 -1
  128. recce/data/_next/static/chunks/6cf54382-49d52ae6e564e2ac.js +0 -1
  129. recce/data/_next/static/chunks/6dc81886-78e2efe4538794ae.js +0 -1
  130. recce/data/_next/static/chunks/715e4acc-9e2e6df4eb3809d1.js +0 -1
  131. recce/data/_next/static/chunks/72-181b430654230f0e.js +0 -1
  132. recce/data/_next/static/chunks/786-774e3e3ed70a41b3.js +0 -1
  133. recce/data/_next/static/chunks/8d700b6a.7fe2c8c3f4e333a6.js +0 -1
  134. recce/data/_next/static/chunks/a69d64b4-d6890125a87b0aba.js +0 -1
  135. recce/data/_next/static/chunks/ae307f12-01100009689ace61.js +0 -1
  136. recce/data/_next/static/chunks/app/_not-found/page-c7ef8ed6dc07aaeb.js +0 -1
  137. recce/data/_next/static/chunks/app/layout-744f0a78e9e50e60.js +0 -1
  138. recce/data/_next/static/chunks/app/page-e8f798c2ae3f59c2.js +0 -1
  139. recce/data/_next/static/chunks/c0015c5c-82c219792582c104.js +0 -1
  140. recce/data/_next/static/chunks/d90cfbaa-e7d779b3912afeec.js +0 -1
  141. recce/data/_next/static/chunks/e07c302e-cd170429646873e1.js +0 -1
  142. recce/data/_next/static/chunks/fa5fb511-15fb438349ad5b97.js +0 -1
  143. recce/data/_next/static/chunks/framework-7950757d31580329.js +0 -1
  144. recce/data/_next/static/chunks/main-app-4df79eb11c34d43c.js +0 -1
  145. recce/data/_next/static/chunks/main-cd6c104af638214a.js +0 -1
  146. recce/data/_next/static/chunks/pages/_app-73008661edbd5e05.js +0 -1
  147. recce/data/_next/static/chunks/pages/_error-cf8bbdc3cf76c83f.js +0 -1
  148. recce/data/_next/static/chunks/webpack-84df6dd5ae3cf908.js +0 -1
  149. recce/data/_next/static/css/188a3a1687e2a064.css +0 -1
  150. recce/data/_next/static/css/8edca58d4abcf908.css +0 -14
  151. recce/data/_next/static/css/abdb9814a3dd18bb.css +0 -1
  152. recce/data/_next/static/css/c21263c1520b615b.css +0 -1
  153. recce/data/_next/static/media/montserrat-cyrillic-800-normal.22628180.woff2 +0 -0
  154. recce/data/_next/static/media/montserrat-cyrillic-ext-800-normal.94a63aea.woff2 +0 -0
  155. recce/data/_next/static/media/montserrat-latin-800-normal.6f8fa298.woff2 +0 -0
  156. recce/data/_next/static/media/montserrat-latin-ext-800-normal.013b84f9.woff2 +0 -0
  157. recce/data/_next/static/media/montserrat-vietnamese-800-normal.c0035377.woff2 +0 -0
  158. recce/state.py +0 -865
  159. recce_nightly-1.15.0.20250806.dist-info/RECORD +0 -156
  160. tests/test_state.py +0 -134
  161. /recce/data/_next/static/{Q_5ThPsmamd4VAGXuqwgi → 52aV_JrNUZU6dMFgvTQEO}/_ssgManifest.js +0 -0
  162. /recce/data/_next/static/chunks/{polyfills-42372ed130431b0a.js → a6dad97d9634a72d.js} +0 -0
  163. /recce/data/_next/static/media/{montserrat-cyrillic-ext-800-normal.e6e0d8d0.woff → montserrat-cyrillic-ext-800-normal.a4fa76b5.woff} +0 -0
  164. /recce/data/_next/static/media/{reload-image.79aabb7d.svg → reload-image.7aa931c7.svg} +0 -0
  165. {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/WHEEL +0 -0
  166. {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/entry_points.txt +0 -0
  167. {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/licenses/LICENSE +0 -0
recce/cli.py CHANGED
@@ -8,7 +8,12 @@ import uvicorn
8
8
  from click import Abort
9
9
 
10
10
  from recce import event
11
- from recce.artifact import download_dbt_artifacts, upload_dbt_artifacts
11
+ from recce.artifact import (
12
+ delete_dbt_artifacts,
13
+ download_dbt_artifacts,
14
+ upload_artifacts_to_session,
15
+ upload_dbt_artifacts,
16
+ )
12
17
  from recce.config import RECCE_CONFIG_FILE, RECCE_ERROR_LOG_FILE, RecceConfig
13
18
  from recce.connect_to_cloud import (
14
19
  generate_key_pair,
@@ -19,7 +24,12 @@ from recce.exceptions import RecceConfigException
19
24
  from recce.git import current_branch, current_default_branch
20
25
  from recce.run import check_github_ci_env, cli_run
21
26
  from recce.server import RecceServerMode
22
- from recce.state import RecceCloudStateManager, RecceShareStateManager, RecceStateLoader
27
+ from recce.state import (
28
+ CloudStateLoader,
29
+ FileStateLoader,
30
+ RecceCloudStateManager,
31
+ RecceShareStateManager,
32
+ )
23
33
  from recce.summary import generate_markdown_summary
24
34
  from recce.util.api_token import prepare_api_token, show_invalid_api_token_message
25
35
  from recce.util.logger import CustomFormatter
@@ -40,9 +50,13 @@ def create_state_loader(review_mode, cloud_mode, state_file, cloud_options):
40
50
  console = Console()
41
51
 
42
52
  try:
43
- return RecceStateLoader(
44
- review_mode=review_mode, cloud_mode=cloud_mode, state_file=state_file, cloud_options=cloud_options
53
+ state_loader = (
54
+ CloudStateLoader(review_mode=review_mode, cloud_options=cloud_options)
55
+ if cloud_mode
56
+ else FileStateLoader(review_mode=review_mode, state_file=state_file)
45
57
  )
58
+ state_loader.load()
59
+ return state_loader
46
60
  except RecceCloudException as e:
47
61
  console.print("[[red]Error[/red]] Failed to load recce state file")
48
62
  console.print(f"Reason: {e.reason}")
@@ -53,6 +67,75 @@ def create_state_loader(review_mode, cloud_mode, state_file, cloud_options):
53
67
  exit(1)
54
68
 
55
69
 
70
+ def patch_derived_args(args):
71
+ """
72
+ Patch derived args based on other args.
73
+ """
74
+ if args.get("session_id") or args.get("share_url"):
75
+ args["cloud"] = True
76
+ args["review"] = True
77
+
78
+
79
+ def create_state_loader_by_args(state_file=None, **kwargs):
80
+ """
81
+ Create a state loader based on CLI arguments.
82
+
83
+ This function handles the cloud options logic that is shared between
84
+ server and mcp-server commands.
85
+
86
+ Args:
87
+ state_file: Optional path to state file
88
+ **kwargs: CLI arguments including api_token, cloud, review, session_id, share_url, etc.
89
+
90
+ Returns:
91
+ state_loader: The created state loader instance
92
+ """
93
+ from rich.console import Console
94
+
95
+ console = Console()
96
+
97
+ api_token = kwargs.get("api_token")
98
+ is_review = kwargs.get("review", False)
99
+ is_cloud = kwargs.get("cloud", False)
100
+ cloud_options = None
101
+
102
+ # Handle share_url and session_id
103
+ share_url = kwargs.get("share_url")
104
+ session_id = kwargs.get("session_id")
105
+
106
+ if share_url:
107
+ share_id = share_url.split("/")[-1]
108
+ if not share_id:
109
+ console.print("[[red]Error[/red]] Invalid share URL format.")
110
+ exit(1)
111
+
112
+ if is_cloud:
113
+ # Cloud mode
114
+ if share_url:
115
+ cloud_options = {
116
+ "host": kwargs.get("state_file_host"),
117
+ "api_token": api_token,
118
+ "share_id": share_id,
119
+ }
120
+ elif session_id:
121
+ cloud_options = {
122
+ "host": kwargs.get("state_file_host"),
123
+ "api_token": api_token,
124
+ "session_id": session_id,
125
+ }
126
+ else:
127
+ cloud_options = {
128
+ "host": kwargs.get("state_file_host"),
129
+ "github_token": kwargs.get("cloud_token"),
130
+ "password": kwargs.get("password"),
131
+ }
132
+
133
+ # Create state loader
134
+ state_loader = create_state_loader(is_review, is_cloud, state_file, cloud_options)
135
+
136
+ return state_loader
137
+
138
+
56
139
  def handle_debug_flag(**kwargs):
57
140
  if kwargs.get("debug"):
58
141
  import logging
@@ -61,6 +144,14 @@ def handle_debug_flag(**kwargs):
61
144
  ch.setFormatter(CustomFormatter())
62
145
  logging.basicConfig(handlers=[ch], level=logging.DEBUG)
63
146
 
147
+ # Explicitly set uvicorn logger to DEBUG level
148
+ uvicorn_logger = logging.getLogger("uvicorn")
149
+ uvicorn_logger.setLevel(logging.DEBUG)
150
+
151
+ # Set all child loggers to DEBUG as well
152
+ for handler in uvicorn_logger.handlers:
153
+ handler.setLevel(logging.DEBUG)
154
+
64
155
 
65
156
  def add_options(options):
66
157
  def _add_options(func):
@@ -130,6 +221,15 @@ recce_cloud_options = [
130
221
  ),
131
222
  ]
132
223
 
224
+ recce_cloud_auth_options = [
225
+ click.option(
226
+ "--api-token",
227
+ help="The personal token generated by Recce Cloud.",
228
+ type=click.STRING,
229
+ envvar="RECCE_API_TOKEN",
230
+ )
231
+ ]
232
+
133
233
  recce_dbt_artifact_dir_options = [
134
234
  click.option(
135
235
  "--target-path",
@@ -159,6 +259,13 @@ recce_hidden_options = [
159
259
  envvar="RECCE_SHARE_URL",
160
260
  hidden=True,
161
261
  ),
262
+ click.option(
263
+ "--session-id",
264
+ help="The session ID triggers this instance.",
265
+ type=click.STRING,
266
+ envvar=["RECCE_SESSION_ID", "RECCE_SNAPSHOT_ID"], # Backward compatibility with RECCE_SNAPSHOT_ID
267
+ hidden=True,
268
+ ),
162
269
  ]
163
270
 
164
271
 
@@ -371,18 +478,23 @@ def diff(sql, primary_keys: List[str] = None, keep_shape: bool = False, keep_equ
371
478
  @click.option("--host", default="localhost", show_default=True, help="The host to bind to.")
372
479
  @click.option("--port", default=8000, show_default=True, help="The port to bind to.", type=int)
373
480
  @click.option("--lifetime", default=0, show_default=True, help="The lifetime of the server in seconds.", type=int)
374
- @click.option("--review", is_flag=True, help="Open the state file in the review mode.")
375
- @click.option("--single-env", is_flag=True, help="Launch in single environment mode directly.")
376
481
  @click.option(
377
- "--api-token", help="The personal token generated by Recce Cloud.", type=click.STRING, envvar="RECCE_API_TOKEN"
482
+ "--idle-timeout",
483
+ default=0,
484
+ show_default=True,
485
+ help="The idle timeout in seconds. If 0, idle timeout is disabled. Maximum value is capped by lifetime.",
486
+ type=int,
378
487
  )
488
+ @click.option("--review", is_flag=True, help="Open the state file in the review mode.")
489
+ @click.option("--single-env", is_flag=True, help="Launch in single environment mode directly.")
379
490
  @add_options(dbt_related_options)
380
491
  @add_options(sqlmesh_related_options)
381
492
  @add_options(recce_options)
382
493
  @add_options(recce_dbt_artifact_dir_options)
383
494
  @add_options(recce_cloud_options)
495
+ @add_options(recce_cloud_auth_options)
384
496
  @add_options(recce_hidden_options)
385
- def server(host, port, lifetime, state_file=None, **kwargs):
497
+ def server(host, port, lifetime, idle_timeout=0, state_file=None, **kwargs):
386
498
  """
387
499
  Launch the recce server
388
500
 
@@ -408,11 +520,6 @@ def server(host, port, lifetime, state_file=None, **kwargs):
408
520
  recce server --cloud
409
521
  recce server --review --cloud
410
522
 
411
- \b
412
- # Launch the server using the state from a shared URL. (Requires Recce API token)
413
- export RECCE_API_TOKEN=<your-recce-api-token>
414
- recce server --cloud --share-url <share-url>
415
-
416
523
  """
417
524
 
418
525
  from rich.console import Console
@@ -423,15 +530,23 @@ def server(host, port, lifetime, state_file=None, **kwargs):
423
530
  RecceConfig(config_file=kwargs.get("config"))
424
531
 
425
532
  handle_debug_flag(**kwargs)
533
+ patch_derived_args(kwargs)
534
+
426
535
  server_mode = kwargs.get("mode") if kwargs.get("mode") else RecceServerMode.server
427
536
  is_review = kwargs.get("review", False)
428
537
  is_cloud = kwargs.get("cloud", False)
429
- flag = {}
538
+ flag = {
539
+ "single_env_onboarding": False,
540
+ "show_relaunch_hint": False,
541
+ "preview": False,
542
+ "read_only": False,
543
+ }
430
544
  console = Console()
431
- cloud_options = None
432
545
 
546
+ # Prepare API token
433
547
  try:
434
548
  api_token = prepare_api_token(**kwargs)
549
+ kwargs["api_token"] = api_token
435
550
  except RecceConfigException:
436
551
  show_invalid_api_token_message()
437
552
  exit(1)
@@ -439,102 +554,33 @@ def server(host, port, lifetime, state_file=None, **kwargs):
439
554
  "api_token": api_token,
440
555
  }
441
556
 
442
- share_url = kwargs.get("share_url")
443
- if share_url:
444
- share_id = share_url.split("/")[-1]
445
- if not share_id:
446
- console.print("[[red]Error[/red]] Invalid share URL format.")
447
- exit(1)
448
-
449
- if server_mode == RecceServerMode.server:
450
- flag = {"single_env_onboarding": False, "show_relaunch_hint": False}
451
- if is_cloud:
452
- if share_url:
453
- # recce server --cloud --share-url <share-url>
454
- # Use state file stored for the share url
455
- # Forces use of the review mode.
456
- is_review = kwargs["review"] = True
457
- cloud_options = {
458
- "host": kwargs.get("state_file_host"),
459
- "api_token": api_token,
460
- "share_id": share_id,
461
- }
462
- else:
463
- # recce server --cloud
464
- # recce server --cloud --review
465
- # Use state file stored for the PR of the current branch
466
- cloud_options = {
467
- "host": kwargs.get("state_file_host"),
468
- "github_token": kwargs.get("cloud_token"),
469
- "password": kwargs.get("password"),
470
- }
471
-
472
- # Check Single Environment Onboarding Mode if the review mode is False
557
+ # Check Single Environment Onboarding Mode if not in cloud mode and not in review mode
558
+ if not is_cloud and not is_review:
473
559
  project_dir_path = Path(kwargs.get("project_dir") or "./")
474
560
  target_base_path = project_dir_path.joinpath(Path(kwargs.get("target_base_path", "target-base")))
475
- if not target_base_path.is_dir() and not is_review:
561
+ if not target_base_path.is_dir():
476
562
  # Mark as single env onboarding mode if user provides the target-path only
477
563
  flag["single_env_onboarding"] = True
478
564
  flag["show_relaunch_hint"] = True
479
565
  # Use the target path as the base path
480
566
  kwargs["target_base_path"] = kwargs.get("target_path")
481
- elif server_mode == RecceServerMode.preview:
482
- if is_cloud:
483
- # recce server --cloud --share-url <share-url> --mode preview
484
- # Use state file stored for the share url
485
- #
486
- # Preview mode disable these features
487
- # - run query
488
- #
489
- # Usage:
490
- # Used in cloud managed instance. For cloud onboarding to preview the uploaded artifacts.
491
- cloud_options = {
492
- "host": kwargs.get("state_file_host"),
493
- "api_token": api_token,
494
- "share_id": share_id,
495
- }
496
- else:
497
- # recce server --mode preview recce_state.json
498
- if state_file is None:
499
- console.print("[[red]Error[/red]] The state_file is required in 'Preview' mode.")
500
- console.print("Please provide recce_state json file exported by Recce OSS.")
501
- exit(1)
502
- is_review = kwargs["review"] = True
503
- flag = {
504
- "preview": True,
505
- }
567
+
568
+ # Server mode:
569
+ #
570
+ # It's used to determine the features disabled in the Web UI. Only used in the cloud-managed recce instances.
571
+ #
572
+ # Read-Only: No run query, no checklist
573
+ # Preview (Metadata-Only): No run query
574
+ if server_mode == RecceServerMode.preview:
575
+ flag["preview"] = True
506
576
  elif server_mode == RecceServerMode.read_only:
507
- if is_cloud:
508
- # recce server --cloud --share-url <share-url> --mode read-only
509
- # Use state file stored for the share url
510
- #
511
- # Read-only mode disable these features
512
- # - run query
513
- # - use checklist
514
- # - share
515
- #
516
- # Usage:
517
- # Used in cloud managed instance. Launch when user click a share link.
518
- cloud_options = {
519
- "host": kwargs.get("state_file_host"),
520
- "api_token": api_token,
521
- "share_id": share_id,
522
- }
523
- else:
524
- # recce server --mode read-only recce_state.json
525
- if state_file is None:
526
- console.print("[[red]Error[/red]] The state_file is required in 'Read-Only' mode.")
527
- console.print("Please provide recce_state json file exported by Recce OSS.")
528
- exit(1)
529
- is_review = kwargs["review"] = True
530
- flag = {
531
- "read_only": True,
532
- }
577
+ flag["read_only"] = True
533
578
 
534
579
  # Onboarding State logic update here
535
580
  update_onboarding_state(api_token, flag.get("single_env_onboarding"))
536
581
 
537
- state_loader = create_state_loader(is_review, is_cloud, state_file, cloud_options)
582
+ # Create state loader using shared function
583
+ state_loader = create_state_loader_by_args(state_file, **kwargs)
538
584
 
539
585
  if not state_loader.verify():
540
586
  error, hint = state_loader.error_and_hint
@@ -576,6 +622,22 @@ def server(host, port, lifetime, state_file=None, **kwargs):
576
622
  else:
577
623
  console.rule("Recce Server")
578
624
 
625
+ # Validate idle_timeout: cap at lifetime if it exceeds lifetime
626
+ if idle_timeout > 0:
627
+ # If lifetime is set (> 0) and idle_timeout exceeds it, cap to lifetime
628
+ if lifetime > 0 and idle_timeout > lifetime:
629
+ effective_idle_timeout = lifetime
630
+ console.print(
631
+ f"[[yellow]Warning[/yellow]] idle_timeout ({idle_timeout}s) exceeds lifetime ({lifetime}s). "
632
+ f"Capping idle_timeout to {effective_idle_timeout}s."
633
+ )
634
+ else:
635
+ # Use idle_timeout as-is (either lifetime is 0, or idle_timeout <= lifetime)
636
+ effective_idle_timeout = idle_timeout
637
+ else:
638
+ # idle_timeout is 0 or negative, disable idle timeout
639
+ effective_idle_timeout = 0
640
+
579
641
  state = AppState(
580
642
  command=server_mode,
581
643
  state_loader=state_loader,
@@ -583,7 +645,10 @@ def server(host, port, lifetime, state_file=None, **kwargs):
583
645
  flag=flag,
584
646
  auth_options=auth_options,
585
647
  lifetime=lifetime,
648
+ idle_timeout=effective_idle_timeout,
586
649
  share_url=kwargs.get("share_url"),
650
+ organization_name=os.environ.get("RECCE_SESSION_ORGANIZATION_NAME"),
651
+ web_url=os.environ.get("RECCE_CLOUD_WEB_URL"),
587
652
  )
588
653
  app.state = state
589
654
 
@@ -831,7 +896,7 @@ def purge(**kwargs):
831
896
 
832
897
  try:
833
898
  console.rule("Check Recce State from Cloud")
834
- state_loader = RecceStateLoader(
899
+ state_loader = create_state_loader(
835
900
  review_mode=False, cloud_mode=True, state_file=None, cloud_options=cloud_options
836
901
  )
837
902
  except Exception:
@@ -1187,9 +1252,287 @@ def download_base_artifacts(**kwargs):
1187
1252
  password = kwargs.get("password")
1188
1253
  target_path = kwargs.get("target_path")
1189
1254
  branch = kwargs.get("branch")
1255
+ # If recce can't infer default branch from "GITHUB_BASE_REF" and current_default_branch()
1256
+ if branch is None:
1257
+ console.print(
1258
+ "[[red]Error[/red]] Please provide your base branch name with '--branch' to download the base " "artifacts."
1259
+ )
1260
+ exit(1)
1261
+
1190
1262
  return _download_artifacts(branch, cloud_token, console, kwargs, password, target_path)
1191
1263
 
1192
1264
 
1265
+ @cloud.command(cls=TrackCommand)
1266
+ @click.option("--cloud-token", help="The GitHub token used by Recce Cloud.", type=click.STRING, envvar="GITHUB_TOKEN")
1267
+ @click.option(
1268
+ "--branch",
1269
+ "-b",
1270
+ help="The branch to delete artifacts from.",
1271
+ type=click.STRING,
1272
+ envvar="GITHUB_HEAD_REF",
1273
+ default=current_branch(),
1274
+ show_default=True,
1275
+ )
1276
+ @click.option("--force", "-f", help="Bypasses the confirmation prompt. Delete the artifacts directly.", is_flag=True)
1277
+ @add_options(recce_options)
1278
+ def delete_artifacts(**kwargs):
1279
+ """
1280
+ Delete the dbt artifacts from cloud
1281
+
1282
+ Delete the dbt artifacts (metadata.json, catalog.json) from Recce Cloud for the given branch.
1283
+ This will permanently remove the artifacts from the cloud storage.
1284
+
1285
+ By default, the artifacts are deleted from the current branch. You can specify the branch using the --branch option.
1286
+ """
1287
+ from rich.console import Console
1288
+
1289
+ console = Console()
1290
+ cloud_token = kwargs.get("cloud_token")
1291
+ branch = kwargs.get("branch")
1292
+ force = kwargs.get("force", False)
1293
+
1294
+ if not force:
1295
+ if not click.confirm(f'Do you want to delete artifacts from branch "{branch}"?'):
1296
+ console.print("Deletion cancelled.")
1297
+ return 0
1298
+
1299
+ try:
1300
+ delete_dbt_artifacts(branch=branch, token=cloud_token, debug=kwargs.get("debug", False))
1301
+ console.print(f"[[green]Success[/green]] Artifacts deleted from branch: {branch}")
1302
+ return 0
1303
+ except click.exceptions.Abort:
1304
+ pass
1305
+ except RecceCloudException as e:
1306
+ console.print("[[red]Error[/red]] Failed to delete the dbt artifacts from cloud.")
1307
+ console.print(f"Reason: {e.reason}")
1308
+ exit(1)
1309
+ except Exception as e:
1310
+ console.print("[[red]Error[/red]] Failed to delete the dbt artifacts from cloud.")
1311
+ console.print(f"Reason: {e}")
1312
+ exit(1)
1313
+
1314
+
1315
+ @cloud.command(cls=TrackCommand, name="list-organizations")
1316
+ @click.option("--api-token", help="The Recce Cloud API token.", type=click.STRING, envvar="RECCE_API_TOKEN")
1317
+ @add_options(recce_options)
1318
+ def list_organizations(**kwargs):
1319
+ """
1320
+ List organizations from Recce Cloud
1321
+
1322
+ Lists all organizations that the authenticated user has access to.
1323
+ """
1324
+ from rich.console import Console
1325
+ from rich.table import Table
1326
+
1327
+ console = Console()
1328
+ handle_debug_flag(**kwargs)
1329
+
1330
+ try:
1331
+ api_token = prepare_api_token(**kwargs)
1332
+ except RecceConfigException:
1333
+ show_invalid_api_token_message()
1334
+ exit(1)
1335
+
1336
+ try:
1337
+ from recce.util.recce_cloud import RecceCloud
1338
+
1339
+ cloud = RecceCloud(api_token)
1340
+ organizations = cloud.list_organizations()
1341
+
1342
+ if not organizations:
1343
+ console.print("No organizations found.")
1344
+ return
1345
+
1346
+ table = Table(title="Organizations")
1347
+ table.add_column("ID", style="cyan")
1348
+ table.add_column("Name", style="green")
1349
+ table.add_column("Display Name", style="yellow")
1350
+
1351
+ for org in organizations:
1352
+ table.add_row(str(org.get("id", "")), org.get("name", ""), org.get("display_name", ""))
1353
+
1354
+ console.print(table)
1355
+
1356
+ except RecceCloudException as e:
1357
+ console.print(f"[[red]Error[/red]] {e}")
1358
+ exit(1)
1359
+ except Exception as e:
1360
+ console.print(f"[[red]Error[/red]] {e}")
1361
+ exit(1)
1362
+
1363
+
1364
+ @cloud.command(cls=TrackCommand, name="list-projects")
1365
+ @click.option(
1366
+ "--organization",
1367
+ "-o",
1368
+ help="Organization ID (can also be set via RECCE_ORGANIZATION_ID environment variable)",
1369
+ type=click.STRING,
1370
+ envvar="RECCE_ORGANIZATION_ID",
1371
+ )
1372
+ @click.option("--api-token", help="The Recce Cloud API token.", type=click.STRING, envvar="RECCE_API_TOKEN")
1373
+ @add_options(recce_options)
1374
+ def list_projects(**kwargs):
1375
+ """
1376
+ List projects from Recce Cloud
1377
+
1378
+ Lists all projects in the specified organization that the authenticated user has access to.
1379
+
1380
+ Examples:
1381
+
1382
+ # Using environment variable
1383
+ export RECCE_ORGANIZATION_ID=8
1384
+ recce cloud list-projects
1385
+
1386
+ # Using command line argument
1387
+ recce cloud list-projects --organization 8
1388
+
1389
+ # Override environment variable
1390
+ export RECCE_ORGANIZATION_ID=8
1391
+ recce cloud list-projects --organization 10
1392
+ """
1393
+ from rich.console import Console
1394
+ from rich.table import Table
1395
+
1396
+ console = Console()
1397
+ handle_debug_flag(**kwargs)
1398
+
1399
+ try:
1400
+ api_token = prepare_api_token(**kwargs)
1401
+ except RecceConfigException:
1402
+ show_invalid_api_token_message()
1403
+ exit(1)
1404
+
1405
+ organization = kwargs.get("organization")
1406
+ if not organization:
1407
+ console.print("[[red]Error[/red]] Organization ID is required. Please provide it via:")
1408
+ console.print(" --organization <id> or set RECCE_ORGANIZATION_ID environment variable")
1409
+ exit(1)
1410
+
1411
+ try:
1412
+ from recce.util.recce_cloud import RecceCloud
1413
+
1414
+ cloud = RecceCloud(api_token)
1415
+ projects = cloud.list_projects(organization)
1416
+
1417
+ if not projects:
1418
+ console.print(f"No projects found in organization {organization}.")
1419
+ return
1420
+
1421
+ table = Table(title=f"Projects in Organization {organization}")
1422
+ table.add_column("ID", style="cyan")
1423
+ table.add_column("Name", style="green")
1424
+ table.add_column("Display Name", style="yellow")
1425
+
1426
+ for project in projects:
1427
+ table.add_row(str(project.get("id", "")), project.get("name", ""), project.get("display_name", ""))
1428
+
1429
+ console.print(table)
1430
+
1431
+ except RecceCloudException as e:
1432
+ console.print(f"[[red]Error[/red]] {e}")
1433
+ exit(1)
1434
+ except Exception as e:
1435
+ console.print(f"[[red]Error[/red]] {e}")
1436
+ exit(1)
1437
+
1438
+
1439
+ @cloud.command(cls=TrackCommand, name="list-sessions")
1440
+ @click.option(
1441
+ "--organization",
1442
+ "-o",
1443
+ help="Organization ID (can also be set via RECCE_ORGANIZATION_ID environment variable)",
1444
+ type=click.STRING,
1445
+ envvar="RECCE_ORGANIZATION_ID",
1446
+ )
1447
+ @click.option(
1448
+ "--project",
1449
+ "-p",
1450
+ help="Project ID (can also be set via RECCE_PROJECT_ID environment variable)",
1451
+ type=click.STRING,
1452
+ envvar="RECCE_PROJECT_ID",
1453
+ )
1454
+ @click.option("--api-token", help="The Recce Cloud API token.", type=click.STRING, envvar="RECCE_API_TOKEN")
1455
+ @add_options(recce_options)
1456
+ def list_sessions(**kwargs):
1457
+ """
1458
+ List sessions from Recce Cloud
1459
+
1460
+ Lists all sessions in the specified project that the authenticated user has access to.
1461
+
1462
+ Examples:
1463
+
1464
+ # Using environment variables
1465
+ export RECCE_ORGANIZATION_ID=8
1466
+ export RECCE_PROJECT_ID=7
1467
+ recce cloud list-sessions
1468
+
1469
+ # Using command line arguments
1470
+ recce cloud list-sessions --organization 8 --project 7
1471
+
1472
+ # Mixed usage (env + CLI override)
1473
+ export RECCE_ORGANIZATION_ID=8
1474
+ recce cloud list-sessions --project 7
1475
+
1476
+ # Override environment variables
1477
+ export RECCE_ORGANIZATION_ID=8
1478
+ export RECCE_PROJECT_ID=7
1479
+ recce cloud list-sessions --organization 10 --project 9
1480
+ """
1481
+ from rich.console import Console
1482
+ from rich.table import Table
1483
+
1484
+ console = Console()
1485
+ handle_debug_flag(**kwargs)
1486
+
1487
+ try:
1488
+ api_token = prepare_api_token(**kwargs)
1489
+ except RecceConfigException:
1490
+ show_invalid_api_token_message()
1491
+ exit(1)
1492
+
1493
+ organization = kwargs.get("organization")
1494
+ project = kwargs.get("project")
1495
+
1496
+ # Validate required parameters
1497
+ if not organization:
1498
+ console.print("[[red]Error[/red]] Organization ID is required. Please provide it via:")
1499
+ console.print(" --organization <id> or set RECCE_ORGANIZATION_ID environment variable")
1500
+ exit(1)
1501
+
1502
+ if not project:
1503
+ console.print("[[red]Error[/red]] Project ID is required. Please provide it via:")
1504
+ console.print(" --project <id> or set RECCE_PROJECT_ID environment variable")
1505
+ exit(1)
1506
+
1507
+ try:
1508
+ from recce.util.recce_cloud import RecceCloud
1509
+
1510
+ cloud = RecceCloud(api_token)
1511
+ sessions = cloud.list_sessions(organization, project)
1512
+
1513
+ if not sessions:
1514
+ console.print(f"No sessions found in project {project}.")
1515
+ return
1516
+
1517
+ table = Table(title=f"Sessions in Project {project}")
1518
+ table.add_column("ID", style="cyan")
1519
+ table.add_column("Name", style="green")
1520
+ table.add_column("Is Base", style="yellow")
1521
+
1522
+ for session in sessions:
1523
+ is_base = "✓" if session.get("is_base", False) else ""
1524
+ table.add_row(session.get("id", ""), session.get("name", ""), is_base)
1525
+
1526
+ console.print(table)
1527
+
1528
+ except RecceCloudException as e:
1529
+ console.print(f"[[red]Error[/red]] {e}")
1530
+ exit(1)
1531
+ except Exception as e:
1532
+ console.print(f"[[red]Error[/red]] {e}")
1533
+ exit(1)
1534
+
1535
+
1193
1536
  @cli.group("github", short_help="GitHub related commands", hidden=True)
1194
1537
  def github(**kwargs):
1195
1538
  pass
@@ -1219,7 +1562,10 @@ def artifact(**kwargs):
1219
1562
  @cli.command(cls=TrackCommand)
1220
1563
  @click.argument("state_file", type=click.Path(exists=True))
1221
1564
  @click.option(
1222
- "--api-token", help="The personal token generated by Recce Cloud.", type=click.STRING, envvar="RECCE_API_TOKEN"
1565
+ "--api-token",
1566
+ help="The personal token generated by Recce Cloud.",
1567
+ type=click.STRING,
1568
+ envvar="RECCE_API_TOKEN",
1223
1569
  )
1224
1570
  def share(state_file, **kwargs):
1225
1571
  """
@@ -1277,6 +1623,100 @@ def share(state_file, **kwargs):
1277
1623
  exit(1)
1278
1624
 
1279
1625
 
1626
+ snapshot_id_option = click.option(
1627
+ "--snapshot-id",
1628
+ help="The snapshot ID to upload artifacts to cloud.",
1629
+ type=click.STRING,
1630
+ envvar=["RECCE_SNAPSHOT_ID", "RECCE_SESSION_ID"],
1631
+ required=True,
1632
+ )
1633
+
1634
+ session_id_option = click.option(
1635
+ "--session-id",
1636
+ help="The session ID to upload artifacts to cloud.",
1637
+ type=click.STRING,
1638
+ envvar=["RECCE_SESSION_ID", "RECCE_SNAPSHOT_ID"],
1639
+ required=True,
1640
+ )
1641
+
1642
+ target_path_option = click.option(
1643
+ "--target-path",
1644
+ help="dbt artifacts directory for your artifacts.",
1645
+ type=click.STRING,
1646
+ default="target",
1647
+ show_default=True,
1648
+ )
1649
+
1650
+
1651
+ @cli.command(cls=TrackCommand, hidden=True)
1652
+ @add_options([session_id_option, target_path_option])
1653
+ @add_options(recce_cloud_auth_options)
1654
+ @add_options(recce_options)
1655
+ def upload_session(**kwargs):
1656
+ """
1657
+ Upload target/manifest.json and target/catalog.json to the specific session ID
1658
+
1659
+ Upload the dbt artifacts (manifest.json, catalog.json) to Recce Cloud for the given session ID.
1660
+ This allows you to associate artifacts with a specific session for later use.
1661
+
1662
+ Examples:\n
1663
+
1664
+ \b
1665
+ # Upload artifacts to a session ID
1666
+ recce upload-session --session-id <session-id>
1667
+
1668
+ \b
1669
+ # Upload artifacts from custom target path to a session ID
1670
+ recce upload-session --session-id <session-id> --target-path my-target
1671
+ """
1672
+ from rich.console import Console
1673
+
1674
+ console = Console()
1675
+ handle_debug_flag(**kwargs)
1676
+
1677
+ # Initialize Recce Config
1678
+ RecceConfig(config_file=kwargs.get("config"))
1679
+
1680
+ try:
1681
+ api_token = prepare_api_token(**kwargs)
1682
+ except RecceConfigException:
1683
+ show_invalid_api_token_message()
1684
+ exit(1)
1685
+
1686
+ session_id = kwargs.get("session_id")
1687
+ target_path = kwargs.get("target_path")
1688
+
1689
+ try:
1690
+ rc = upload_artifacts_to_session(
1691
+ target_path, session_id=session_id, token=api_token, debug=kwargs.get("debug", False)
1692
+ )
1693
+ console.rule("Uploaded Successfully")
1694
+ console.print(
1695
+ f'Uploaded dbt artifacts to Recce Cloud for session ID "{session_id}" from "{os.path.abspath(target_path)}"'
1696
+ )
1697
+ except Exception as e:
1698
+ console.rule("Failed to Upload Session", style="red")
1699
+ console.print(f"[[red]Error[/red]] Failed to upload the dbt artifacts to the session {session_id}.")
1700
+ console.print(f"Reason: {e}")
1701
+ rc = 1
1702
+ return rc
1703
+
1704
+
1705
+ # Backward compatibility for `recce snapshot` command
1706
+ @cli.command(
1707
+ cls=TrackCommand,
1708
+ hidden=True,
1709
+ deprecated=True,
1710
+ help="Upload target/manifest.json and target/catalog.json to the specific snapshot ID",
1711
+ )
1712
+ @add_options([snapshot_id_option, target_path_option])
1713
+ @add_options(recce_cloud_auth_options)
1714
+ @add_options(recce_options)
1715
+ def snapshot(**kwargs):
1716
+ kwargs["session_id"] = kwargs.get("snapshot_id")
1717
+ return upload_session(**kwargs)
1718
+
1719
+
1280
1720
  @cli.command(hidden=True, cls=TrackCommand)
1281
1721
  @click.argument("state_file", required=True)
1282
1722
  @click.option("--host", default="localhost", show_default=True, help="The host to bind to.")
@@ -1290,5 +1730,106 @@ def read_only(ctx, state_file=None, **kwargs):
1290
1730
  ctx.invoke(server, state_file=state_file, **kwargs)
1291
1731
 
1292
1732
 
1733
+ @cli.command(cls=TrackCommand)
1734
+ @click.option("--sse", is_flag=True, default=False, help="Start in HTTP/SSE mode instead of stdio mode")
1735
+ @click.option("--host", default="localhost", help="Host to bind to in SSE mode (default: localhost)")
1736
+ @click.option("--port", default=8000, type=int, help="Port to bind to in SSE mode (default: 8000)")
1737
+ @add_options(dbt_related_options)
1738
+ @add_options(sqlmesh_related_options)
1739
+ @add_options(recce_options)
1740
+ @add_options(recce_dbt_artifact_dir_options)
1741
+ @add_options(recce_cloud_options)
1742
+ @add_options(recce_cloud_auth_options)
1743
+ @add_options(recce_hidden_options)
1744
+ def mcp_server(sse, host, port, **kwargs):
1745
+ """
1746
+ [Experiment] Start the Recce MCP (Model Context Protocol) server
1747
+
1748
+ The MCP server provides an interface for AI assistants and tools to interact
1749
+ with Recce's data validation capabilities. By default, it uses stdio for
1750
+ communication. Use --sse to enable HTTP/Server-Sent Events mode instead.
1751
+
1752
+ Available tools:
1753
+ - get_lineage_diff: Get lineage differences between environments
1754
+ - row_count_diff: Compare row counts between environments
1755
+ - query: Execute SQL queries with dbt templating
1756
+ - query_diff: Compare query results between environments
1757
+ - profile_diff: Generate statistical profiles and compare
1758
+
1759
+ Examples:\n
1760
+
1761
+ \b
1762
+ # Start the MCP server in stdio mode (default)
1763
+ recce mcp-server
1764
+
1765
+ \b
1766
+ # Start in HTTP/SSE mode on default port 8000
1767
+ recce mcp-server --sse
1768
+
1769
+ \b
1770
+ # Start in HTTP/SSE mode with custom host and port
1771
+ recce mcp-server --sse --host 0.0.0.0 --port 9000
1772
+
1773
+ \b
1774
+ # Start with custom dbt configuration
1775
+ recce mcp-server --target prod --project-dir ./my_project
1776
+
1777
+ SSE Connection URL (when using --sse): http://<host>:<port>/sse
1778
+ """
1779
+ from rich.console import Console
1780
+
1781
+ console = Console()
1782
+ try:
1783
+ # Import here to avoid import errors if mcp is not installed
1784
+ from recce.mcp_server import run_mcp_server
1785
+ except ImportError as e:
1786
+ console.print(f"[[red]Error[/red]] Failed to import MCP server: {e}")
1787
+ console.print(r"Please install the MCP package: pip install 'recce\[mcp]'")
1788
+ exit(1)
1789
+
1790
+ # Initialize Recce Config
1791
+ RecceConfig(config_file=kwargs.get("config"))
1792
+
1793
+ handle_debug_flag(**kwargs)
1794
+ patch_derived_args(kwargs)
1795
+
1796
+ # Prepare API token
1797
+ try:
1798
+ api_token = prepare_api_token(**kwargs)
1799
+ kwargs["api_token"] = api_token
1800
+ except RecceConfigException:
1801
+ show_invalid_api_token_message()
1802
+ exit(1)
1803
+
1804
+ # Create state loader using shared function (if cloud mode is enabled)
1805
+ is_cloud = kwargs.get("cloud", False)
1806
+ if is_cloud:
1807
+ state_loader = create_state_loader_by_args(None, **kwargs)
1808
+ kwargs["state_loader"] = state_loader
1809
+
1810
+ try:
1811
+ if sse:
1812
+ console.print(f"Starting Recce MCP Server in HTTP/SSE mode on {host}:{port}...")
1813
+ console.print(f"SSE endpoint: http://{host}:{port}/sse")
1814
+ console.print("Available tools: get_lineage_diff, row_count_diff, query, query_diff, profile_diff")
1815
+ else:
1816
+ console.print("Starting Recce MCP Server in stdio mode...")
1817
+ console.print("Available tools: get_lineage_diff, row_count_diff, query, query_diff, profile_diff")
1818
+
1819
+ # Run the server (stdio or SSE based on --sse flag)
1820
+ asyncio.run(run_mcp_server(sse=sse, host=host, port=port, **kwargs))
1821
+ except (asyncio.CancelledError, KeyboardInterrupt):
1822
+ # Graceful shutdown (e.g., Ctrl+C)
1823
+ console.print("[yellow]MCP Server interrupted[/yellow]")
1824
+ exit(0)
1825
+ except Exception as e:
1826
+ console.print(f"[[red]Error[/red]] Failed to start MCP server: {e}")
1827
+ if kwargs.get("debug"):
1828
+ import traceback
1829
+
1830
+ traceback.print_exc()
1831
+ exit(1)
1832
+
1833
+
1293
1834
  if __name__ == "__main__":
1294
1835
  cli()