recce-nightly 1.10.0.20250629__py3-none-any.whl → 1.25.0.20251112a2066__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.
Files changed (168) hide show
  1. recce/VERSION +1 -1
  2. recce/__init__.py +5 -0
  3. recce/adapter/dbt_adapter/__init__.py +116 -74
  4. recce/artifact.py +76 -3
  5. recce/cli.py +665 -69
  6. recce/config.py +2 -2
  7. recce/connect_to_cloud.py +1 -1
  8. recce/core.py +3 -3
  9. recce/data/404.html +1 -22
  10. recce/data/__next.__PAGE__.txt +10 -0
  11. recce/data/__next._full.txt +23 -0
  12. recce/data/__next._index.txt +8 -0
  13. recce/data/__next._tree.txt +12 -0
  14. recce/data/_next/static/6LypcDXgyuSaiSCrsmUub/_buildManifest.js +11 -0
  15. recce/data/_next/static/6LypcDXgyuSaiSCrsmUub/_clientMiddlewareManifest.json +1 -0
  16. recce/data/_next/static/chunks/0a2b2dd4b57049c2.js +1 -0
  17. recce/data/_next/static/chunks/19c10d219a6a21ff.js +1 -0
  18. recce/data/_next/static/chunks/24fd885c7180a612.js +1 -0
  19. recce/data/_next/static/chunks/27e66b2eab4adc32.js +19 -0
  20. recce/data/_next/static/chunks/71f88fcc615bf282.js +1 -0
  21. recce/data/_next/static/chunks/917619ab62a32388.js +1 -0
  22. recce/data/_next/static/chunks/93ba5a62932b704f.js +4 -0
  23. recce/data/_next/static/chunks/a43a2a5e06d5a92b.js +1 -0
  24. recce/data/_next/static/chunks/a6c78b24bd8b84fc.js +1 -0
  25. recce/data/_next/static/chunks/b2610ba997ff8c4f.js +110 -0
  26. recce/data/_next/static/chunks/ba2d87265a68599d.css +2 -0
  27. recce/data/_next/static/chunks/c117fd1c1382dd83.js +11 -0
  28. recce/data/_next/static/chunks/c9425ca46eebdde9.js +1 -0
  29. recce/data/_next/static/chunks/cc8a9eadba012be0.css +6 -0
  30. recce/data/_next/static/chunks/e124bccf574a3361.css +1 -0
  31. recce/data/_next/static/chunks/e392ad92847c3e17.js +1 -0
  32. recce/data/_next/static/chunks/e4ce95efe88dae79.js +11 -0
  33. recce/data/_next/static/chunks/e69c777814fea6ed.js +2 -0
  34. recce/data/_next/static/chunks/turbopack-21cfd73037ff57ab.js +3 -0
  35. recce/data/_next/static/media/favicon.a8d38d84.ico +0 -0
  36. recce/data/_next/static/media/montserrat-cyrillic-800-normal.d80d830d.woff2 +0 -0
  37. recce/data/_next/static/media/{montserrat-cyrillic-800-normal.bd5c9f50.woff → montserrat-cyrillic-800-normal.f9d58125.woff} +0 -0
  38. recce/data/_next/static/media/montserrat-cyrillic-ext-800-normal.076c2a93.woff2 +0 -0
  39. recce/data/_next/static/media/montserrat-latin-800-normal.cde454cc.woff2 +0 -0
  40. recce/data/_next/static/media/{montserrat-latin-800-normal.fc315020.woff → montserrat-latin-800-normal.d5761935.woff} +0 -0
  41. recce/data/_next/static/media/montserrat-latin-ext-800-normal.40ec0659.woff2 +0 -0
  42. recce/data/_next/static/media/{montserrat-latin-ext-800-normal.2e5381b2.woff → montserrat-latin-ext-800-normal.b671449b.woff} +0 -0
  43. recce/data/_next/static/media/{montserrat-vietnamese-800-normal.20c545e6.woff → montserrat-vietnamese-800-normal.9f7b8541.woff} +0 -0
  44. recce/data/_next/static/media/montserrat-vietnamese-800-normal.f9eb854e.woff2 +0 -0
  45. recce/data/_not-found/__next._full.txt +17 -0
  46. recce/data/_not-found/__next._index.txt +8 -0
  47. recce/data/_not-found/__next._not-found.__PAGE__.txt +5 -0
  48. recce/data/_not-found/__next._not-found.txt +4 -0
  49. recce/data/_not-found/__next._tree.txt +10 -0
  50. recce/data/_not-found.html +1 -0
  51. recce/data/_not-found.txt +17 -0
  52. recce/data/auth_callback.html +1 -1
  53. recce/data/index.html +1 -27
  54. recce/data/index.txt +23 -8
  55. recce/event/__init__.py +9 -8
  56. recce/event/collector.py +6 -2
  57. recce/event/track.py +10 -0
  58. recce/github.py +1 -1
  59. recce/mcp_server.py +632 -0
  60. recce/models/types.py +23 -2
  61. recce/pull_request.py +1 -1
  62. recce/run.py +23 -16
  63. recce/server.py +165 -11
  64. recce/state/__init__.py +31 -0
  65. recce/state/cloud.py +632 -0
  66. recce/state/const.py +26 -0
  67. recce/state/local.py +56 -0
  68. recce/state/state.py +119 -0
  69. recce/state/state_loader.py +174 -0
  70. recce/summary.py +2 -1
  71. recce/tasks/dataframe.py +59 -2
  72. recce/tasks/rowcount.py +4 -1
  73. recce/tasks/schema.py +4 -1
  74. recce/tasks/valuediff.py +1 -1
  75. recce/util/api_token.py +11 -2
  76. recce/util/breaking.py +9 -0
  77. recce/util/cll.py +1 -2
  78. recce/util/io.py +2 -2
  79. recce/util/lineage.py +14 -18
  80. recce/util/perf_tracking.py +85 -0
  81. recce/util/recce_cloud.py +229 -5
  82. recce/yaml/__init__.py +2 -2
  83. recce_cloud/__init__.py +15 -0
  84. recce_cloud/api/__init__.py +17 -0
  85. recce_cloud/api/base.py +104 -0
  86. recce_cloud/api/client.py +150 -0
  87. recce_cloud/api/exceptions.py +26 -0
  88. recce_cloud/api/factory.py +63 -0
  89. recce_cloud/api/github.py +72 -0
  90. recce_cloud/api/gitlab.py +78 -0
  91. recce_cloud/artifact.py +57 -0
  92. recce_cloud/ci_providers/__init__.py +9 -0
  93. recce_cloud/ci_providers/base.py +82 -0
  94. recce_cloud/ci_providers/detector.py +147 -0
  95. recce_cloud/ci_providers/github_actions.py +136 -0
  96. recce_cloud/ci_providers/gitlab_ci.py +130 -0
  97. recce_cloud/cli.py +303 -0
  98. recce_cloud/upload.py +213 -0
  99. {recce_nightly-1.10.0.20250629.dist-info → recce_nightly-1.25.0.20251112a2066.dist-info}/METADATA +31 -27
  100. recce_nightly-1.25.0.20251112a2066.dist-info/RECORD +178 -0
  101. {recce_nightly-1.10.0.20250629.dist-info → recce_nightly-1.25.0.20251112a2066.dist-info}/top_level.txt +1 -0
  102. tests/adapter/dbt_adapter/test_dbt_cll.py +68 -17
  103. tests/recce_cloud/__init__.py +0 -0
  104. tests/recce_cloud/test_ci_providers.py +351 -0
  105. tests/recce_cloud/test_cli.py +372 -0
  106. tests/recce_cloud/test_client.py +273 -0
  107. tests/recce_cloud/test_platform_clients.py +279 -0
  108. tests/test_cli.py +106 -3
  109. tests/test_cli_mcp_optional.py +45 -0
  110. tests/test_cloud_listing_cli.py +324 -0
  111. tests/test_core.py +147 -0
  112. tests/test_mcp_server.py +332 -0
  113. tests/test_server.py +6 -6
  114. tests/test_summary.py +14 -6
  115. recce/data/_next/static/Mrb9CZ3toH6Q8xrzNzCrg/_buildManifest.js +0 -1
  116. recce/data/_next/static/chunks/181-acc61ddada3bc0ca.js +0 -43
  117. recce/data/_next/static/chunks/1bff33f1-1ef85cf5e658a751.js +0 -1
  118. recce/data/_next/static/chunks/217-879a84d70f7a907c.js +0 -2
  119. recce/data/_next/static/chunks/29e3cc0d-60045b2e47aa3916.js +0 -1
  120. recce/data/_next/static/chunks/36e1c10d-8e7be4a6c1f6ab2d.js +0 -1
  121. recce/data/_next/static/chunks/3998a672-03adacad07b346ac.js +0 -1
  122. recce/data/_next/static/chunks/3a92ee20-1081c360214f9602.js +0 -1
  123. recce/data/_next/static/chunks/41-f30276c289169376.js +0 -9
  124. recce/data/_next/static/chunks/450c323b-fd94e7ffaa4a5efa.js +0 -1
  125. recce/data/_next/static/chunks/47d8844f-929aed9b1c73a905.js +0 -1
  126. recce/data/_next/static/chunks/608-3b079b544e5d5f5e.js +0 -15
  127. recce/data/_next/static/chunks/6dc81886-adbfa45836061d79.js +0 -1
  128. recce/data/_next/static/chunks/7a8a3e83-edf6dc64b5d5f0a5.js +0 -1
  129. recce/data/_next/static/chunks/7f27ae6c-d5f0438edd5c2a5b.js +0 -1
  130. recce/data/_next/static/chunks/86730205-cfb14e3f051bab35.js +0 -1
  131. recce/data/_next/static/chunks/8d700b6a.8bb140898499c512.js +0 -1
  132. recce/data/_next/static/chunks/92-68460b15fe448f33.js +0 -1
  133. recce/data/_next/static/chunks/9746af58-a42b7d169cacadf0.js +0 -1
  134. recce/data/_next/static/chunks/a30376cd-de84559016d7e133.js +0 -1
  135. recce/data/_next/static/chunks/app/_not-found/page-01ed58b7f971d311.js +0 -1
  136. recce/data/_next/static/chunks/app/layout-292f035bb0d2a98e.js +0 -1
  137. recce/data/_next/static/chunks/app/page-598f8acc82179d01.js +0 -1
  138. recce/data/_next/static/chunks/b63b1b3f-4282bdcf459e075c.js +0 -1
  139. recce/data/_next/static/chunks/bbda5537-9ec25eb1dd62348a.js +0 -1
  140. recce/data/_next/static/chunks/c132bf7d-08cb668a789d6afd.js +0 -1
  141. recce/data/_next/static/chunks/ce84277d-2e5d1d46910cf052.js +0 -1
  142. recce/data/_next/static/chunks/febdd86e-c6b525341634b860.js +0 -54
  143. recce/data/_next/static/chunks/fee69bc6-2dbccaf9b90474e6.js +0 -1
  144. recce/data/_next/static/chunks/framework-ded83d71b51ce901.js +0 -1
  145. recce/data/_next/static/chunks/main-app-39061b0166c47f55.js +0 -1
  146. recce/data/_next/static/chunks/main-b5b3ae20a1405261.js +0 -1
  147. recce/data/_next/static/chunks/pages/_app-437c455677d62394.js +0 -1
  148. recce/data/_next/static/chunks/pages/_error-e7650df18ca04bde.js +0 -1
  149. recce/data/_next/static/chunks/webpack-7b49d5ba7e3a434d.js +0 -1
  150. recce/data/_next/static/css/17a96168e3a9db13.css +0 -1
  151. recce/data/_next/static/css/35c6679a098e1e34.css +0 -1
  152. recce/data/_next/static/css/951e2e0eea2d4a5b.css +0 -14
  153. recce/data/_next/static/css/a2b12b4ba4227f0a.css +0 -3
  154. recce/data/_next/static/media/montserrat-cyrillic-800-normal.22628180.woff2 +0 -0
  155. recce/data/_next/static/media/montserrat-cyrillic-ext-800-normal.94a63aea.woff2 +0 -0
  156. recce/data/_next/static/media/montserrat-latin-800-normal.6f8fa298.woff2 +0 -0
  157. recce/data/_next/static/media/montserrat-latin-ext-800-normal.013b84f9.woff2 +0 -0
  158. recce/data/_next/static/media/montserrat-vietnamese-800-normal.c0035377.woff2 +0 -0
  159. recce/state.py +0 -786
  160. recce_nightly-1.10.0.20250629.dist-info/RECORD +0 -154
  161. tests/test_state.py +0 -134
  162. /recce/data/_next/static/{Mrb9CZ3toH6Q8xrzNzCrg → 6LypcDXgyuSaiSCrsmUub}/_ssgManifest.js +0 -0
  163. /recce/data/_next/static/chunks/{polyfills-42372ed130431b0a.js → a6dad97d9634a72d.js} +0 -0
  164. /recce/data/_next/static/media/{montserrat-cyrillic-ext-800-normal.e6e0d8d0.woff → montserrat-cyrillic-ext-800-normal.a4fa76b5.woff} +0 -0
  165. /recce/data/_next/static/media/{reload-image.79aabb7d.svg → reload-image.7aa931c7.svg} +0 -0
  166. {recce_nightly-1.10.0.20250629.dist-info → recce_nightly-1.25.0.20251112a2066.dist-info}/WHEEL +0 -0
  167. {recce_nightly-1.10.0.20250629.dist-info → recce_nightly-1.25.0.20251112a2066.dist-info}/entry_points.txt +0 -0
  168. {recce_nightly-1.10.0.20250629.dist-info → recce_nightly-1.25.0.20251112a2066.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,
@@ -18,7 +23,13 @@ from recce.connect_to_cloud import (
18
23
  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
- from recce.state import RecceCloudStateManager, RecceShareStateManager, RecceStateLoader
26
+ from recce.server import RecceServerMode
27
+ from recce.state import (
28
+ CloudStateLoader,
29
+ FileStateLoader,
30
+ RecceCloudStateManager,
31
+ RecceShareStateManager,
32
+ )
22
33
  from recce.summary import generate_markdown_summary
23
34
  from recce.util.api_token import prepare_api_token, show_invalid_api_token_message
24
35
  from recce.util.logger import CustomFormatter
@@ -39,9 +50,13 @@ def create_state_loader(review_mode, cloud_mode, state_file, cloud_options):
39
50
  console = Console()
40
51
 
41
52
  try:
42
- return RecceStateLoader(
43
- 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)
44
57
  )
58
+ state_loader.load()
59
+ return state_loader
45
60
  except RecceCloudException as e:
46
61
  console.print("[[red]Error[/red]] Failed to load recce state file")
47
62
  console.print(f"Reason: {e.reason}")
@@ -52,6 +67,75 @@ def create_state_loader(review_mode, cloud_mode, state_file, cloud_options):
52
67
  exit(1)
53
68
 
54
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
+
55
139
  def handle_debug_flag(**kwargs):
56
140
  if kwargs.get("debug"):
57
141
  import logging
@@ -60,6 +144,14 @@ def handle_debug_flag(**kwargs):
60
144
  ch.setFormatter(CustomFormatter())
61
145
  logging.basicConfig(handlers=[ch], level=logging.DEBUG)
62
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
+
63
155
 
64
156
  def add_options(options):
65
157
  def _add_options(func):
@@ -129,6 +221,15 @@ recce_cloud_options = [
129
221
  ),
130
222
  ]
