@josephyan/qingflow-app-builder-mcp 0.2.0-beta.1016 → 0.2.0-beta.1017
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.
package/README.md
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Install:
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npm install @josephyan/qingflow-app-builder-mcp@0.2.0-beta.
|
|
6
|
+
npm install @josephyan/qingflow-app-builder-mcp@0.2.0-beta.1017
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
Run:
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
npx -y -p @josephyan/qingflow-app-builder-mcp@0.2.0-beta.
|
|
12
|
+
npx -y -p @josephyan/qingflow-app-builder-mcp@0.2.0-beta.1017 qingflow-app-builder-mcp
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
Environment:
|
package/package.json
CHANGED
package/pyproject.toml
CHANGED
|
@@ -11,6 +11,7 @@ from uuid import uuid4
|
|
|
11
11
|
|
|
12
12
|
from mcp.server.fastmcp import FastMCP
|
|
13
13
|
|
|
14
|
+
from ..backend_client import BackendRequestContext
|
|
14
15
|
from ..config import DEFAULT_PROFILE, DEFAULT_RECORD_LIST_TYPE
|
|
15
16
|
from ..errors import QingflowApiError
|
|
16
17
|
from ..export_store import ExportJobStore
|
|
@@ -213,6 +214,10 @@ class ExportTools(ToolBase):
|
|
|
213
214
|
{
|
|
214
215
|
"created_at": started_at,
|
|
215
216
|
"profile": profile,
|
|
217
|
+
"base_url": context.base_url,
|
|
218
|
+
"ws_id": context.ws_id,
|
|
219
|
+
"qf_version": context.qf_version,
|
|
220
|
+
"qf_version_source": context.qf_version_source,
|
|
216
221
|
"app_key": normalized_app_key,
|
|
217
222
|
"view_id": resolved_view.view_id,
|
|
218
223
|
"backend_export_id": str(socket_result.get("backend_export_id") or ""),
|
|
@@ -280,7 +285,7 @@ class ExportTools(ToolBase):
|
|
|
280
285
|
extra={"status": "failed"},
|
|
281
286
|
)
|
|
282
287
|
|
|
283
|
-
def runner(
|
|
288
|
+
def runner(session_profile, context):
|
|
284
289
|
local_job = self._job_store.get(normalized_handle)
|
|
285
290
|
if local_job is None:
|
|
286
291
|
return self._failed_export_result(
|
|
@@ -288,7 +293,13 @@ class ExportTools(ToolBase):
|
|
|
288
293
|
message="export_handle is missing or expired",
|
|
289
294
|
extra={"export_handle": normalized_handle, "status": "failed"},
|
|
290
295
|
)
|
|
291
|
-
|
|
296
|
+
lookup_context = self._build_export_lookup_context(
|
|
297
|
+
profile=profile,
|
|
298
|
+
session_profile=session_profile,
|
|
299
|
+
current_context=context,
|
|
300
|
+
local_job=local_job,
|
|
301
|
+
)
|
|
302
|
+
snapshot = self._resolve_export_snapshot(lookup_context, local_job)
|
|
292
303
|
return self._status_payload_from_snapshot(local_job, normalized_handle, snapshot)
|
|
293
304
|
|
|
294
305
|
try:
|
|
@@ -316,7 +327,7 @@ class ExportTools(ToolBase):
|
|
|
316
327
|
extra={"status": "failed"},
|
|
317
328
|
)
|
|
318
329
|
|
|
319
|
-
def runner(
|
|
330
|
+
def runner(session_profile, context):
|
|
320
331
|
local_job = self._job_store.get(normalized_handle)
|
|
321
332
|
if local_job is None:
|
|
322
333
|
return self._failed_export_result(
|
|
@@ -324,7 +335,13 @@ class ExportTools(ToolBase):
|
|
|
324
335
|
message="export_handle is missing or expired",
|
|
325
336
|
extra={"export_handle": normalized_handle, "status": "failed"},
|
|
326
337
|
)
|
|
327
|
-
|
|
338
|
+
lookup_context = self._build_export_lookup_context(
|
|
339
|
+
profile=profile,
|
|
340
|
+
session_profile=session_profile,
|
|
341
|
+
current_context=context,
|
|
342
|
+
local_job=local_job,
|
|
343
|
+
)
|
|
344
|
+
snapshot = self._resolve_export_snapshot(lookup_context, local_job)
|
|
328
345
|
normalized_status = str(snapshot.get("status") or "unknown")
|
|
329
346
|
if normalized_status not in {"succeeded", "failed"}:
|
|
330
347
|
return self._failed_export_result(
|
|
@@ -414,7 +431,7 @@ class ExportTools(ToolBase):
|
|
|
414
431
|
"downloaded_files": downloaded_files,
|
|
415
432
|
"warnings": snapshot.get("warnings") or [],
|
|
416
433
|
"verification": snapshot.get("verification") or {},
|
|
417
|
-
"request_route": self.backend.describe_route(
|
|
434
|
+
"request_route": self.backend.describe_route(lookup_context),
|
|
418
435
|
}
|
|
419
436
|
|
|
420
437
|
try:
|
|
@@ -451,7 +468,7 @@ class ExportTools(ToolBase):
|
|
|
451
468
|
)
|
|
452
469
|
timeout_seconds = self._normalize_timeout_seconds(wait_timeout_seconds)
|
|
453
470
|
|
|
454
|
-
def runner(
|
|
471
|
+
def runner(session_profile, context):
|
|
455
472
|
start_result = self.record_export_start(
|
|
456
473
|
profile=profile,
|
|
457
474
|
app_key=normalized_app_key,
|
|
@@ -475,7 +492,13 @@ class ExportTools(ToolBase):
|
|
|
475
492
|
message="export_handle is missing or expired",
|
|
476
493
|
extra={"status": "failed", "export_handle": export_handle},
|
|
477
494
|
)
|
|
478
|
-
|
|
495
|
+
lookup_context = self._build_export_lookup_context(
|
|
496
|
+
profile=profile,
|
|
497
|
+
session_profile=session_profile,
|
|
498
|
+
current_context=context,
|
|
499
|
+
local_job=local_job,
|
|
500
|
+
)
|
|
501
|
+
snapshot = self._resolve_export_snapshot(lookup_context, local_job)
|
|
479
502
|
last_snapshot = snapshot
|
|
480
503
|
normalized_status = str(snapshot.get("status") or "unknown")
|
|
481
504
|
if normalized_status == "succeeded":
|
|
@@ -583,6 +606,49 @@ class ExportTools(ToolBase):
|
|
|
583
606
|
extra={"app_key": normalized_app_key, "view_id": normalized_view_id},
|
|
584
607
|
)
|
|
585
608
|
|
|
609
|
+
def _build_export_lookup_context(
|
|
610
|
+
self,
|
|
611
|
+
*,
|
|
612
|
+
profile: str,
|
|
613
|
+
session_profile,
|
|
614
|
+
current_context: BackendRequestContext,
|
|
615
|
+
local_job: dict[str, Any],
|
|
616
|
+
) -> BackendRequestContext:
|
|
617
|
+
stored_profile = str(local_job.get("profile") or "").strip()
|
|
618
|
+
if stored_profile and stored_profile != profile:
|
|
619
|
+
raise QingflowApiError.config_error(
|
|
620
|
+
"export_handle was created under a different profile",
|
|
621
|
+
details={
|
|
622
|
+
"error_code": "EXPORT_HANDLE_PROFILE_MISMATCH",
|
|
623
|
+
"expected_profile": stored_profile,
|
|
624
|
+
"received_profile": profile,
|
|
625
|
+
},
|
|
626
|
+
)
|
|
627
|
+
stored_uid = _coerce_positive_int(local_job.get("uid"))
|
|
628
|
+
if stored_uid is not None and stored_uid != session_profile.uid:
|
|
629
|
+
raise QingflowApiError.config_error(
|
|
630
|
+
"export_handle belongs to a different authenticated user",
|
|
631
|
+
details={
|
|
632
|
+
"error_code": "EXPORT_HANDLE_OWNER_MISMATCH",
|
|
633
|
+
"expected_uid": stored_uid,
|
|
634
|
+
"current_uid": session_profile.uid,
|
|
635
|
+
},
|
|
636
|
+
)
|
|
637
|
+
stored_base_url = str(local_job.get("base_url") or "").strip() or current_context.base_url
|
|
638
|
+
stored_ws_id = _coerce_positive_int(local_job.get("ws_id"))
|
|
639
|
+
stored_qf_version = str(local_job.get("qf_version") or "").strip() or current_context.qf_version
|
|
640
|
+
stored_qf_version_source = (
|
|
641
|
+
str(local_job.get("qf_version_source") or "").strip() or current_context.qf_version_source
|
|
642
|
+
)
|
|
643
|
+
return BackendRequestContext(
|
|
644
|
+
base_url=stored_base_url,
|
|
645
|
+
token=current_context.token,
|
|
646
|
+
ws_id=stored_ws_id if stored_ws_id is not None else current_context.ws_id,
|
|
647
|
+
qf_request_id=current_context.qf_request_id,
|
|
648
|
+
qf_version=stored_qf_version,
|
|
649
|
+
qf_version_source=stored_qf_version_source,
|
|
650
|
+
)
|
|
651
|
+
|
|
586
652
|
def _resolve_export_record_scope(
|
|
587
653
|
self,
|
|
588
654
|
*,
|
|
@@ -2920,12 +2920,14 @@ class RecordTools(ToolBase):
|
|
|
2920
2920
|
payload["category"] = error.category
|
|
2921
2921
|
if error.backend_code is not None:
|
|
2922
2922
|
payload["backend_code"] = error.backend_code
|
|
2923
|
+
if error.request_id is not None:
|
|
2924
|
+
payload["request_id"] = error.request_id
|
|
2923
2925
|
if error.http_status is not None:
|
|
2924
2926
|
payload["http_status"] = error.http_status
|
|
2925
2927
|
return payload
|
|
2926
2928
|
|
|
2927
2929
|
def _is_record_context_route_miss(self, error: QingflowApiError) -> bool:
|
|
2928
|
-
if error.backend_code in {40002, 40027, 40038, 404}:
|
|
2930
|
+
if error.backend_code in {40002, 40023, 40027, 40038, 404}:
|
|
2929
2931
|
return True
|
|
2930
2932
|
if error.http_status == 404:
|
|
2931
2933
|
return True
|
|
@@ -3059,6 +3061,107 @@ class RecordTools(ToolBase):
|
|
|
3059
3061
|
f"({get_record_list_type_label(used_list_type)})."
|
|
3060
3062
|
]
|
|
3061
3063
|
|
|
3064
|
+
def _looks_like_generic_record_update_backend_failure(self, exc: QingflowApiError) -> bool:
|
|
3065
|
+
if exc.backend_code == 500:
|
|
3066
|
+
return True
|
|
3067
|
+
if exc.http_status is not None and exc.http_status >= 500:
|
|
3068
|
+
return True
|
|
3069
|
+
normalized_message = exc.message.strip().lower()
|
|
3070
|
+
return normalized_message in {"unknown error", "internal server error"}
|
|
3071
|
+
|
|
3072
|
+
def _remap_record_update_target_context_error(
|
|
3073
|
+
self,
|
|
3074
|
+
profile: str,
|
|
3075
|
+
context, # type: ignore[no-untyped-def]
|
|
3076
|
+
*,
|
|
3077
|
+
app_key: str,
|
|
3078
|
+
apply_id: int,
|
|
3079
|
+
exc: QingflowApiError,
|
|
3080
|
+
) -> None:
|
|
3081
|
+
if not self._looks_like_generic_record_update_backend_failure(exc):
|
|
3082
|
+
return
|
|
3083
|
+
try:
|
|
3084
|
+
candidate_routes = self._candidate_update_views(profile, context, app_key)
|
|
3085
|
+
probes = self._probe_candidate_record_contexts(
|
|
3086
|
+
context,
|
|
3087
|
+
app_key=app_key,
|
|
3088
|
+
apply_id=apply_id,
|
|
3089
|
+
candidate_routes=candidate_routes,
|
|
3090
|
+
)
|
|
3091
|
+
except (QingflowApiError, RuntimeError):
|
|
3092
|
+
return
|
|
3093
|
+
if not probes or any(probe.readable for probe in probes):
|
|
3094
|
+
return
|
|
3095
|
+
|
|
3096
|
+
blocker = (
|
|
3097
|
+
"CURRENT_RECORD_CONTEXT_UNAVAILABLE"
|
|
3098
|
+
if all(probe.transport_error for probe in probes)
|
|
3099
|
+
else "NO_MATCHING_ACCESSIBLE_VIEW_FOR_RECORD"
|
|
3100
|
+
)
|
|
3101
|
+
recommended_next_actions = (
|
|
3102
|
+
[
|
|
3103
|
+
"Retry after the record becomes readable in the current workspace/profile context.",
|
|
3104
|
+
"If the issue persists, verify that the current profile still has read access to this record.",
|
|
3105
|
+
]
|
|
3106
|
+
if blocker == "CURRENT_RECORD_CONTEXT_UNAVAILABLE"
|
|
3107
|
+
else [
|
|
3108
|
+
"Use record_get or record_list to confirm the record still exists in the current workspace.",
|
|
3109
|
+
"Call record_update_schema_get to inspect whether any accessible view still matches this record.",
|
|
3110
|
+
]
|
|
3111
|
+
)
|
|
3112
|
+
first_error_payload = next(
|
|
3113
|
+
(
|
|
3114
|
+
cast(JSONObject, probe.error_payload)
|
|
3115
|
+
for probe in probes
|
|
3116
|
+
if isinstance(probe.error_payload, dict)
|
|
3117
|
+
),
|
|
3118
|
+
None,
|
|
3119
|
+
)
|
|
3120
|
+
backend_code = (
|
|
3121
|
+
cast(int, first_error_payload.get("backend_code"))
|
|
3122
|
+
if isinstance(first_error_payload, dict) and isinstance(first_error_payload.get("backend_code"), int)
|
|
3123
|
+
else exc.backend_code
|
|
3124
|
+
)
|
|
3125
|
+
request_id = (
|
|
3126
|
+
_normalize_optional_text(first_error_payload.get("request_id"))
|
|
3127
|
+
if isinstance(first_error_payload, dict)
|
|
3128
|
+
else None
|
|
3129
|
+
) or exc.request_id
|
|
3130
|
+
http_status = (
|
|
3131
|
+
cast(int, first_error_payload.get("http_status"))
|
|
3132
|
+
if isinstance(first_error_payload, dict) and isinstance(first_error_payload.get("http_status"), int)
|
|
3133
|
+
else exc.http_status
|
|
3134
|
+
)
|
|
3135
|
+
raise_tool_error(
|
|
3136
|
+
QingflowApiError(
|
|
3137
|
+
category="backend",
|
|
3138
|
+
message=(
|
|
3139
|
+
"Direct record edit was blocked because the current record context could not be loaded from any candidate route."
|
|
3140
|
+
if blocker == "CURRENT_RECORD_CONTEXT_UNAVAILABLE"
|
|
3141
|
+
else "Direct record edit was blocked because the target record is no longer accessible in any readable view for the current profile."
|
|
3142
|
+
),
|
|
3143
|
+
backend_code=backend_code,
|
|
3144
|
+
request_id=request_id,
|
|
3145
|
+
http_status=http_status,
|
|
3146
|
+
details={
|
|
3147
|
+
"error_code": blocker,
|
|
3148
|
+
"operation": "update",
|
|
3149
|
+
"app_key": app_key,
|
|
3150
|
+
"record_id": apply_id,
|
|
3151
|
+
"blockers": [blocker],
|
|
3152
|
+
"request_route": self._request_route_payload(context),
|
|
3153
|
+
"view_probe_summary": [
|
|
3154
|
+
self._record_context_probe_summary_payload(probe)
|
|
3155
|
+
for probe in probes
|
|
3156
|
+
],
|
|
3157
|
+
"recommended_next_actions": recommended_next_actions,
|
|
3158
|
+
"fix_hint": (
|
|
3159
|
+
"Confirm the target record still exists and remains visible in at least one accessible view before retrying the update."
|
|
3160
|
+
),
|
|
3161
|
+
},
|
|
3162
|
+
)
|
|
3163
|
+
)
|
|
3164
|
+
|
|
3062
3165
|
def _record_matches_accessible_view(
|
|
3063
3166
|
self,
|
|
3064
3167
|
context, # type: ignore[no-untyped-def]
|
|
@@ -6355,12 +6458,22 @@ class RecordTools(ToolBase):
|
|
|
6355
6458
|
force_refresh_form=force_refresh_form,
|
|
6356
6459
|
)
|
|
6357
6460
|
self._validate_record_write(app_key, normalized_answers, apply_id=normalized_apply_id)
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6461
|
+
try:
|
|
6462
|
+
result = self.backend.request(
|
|
6463
|
+
"POST",
|
|
6464
|
+
context,
|
|
6465
|
+
f"/app/{app_key}/apply/{normalized_apply_id}",
|
|
6466
|
+
json_body={"role": role, "answers": normalized_answers},
|
|
6467
|
+
)
|
|
6468
|
+
except QingflowApiError as exc:
|
|
6469
|
+
self._remap_record_update_target_context_error(
|
|
6470
|
+
profile,
|
|
6471
|
+
context,
|
|
6472
|
+
app_key=app_key,
|
|
6473
|
+
apply_id=normalized_apply_id,
|
|
6474
|
+
exc=exc,
|
|
6475
|
+
)
|
|
6476
|
+
raise
|
|
6364
6477
|
verification = self._verify_record_write_result(
|
|
6365
6478
|
context,
|
|
6366
6479
|
app_key=app_key,
|
|
@@ -8810,6 +8923,8 @@ class RecordTools(ToolBase):
|
|
|
8810
8923
|
error_payload["request_id"] = parsed.get("request_id")
|
|
8811
8924
|
if isinstance(parsed.get("request_route"), dict):
|
|
8812
8925
|
request_route = cast(JSONObject, parsed.get("request_route"))
|
|
8926
|
+
elif details_payload is not None and isinstance(details_payload.get("request_route"), dict):
|
|
8927
|
+
request_route = cast(JSONObject, details_payload.get("request_route"))
|
|
8813
8928
|
response: JSONObject = {
|
|
8814
8929
|
"profile": profile,
|
|
8815
8930
|
"ws_id": None,
|
|
@@ -96,7 +96,9 @@ class ResourceReadTools(ToolBase):
|
|
|
96
96
|
)
|
|
97
97
|
)
|
|
98
98
|
if system_view is not None:
|
|
99
|
-
export_capability = _view_export_capability_payload(
|
|
99
|
+
export_capability = _view_export_capability_payload(
|
|
100
|
+
supported=_export_supported_for_view_type(system_view["view_type"])
|
|
101
|
+
)
|
|
100
102
|
return self._run(
|
|
101
103
|
profile,
|
|
102
104
|
lambda session_profile, _context: {
|
|
@@ -133,13 +135,11 @@ class ResourceReadTools(ToolBase):
|
|
|
133
135
|
)
|
|
134
136
|
|
|
135
137
|
def runner(session_profile, context):
|
|
136
|
-
|
|
138
|
+
raw_view_type = None
|
|
137
139
|
warnings: list[JSONObject] = []
|
|
138
140
|
verification = {
|
|
139
141
|
"view_exists": True,
|
|
140
142
|
"questions_verified": True,
|
|
141
|
-
"export_route_supported": export_capability["supported"],
|
|
142
|
-
"export_permission_verified": export_capability["permission_verified"],
|
|
143
143
|
}
|
|
144
144
|
config = self.backend.request("GET", context, f"/view/{view_key}/viewConfig")
|
|
145
145
|
base_info = self.backend.request("GET", context, f"/view/{view_key}/viewConfig/baseInfo")
|
|
@@ -161,6 +161,11 @@ class ResourceReadTools(ToolBase):
|
|
|
161
161
|
str(base_info.get("viewgraphType") or "").strip()
|
|
162
162
|
or str(config.get("viewgraphType") or config.get("viewType") or "").strip()
|
|
163
163
|
)
|
|
164
|
+
export_capability = _view_export_capability_payload(
|
|
165
|
+
supported=_export_supported_for_view_type(raw_view_type or None)
|
|
166
|
+
)
|
|
167
|
+
verification["export_route_supported"] = export_capability["supported"]
|
|
168
|
+
verification["export_permission_verified"] = export_capability["permission_verified"]
|
|
164
169
|
resolved_app_key = str(base_info.get("appKey") or config.get("appKey") or "").strip() or None
|
|
165
170
|
if not resolved_app_key:
|
|
166
171
|
resolved_app_key = self._resolve_app_key_from_view_form(context=context, view_key=view_key)
|
|
@@ -176,12 +181,13 @@ class ResourceReadTools(ToolBase):
|
|
|
176
181
|
"message": f"view_get could not resolve app_key for `{view_id}` from view metadata; keep using the app_key from the parent app or portal context.",
|
|
177
182
|
}
|
|
178
183
|
)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
184
|
+
if export_capability["supported"]:
|
|
185
|
+
warnings.append(
|
|
186
|
+
{
|
|
187
|
+
"code": "VIEW_EXPORT_APP_CONTEXT_REQUIRED",
|
|
188
|
+
"message": f"view_get supports exporting `{view_id}`, but the export call still needs an explicit `app_key` from the parent app context.",
|
|
189
|
+
}
|
|
190
|
+
)
|
|
185
191
|
return {
|
|
186
192
|
"profile": profile,
|
|
187
193
|
"ws_id": session_profile.selected_ws_id,
|
|
@@ -493,6 +499,10 @@ def _view_export_capability_payload(*, supported: bool) -> JSONObject:
|
|
|
493
499
|
}
|
|
494
500
|
|
|
495
501
|
|
|
502
|
+
def _export_supported_for_view_type(view_type: str | None) -> bool:
|
|
503
|
+
return _analysis_supported_for_view_type(view_type)
|
|
504
|
+
|
|
505
|
+
|
|
496
506
|
def _normalize_view_type(view_type: Any) -> str | None:
|
|
497
507
|
value = str(view_type or "").strip()
|
|
498
508
|
if not value:
|