131
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
+
132
233
  recce_dbt_artifact_dir_options = [
133
234
  click.option(
134
235
  "--target-path",
@@ -144,6 +245,29 @@ recce_dbt_artifact_dir_options = [
144
245
  ),
145
246
  ]
146
247
 
248
+ recce_hidden_options = [
249
+ click.option(
250
+ "--mode",
251
+ envvar="RECCE_SERVER_MODE",
252
+ type=click.Choice(RecceServerMode.available_members(), case_sensitive=False),
253
+ hidden=True,
254
+ ),
255
+ click.option(
256
+ "--share-url",
257
+ help="The share URL triggers this instance.",
258
+ type=click.STRING,
259
+ envvar="RECCE_SHARE_URL",
260
+ hidden=True,
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
+ ),
269
+ ]
270
+
147
271
 
148
272
  def _execute_sql(context, sql_template, base=False):
149
273
  try:
@@ -228,8 +352,9 @@ def debug(**kwargs):
228
352
 
229
353
  return [True, manifest_is_ready, catalog_is_ready]
230
354
 
231
- target_path = Path(kwargs.get("target_path", "target"))
232
- target_base_path = Path(kwargs.get("target_base_path", "target-base"))
355
+ project_dir_path = Path(kwargs.get("project_dir") or "./")
356
+ target_path = project_dir_path.joinpath(Path(kwargs.get("target_path", "target")))
357
+ target_base_path = project_dir_path.joinpath(Path(kwargs.get("target_base_path", "target-base")))
233
358
 
234
359
  curr_is_ready = check_artifacts("Development", target_path)
235
360
  base_is_ready = check_artifacts("Base", target_base_path)
@@ -353,17 +478,23 @@ def diff(sql, primary_keys: List[str] = None, keep_shape: bool = False, keep_equ
353
478
  @click.option("--host", default="localhost", show_default=True, help="The host to bind to.")
354
479
  @click.option("--port", default=8000, show_default=True, help="The port to bind to.", type=int)
355
480
  @click.option("--lifetime", default=0, show_default=True, help="The lifetime of the server in seconds.", type=int)
356
- @click.option("--review", is_flag=True, help="Open the state file in the review mode.")
357
- @click.option("--single-env", is_flag=True, help="Launch in single environment mode directly.")
358
481
  @click.option(
359
- "--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,
360
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.")
361
490
  @add_options(dbt_related_options)
362
491
  @add_options(sqlmesh_related_options)
363
492
  @add_options(recce_options)
364
493
  @add_options(recce_dbt_artifact_dir_options)
365
494
  @add_options(recce_cloud_options)
366
- def server(host, port, lifetime, state_file=None, **kwargs):
495
+ @add_options(recce_cloud_auth_options)
496
+ @add_options(recce_hidden_options)
497
+ def server(host, port, lifetime, idle_timeout=0, state_file=None, **kwargs):
367
498
  """
368
499
  Launch the recce server
369
500
 
@@ -384,7 +515,8 @@ def server(host, port, lifetime, state_file=None, **kwargs):
384
515
  recce server --review recce_state.json
385
516
 
386
517
  \b
387
- # Launch the server and synchronize the state with the cloud
518
+ # Launch the server using the state from the PR of your current branch. (Requires GitHub token)
519
+ export GITHUB_TOKEN=<your-github-token>
388
520
  recce server --cloud
389
521
  recce server --review --cloud
390
522
 
@@ -398,38 +530,57 @@ def server(host, port, lifetime, state_file=None, **kwargs):
398
530
  RecceConfig(config_file=kwargs.get("config"))
399
531
 
400
532
  handle_debug_flag(**kwargs)
533
+ patch_derived_args(kwargs)
534
+
535
+ server_mode = kwargs.get("mode") if kwargs.get("mode") else RecceServerMode.server
401
536
  is_review = kwargs.get("review", False)
402
537
  is_cloud = kwargs.get("cloud", False)
538
+ flag = {
539
+ "single_env_onboarding": False,
540
+ "show_relaunch_hint": False,
541
+ "preview": False,
542
+ "read_only": False,
543
+ }
403
544
  console = Console()
404
- cloud_options = None
405
- flag = {"single_env_onboarding": False, "show_relaunch_hint": False}
406
- if is_cloud:
407
- cloud_options = {
408
- "host": kwargs.get("state_file_host"),
409
- "token": kwargs.get("cloud_token"),
410
- "password": kwargs.get("password"),
411
- }
412
-
413
- # Check Single Environment Onboarding Mode if the review mode is False
414
- if not Path(kwargs.get("target_base_path", "target-base")).is_dir() and not is_review:
415
- # Mark as single env onboarding mode if user provides the target-path only
416
- flag["single_env_onboarding"] = True
417
- flag["show_relaunch_hint"] = True
418
- # Use the target path as the base path
419
- kwargs["target_base_path"] = kwargs.get("target_path")
420
545
 
421
- auth_options = {}
546
+ # Prepare API token
422
547
  try:
423
548
  api_token = prepare_api_token(**kwargs)
549
+ kwargs["api_token"] = api_token
424
550
  except RecceConfigException:
425
551
  show_invalid_api_token_message()
426
552
  exit(1)
427
- auth_options["api_token"] = api_token
553
+ auth_options = {
554
+ "api_token": api_token,
555
+ }
556
+
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:
559
+ project_dir_path = Path(kwargs.get("project_dir") or "./")
560
+ target_base_path = project_dir_path.joinpath(Path(kwargs.get("target_base_path", "target-base")))
561
+ if not target_base_path.is_dir():
562
+ # Mark as single env onboarding mode if user provides the target-path only
563
+ flag["single_env_onboarding"] = True
564
+ flag["show_relaunch_hint"] = True
565
+ # Use the target path as the base path
566
+ kwargs["target_base_path"] = kwargs.get("target_path")
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
576
+ elif server_mode == RecceServerMode.read_only:
577
+ flag["read_only"] = True
428
578
 
429
579
  # Onboarding State logic update here
430
- update_onboarding_state(api_token, flag["single_env_onboarding"])
580
+ update_onboarding_state(api_token, flag.get("single_env_onboarding"))
431
581
 
432
- 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)
433
584
 
434
585
  if not state_loader.verify():
435
586
  error, hint = state_loader.error_and_hint
@@ -449,9 +600,9 @@ def server(host, port, lifetime, state_file=None, **kwargs):
449
600
  console.print(f"[[red]Error[/red]] {message}")
450
601
  exit(1)
451
602
 
452
- if state_loader.review_mode is True:
603
+ if state_loader.review_mode:
453
604
  console.rule("Recce Server : Review Mode")
454
- elif flag["single_env_onboarding"]:
605
+ elif flag.get("single_env_onboarding"):
455
606
  # Show warning message
456
607
  console.rule("Notice", style="orange3")
457
608
  console.print(
@@ -471,16 +622,39 @@ def server(host, port, lifetime, state_file=None, **kwargs):
471
622
  else:
472
623
  console.rule("Recce Server")
473
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
+
474
641
  state = AppState(
475
- command="server",
642
+ command=server_mode,
476
643
  state_loader=state_loader,
477
644
  kwargs=kwargs,
478
645
  flag=flag,
479
646
  auth_options=auth_options,
480
647
  lifetime=lifetime,
648
+ idle_timeout=effective_idle_timeout,
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"),
481
652
  )
482
653
  app.state = state
483
654
 
655
+ if server_mode == RecceServerMode.read_only:
656
+ set_default_context(RecceContext.load(**kwargs, state_loader=state_loader))
657
+
484
658
  uvicorn.run(app, host=host, port=port, lifespan="on")
485
659
 
486
660
 
@@ -499,6 +673,7 @@ DEFAULT_RECCE_STATE_FILE = "recce_state.json"
499
673
  @click.option("--state-file", help="Path of the import state file.", type=click.Path())
500
674
  @click.option("--summary", help="Path of the summary markdown file.", type=click.Path())
501
675
  @click.option("--skip-query", is_flag=True, help="Skip running the queries for the checks.")
676
+ @click.option("--skip-check", is_flag=True, help="Skip running the checks.")
502
677
  @click.option(
503
678
  "--git-current-branch",
504
679
  help="The git branch of the current environment.",
@@ -551,7 +726,7 @@ def run(output, **kwargs):
551
726
  cloud_options = (
552
727
  {
553
728
  "host": kwargs.get("state_file_host"),
554
- "token": kwargs.get("cloud_token"),
729
+ "github_token": kwargs.get("cloud_token"),
555
730
  "password": kwargs.get("password"),
556
731
  }
557
732
  if cloud_mode
@@ -625,7 +800,7 @@ def summary(state_file, **kwargs):
625
800
  cloud_options = (
626
801
  {
627
802
  "host": kwargs.get("state_file_host"),
628
- "token": kwargs.get("cloud_token"),
803
+ "github_token": kwargs.get("cloud_token"),
629
804
  "password": kwargs.get("password"),
630
805
  }
631
806
  if cloud_mode
@@ -714,14 +889,14 @@ def purge(**kwargs):
714
889
  state_loader = None
715
890
  cloud_options = {
716
891
  "host": kwargs.get("state_file_host"),
717
- "token": kwargs.get("cloud_token"),
892
+ "github_token": kwargs.get("cloud_token"),
718
893
  "password": kwargs.get("password"),
719
894
  }
720
895
  force_to_purge = kwargs.get("force", False)
721
896
 
722
897
  try:
723
898
  console.rule("Check Recce State from Cloud")
724
- state_loader = RecceStateLoader(
899
+ state_loader = create_state_loader(
725
900
  review_mode=False, cloud_mode=True, state_file=None, cloud_options=cloud_options
726
901
  )
727
902
  except Exception:
@@ -795,7 +970,7 @@ def upload(state_file, **kwargs):
795
970
  handle_debug_flag(**kwargs)
796
971
  cloud_options = {
797
972
  "host": kwargs.get("state_file_host"),
798
- "token": kwargs.get("cloud_token"),
973
+ "github_token": kwargs.get("cloud_token"),
799
974
  "password": kwargs.get("password"),
800
975
  }
801
976
 
@@ -864,7 +1039,7 @@ def download(**kwargs):
864
1039
  filepath = kwargs.get("output")
865
1040
  cloud_options = {
866
1041
  "host": kwargs.get("state_file_host"),
867
- "token": kwargs.get("cloud_token"),
1042
+ "github_token": kwargs.get("cloud_token"),
868
1043
  "password": kwargs.get("password"),
869
1044
  }
870
1045
 
@@ -1077,9 +1252,287 @@ def download_base_artifacts(**kwargs):
1077
1252
  password = kwargs.get("password")
1078
1253
  target_path = kwargs.get("target_path")
1079
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
+
1080
1262
  return _download_artifacts(branch, cloud_token, console, kwargs, password, target_path)
1081
1263
 
1082
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
+
1083
1536
  @cli.group("github", short_help="GitHub related commands", hidden=True)
1084
1537
  def github(**kwargs):
1085
1538
  pass
@@ -1109,7 +1562,10 @@ def artifact(**kwargs):
1109
1562
  @cli.command(cls=TrackCommand)
1110
1563
  @click.argument("state_file", type=click.Path(exists=True))
1111
1564
  @click.option(
1112
- "--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",
1113
1569
  )
1114
1570
  def share(state_file, **kwargs):
1115
1571
  """
@@ -1167,49 +1623,189 @@ def share(state_file, **kwargs):
1167
1623
  exit(1)
1168
1624
 
1169
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
+
1170
1720
  @cli.command(hidden=True, cls=TrackCommand)
1171
1721
  @click.argument("state_file", required=True)
1172
1722
  @click.option("--host", default="localhost", show_default=True, help="The host to bind to.")
1173
1723
  @click.option("--port", default=8000, show_default=True, help="The port to bind to.", type=int)
1174
1724
  @click.option("--lifetime", default=0, show_default=True, help="The lifetime of the server in seconds.", type=int)
1175
1725
  @click.option("--share-url", help="The share URL triggers this instance.", type=click.STRING, envvar="RECCE_SHARE_URL")
1176
- def read_only(host, port, lifetime, state_file=None, **kwargs):
1177
- from rich.console import Console
1726
+ @click.pass_context
1727
+ def read_only(ctx, state_file=None, **kwargs):
1728
+ # Invoke `recce server --mode read-only <state_file> ...
1729
+ kwargs["mode"] = RecceServerMode.read_only
1730
+ ctx.invoke(server, state_file=state_file, **kwargs)
1178
1731
 
1179
- from .server import AppState, app
1732
+
1733
+ @cli.command(cls=TrackCommand)
1734
+ @add_options(dbt_related_options)
1735
+ @add_options(sqlmesh_related_options)
1736
+ @add_options(recce_options)
1737
+ @add_options(recce_dbt_artifact_dir_options)
1738
+ @add_options(recce_cloud_options)
1739
+ @add_options(recce_cloud_auth_options)
1740
+ @add_options(recce_hidden_options)
1741
+ def mcp_server(**kwargs):
1742
+ """
1743
+ [Experiment] Start the Recce MCP (Model Context Protocol) server
1744
+
1745
+ The MCP server provides a stdio-based interface for AI assistants and tools
1746
+ to interact with Recce's data validation capabilities.
1747
+
1748
+ Available tools:
1749
+ - get_lineage_diff: Get lineage differences between environments
1750
+ - row_count_diff: Compare row counts between environments
1751
+ - query: Execute SQL queries with dbt templating
1752
+ - query_diff: Compare query results between environments
1753
+ - profile_diff: Generate statistical profiles and compare
1754
+
1755
+ Examples:\n
1756
+
1757
+ \b
1758
+ # Start the MCP server
1759
+ recce mcp-server
1760
+
1761
+ \b
1762
+ # Start with custom dbt configuration
1763
+ recce mcp-server --target prod --project-dir ./my_project
1764
+ """
1765
+ from rich.console import Console
1180
1766
 
1181
1767
  console = Console()
1768
+ try:
1769
+ # Import here to avoid import errors if mcp is not installed
1770
+ from recce.mcp_server import run_mcp_server
1771
+ except ImportError as e:
1772
+ console.print(f"[[red]Error[/red]] Failed to import MCP server: {e}")
1773
+ console.print(r"Please install the MCP package: pip install 'recce\[mcp]'")
1774
+ exit(1)
1775
+
1776
+ # Initialize Recce Config
1777
+ RecceConfig(config_file=kwargs.get("config"))
1778
+
1182
1779
  handle_debug_flag(**kwargs)
1183
- is_review = True
1184
- is_cloud = False
1185
- cloud_options = None
1186
- flag = {
1187
- "read_only": True,
1188
- }
1189
- state_loader = create_state_loader(is_review, is_cloud, state_file, cloud_options)
1780
+ patch_derived_args(kwargs)
1190
1781
 
1191
- if not state_loader.verify():
1192
- error, hint = state_loader.error_and_hint
1193
- console.print(f"[[red]Error[/red]] {error}")
1194
- console.print(f"{hint}")
1782
+ # Prepare API token
1783
+ try:
1784
+ api_token = prepare_api_token(**kwargs)
1785
+ kwargs["api_token"] = api_token
1786
+ except RecceConfigException:
1787
+ show_invalid_api_token_message()
1195
1788
  exit(1)
1196
1789
 
1197
- result, message = RecceContext.verify_required_artifacts(**kwargs, review=is_review)
1198
- if not result:
1199
- console.print(f"[[red]Error[/red]] {message}")
1200
- exit(1)
1790
+ # Create state loader using shared function (if cloud mode is enabled)
1791
+ is_cloud = kwargs.get("cloud", False)
1792
+ if is_cloud:
1793
+ state_loader = create_state_loader_by_args(None, **kwargs)
1794
+ kwargs["state_loader"] = state_loader
1201
1795
 
1202
- app.state = AppState(
1203
- command="read_only",
1204
- state_loader=state_loader,
1205
- kwargs=kwargs,
1206
- flag=flag,
1207
- lifetime=lifetime,
1208
- share_url=kwargs.get("share_url"),
1209
- )
1210
- set_default_context(RecceContext.load(**kwargs, review=is_review, state_loader=state_loader))
1796
+ try:
1797
+ console.print("Starting Recce MCP Server...")
1798
+ console.print("Available tools: get_lineage_diff, row_count_diff, query, query_diff, profile_diff")
1211
1799
 
1212
- uvicorn.run(app, host=host, port=port, lifespan="on")
1800
+ # Run the async server
1801
+ asyncio.run(run_mcp_server(**kwargs))
1802
+ except Exception as e:
1803
+ console.print(f"[[red]Error[/red]] Failed to start MCP server: {e}")
1804
+ if kwargs.get("debug"):
1805
+ import traceback
1806
+
1807
+ traceback.print_exc()
1808
+ exit(1)
1213
1809
 
1214
1810
 
1215
1811
  if __name__ == "__main__":