@josephyan/qingflow-cli 0.2.0-beta.1000

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 (92) hide show
  1. package/README.md +31 -0
  2. package/docs/local-agent-install.md +309 -0
  3. package/entry_point.py +13 -0
  4. package/npm/bin/qingflow.mjs +5 -0
  5. package/npm/lib/runtime.mjs +346 -0
  6. package/npm/scripts/postinstall.mjs +16 -0
  7. package/package.json +34 -0
  8. package/pyproject.toml +67 -0
  9. package/qingflow +15 -0
  10. package/src/qingflow_mcp/__init__.py +37 -0
  11. package/src/qingflow_mcp/__main__.py +5 -0
  12. package/src/qingflow_mcp/backend_client.py +649 -0
  13. package/src/qingflow_mcp/builder_facade/__init__.py +3 -0
  14. package/src/qingflow_mcp/builder_facade/models.py +1846 -0
  15. package/src/qingflow_mcp/builder_facade/service.py +16502 -0
  16. package/src/qingflow_mcp/cli/__init__.py +1 -0
  17. package/src/qingflow_mcp/cli/commands/__init__.py +18 -0
  18. package/src/qingflow_mcp/cli/commands/app.py +40 -0
  19. package/src/qingflow_mcp/cli/commands/auth.py +112 -0
  20. package/src/qingflow_mcp/cli/commands/builder.py +539 -0
  21. package/src/qingflow_mcp/cli/commands/chart.py +18 -0
  22. package/src/qingflow_mcp/cli/commands/common.py +62 -0
  23. package/src/qingflow_mcp/cli/commands/imports.py +96 -0
  24. package/src/qingflow_mcp/cli/commands/portal.py +25 -0
  25. package/src/qingflow_mcp/cli/commands/record.py +331 -0
  26. package/src/qingflow_mcp/cli/commands/repo.py +80 -0
  27. package/src/qingflow_mcp/cli/commands/task.py +141 -0
  28. package/src/qingflow_mcp/cli/commands/view.py +18 -0
  29. package/src/qingflow_mcp/cli/commands/workspace.py +110 -0
  30. package/src/qingflow_mcp/cli/context.py +60 -0
  31. package/src/qingflow_mcp/cli/formatters.py +573 -0
  32. package/src/qingflow_mcp/cli/json_io.py +50 -0
  33. package/src/qingflow_mcp/cli/main.py +186 -0
  34. package/src/qingflow_mcp/cli/qingflow_login.py +116 -0
  35. package/src/qingflow_mcp/cli/terminal_ui.py +173 -0
  36. package/src/qingflow_mcp/config.py +407 -0
  37. package/src/qingflow_mcp/errors.py +66 -0
  38. package/src/qingflow_mcp/id_utils.py +49 -0
  39. package/src/qingflow_mcp/import_store.py +121 -0
  40. package/src/qingflow_mcp/json_types.py +18 -0
  41. package/src/qingflow_mcp/list_type_labels.py +76 -0
  42. package/src/qingflow_mcp/public_surface.py +243 -0
  43. package/src/qingflow_mcp/repository_store.py +71 -0
  44. package/src/qingflow_mcp/response_trim.py +841 -0
  45. package/src/qingflow_mcp/server.py +216 -0
  46. package/src/qingflow_mcp/server_app_builder.py +543 -0
  47. package/src/qingflow_mcp/server_app_user.py +386 -0
  48. package/src/qingflow_mcp/session_store.py +369 -0
  49. package/src/qingflow_mcp/solution/__init__.py +6 -0
  50. package/src/qingflow_mcp/solution/build_assembly_store.py +181 -0
  51. package/src/qingflow_mcp/solution/compiler/__init__.py +282 -0
  52. package/src/qingflow_mcp/solution/compiler/chart_compiler.py +96 -0
  53. package/src/qingflow_mcp/solution/compiler/form_compiler.py +495 -0
  54. package/src/qingflow_mcp/solution/compiler/icon_utils.py +187 -0
  55. package/src/qingflow_mcp/solution/compiler/navigation_compiler.py +57 -0
  56. package/src/qingflow_mcp/solution/compiler/package_compiler.py +19 -0
  57. package/src/qingflow_mcp/solution/compiler/portal_compiler.py +60 -0
  58. package/src/qingflow_mcp/solution/compiler/view_compiler.py +51 -0
  59. package/src/qingflow_mcp/solution/compiler/workflow_compiler.py +173 -0
  60. package/src/qingflow_mcp/solution/design_session.py +222 -0
  61. package/src/qingflow_mcp/solution/design_store.py +100 -0
  62. package/src/qingflow_mcp/solution/executor.py +2398 -0
  63. package/src/qingflow_mcp/solution/normalizer.py +23 -0
  64. package/src/qingflow_mcp/solution/requirements_builder.py +536 -0
  65. package/src/qingflow_mcp/solution/run_store.py +244 -0
  66. package/src/qingflow_mcp/solution/spec_models.py +855 -0
  67. package/src/qingflow_mcp/tools/__init__.py +1 -0
  68. package/src/qingflow_mcp/tools/ai_builder_tools.py +3449 -0
  69. package/src/qingflow_mcp/tools/app_tools.py +926 -0
  70. package/src/qingflow_mcp/tools/approval_tools.py +1062 -0
  71. package/src/qingflow_mcp/tools/auth_tools.py +1133 -0
  72. package/src/qingflow_mcp/tools/base.py +281 -0
  73. package/src/qingflow_mcp/tools/code_block_tools.py +777 -0
  74. package/src/qingflow_mcp/tools/custom_button_tools.py +202 -0
  75. package/src/qingflow_mcp/tools/directory_tools.py +675 -0
  76. package/src/qingflow_mcp/tools/feedback_tools.py +238 -0
  77. package/src/qingflow_mcp/tools/file_tools.py +409 -0
  78. package/src/qingflow_mcp/tools/import_tools.py +2223 -0
  79. package/src/qingflow_mcp/tools/navigation_tools.py +210 -0
  80. package/src/qingflow_mcp/tools/package_tools.py +326 -0
  81. package/src/qingflow_mcp/tools/portal_tools.py +158 -0
  82. package/src/qingflow_mcp/tools/qingbi_report_tools.py +374 -0
  83. package/src/qingflow_mcp/tools/record_tools.py +14291 -0
  84. package/src/qingflow_mcp/tools/repository_dev_tools.py +552 -0
  85. package/src/qingflow_mcp/tools/resource_read_tools.py +503 -0
  86. package/src/qingflow_mcp/tools/role_tools.py +112 -0
  87. package/src/qingflow_mcp/tools/solution_tools.py +4054 -0
  88. package/src/qingflow_mcp/tools/task_context_tools.py +2986 -0
  89. package/src/qingflow_mcp/tools/task_tools.py +889 -0
  90. package/src/qingflow_mcp/tools/view_tools.py +335 -0
  91. package/src/qingflow_mcp/tools/workflow_tools.py +376 -0
  92. package/src/qingflow_mcp/tools/workspace_tools.py +266 -0
@@ -0,0 +1,216 @@
1
+ from __future__ import annotations
2
+
3
+ from datetime import date
4
+
5
+ from mcp.server.fastmcp import FastMCP
6
+
7
+ from .backend_client import BackendClient
8
+ from .session_store import SessionStore
9
+ from .tools.app_tools import AppTools
10
+ from .tools.auth_tools import AuthTools
11
+ from .tools.code_block_tools import CodeBlockTools
12
+ from .tools.feedback_tools import FeedbackTools
13
+ from .tools.file_tools import FileTools
14
+ from .tools.import_tools import ImportTools
15
+ from .tools.package_tools import PackageTools
16
+ from .tools.navigation_tools import NavigationTools
17
+ from .tools.directory_tools import DirectoryTools
18
+ from .tools.portal_tools import PortalTools
19
+ from .tools.qingbi_report_tools import QingbiReportTools
20
+ from .tools.role_tools import RoleTools
21
+ from .tools.solution_tools import SolutionTools
22
+ from .tools.task_context_tools import TaskContextTools
23
+ from .tools.view_tools import ViewTools
24
+ from .tools.workflow_tools import WorkflowTools
25
+ from .tools.workspace_tools import WorkspaceTools
26
+
27
+
28
+ def build_server() -> FastMCP:
29
+ today = date.today()
30
+ current_year = today.year
31
+ server = FastMCP(
32
+ "Qingflow MCP",
33
+ instructions=f"""Use this server for Qingflow operational workflows. Current date: `{today.isoformat()}`.
34
+
35
+ ## Authentication
36
+
37
+ Use `auth_use_credential` first when a local host such as createClaw can provide a credential. Treat the returned `wsId` and `qfVersion` as authoritative for the local session.
38
+ All resource tools operate with the logged-in user's Qingflow permissions.
39
+
40
+ ## Shared Helper
41
+
42
+ `feedback_submit` is always available as a cross-cutting helper.
43
+
44
+ - Use it when the current MCP capability is unsupported, awkward, or still cannot satisfy the user's need after reasonable use.
45
+ - It does not require Qingflow login or workspace selection.
46
+ - Call it only after the user explicitly confirms submission.
47
+
48
+ ## App Discovery
49
+
50
+ If `app_key` is unknown, use `app_list` or `app_search` first.
51
+ If the app is known but the data range is not, use `app_get` first and choose from `accessible_views`.
52
+ If an accessible view has `analysis_supported=false`, do not use it for `record_list` or `record_analyze`. `boardView` and `ganttView` are special UI views, not list/analyze targets.
53
+
54
+ ## Schema-First Rule
55
+
56
+ Call `record_insert_schema_get` before `record_insert`.
57
+ Call `record_update_schema_get` before `record_update`.
58
+ Call `record_code_block_schema_get` before `record_code_block_run`.
59
+ Call `app_get` first when the data range is unclear, then use `record_browse_schema_get(view_id=...)` before `record_list`, `record_get`, or `record_analyze`.
60
+ Call `record_import_schema_get` when the import field mapping is unclear before template download or verify.
61
+
62
+ - All `field_id` values must come from the schema response.
63
+ - Never guess field names or ids.
64
+
65
+ ## Schema Scope
66
+
67
+ `record_insert_schema_get` returns the current user's insert-ready applicant schema; read `required_fields`, `optional_fields`, `runtime_linked_required_fields`, and `payload_template`.
68
+ `record_update_schema_get` returns the current record's overall update-ready writable field set across matched accessible views; read `writable_fields` and `payload_template`.
69
+ `record_browse_schema_get(view_id=...)` returns browse-schema fields for the selected accessible view.
70
+ `record_code_block_schema_get` returns code-block-ready schema for exact code block field selection.
71
+ `record_import_schema_get` returns import-ready column metadata.
72
+
73
+ - Hidden fields are omitted.
74
+ - Missing fields mean the field is not visible in the current permission scope.
75
+ - Read the top-level schema payload directly; do not guess missing writable fields.
76
+
77
+ ## Analytics Path
78
+
79
+ `app_get -> record_browse_schema_get(view_id=...) -> record_analyze`
80
+
81
+ Prefer `view_id` entries from `accessible_views` where `analysis_supported=true`.
82
+
83
+ Use this DSL shape:
84
+
85
+ - `dimensions`: `{{field_id, alias, bucket}}`
86
+ - `metrics`: `{{op, field_id, alias}}`
87
+ - `filters`: `{{field_id, op, value}}`
88
+ - `sort`: `{{by, order}}`
89
+
90
+ Important key rules:
91
+
92
+ - Use `op`
93
+ - Do **not** use `type`
94
+ - Do **not** use `agg`
95
+ - Do **not** use `aggregation`
96
+ - Do **not** use `operator`
97
+
98
+ Analysis answers must include concrete numbers. When applicable, include percentages based on the returned totals.
99
+
100
+ ## Record CRUD Path
101
+
102
+ `app_get -> record_browse_schema_get(view_id=...) -> record_list / record_get`
103
+ `record_insert_schema_get -> record_insert`
104
+ `record_update_schema_get -> record_update`
105
+ `record_list / record_get -> record_delete`
106
+ `record_code_block_schema_get -> record_code_block_run`
107
+
108
+ - Use `columns` as `[{{field_id}}]`
109
+ - Use `where` items as `{{field_id, op, value}}`
110
+ - Use `order_by` items as `{{field_id, direction}}`
111
+ - Legacy forms such as bare integer `field_id`, `fieldId`, `operator`, `values`, or `order` may still parse, but they are compatibility-only and not the canonical DSL
112
+
113
+ - `record_insert` uses an applicant-node `fields` map keyed by field title.
114
+ - `record_update` uses a field-title keyed `fields` map and internally selects the first accessible view that can execute the current payload.
115
+ - For insert, `runtime_linked_required_fields` means required-but-not-directly-writable fields that are usually supplied by runtime linkage or upstream context.
116
+ - For insert, fields marked `may_become_required=true` stay in `optional_fields`; they are still directly writable, but linked visibility or option-driven rules can make them required at runtime.
117
+ - Read field-level `linkage` whenever present on `record_insert_schema_get` or `record_update_schema_get`; it is the static hint for linked visibility, reference-driven auto fill, and formula/default auto-fill behavior.
118
+ - `linkage.sources` lists upstream field titles that influence the current field; `linkage.affects_fields` lists downstream fields that may change when the current field changes.
119
+ - `linkage.kind=logic_visibility` means linked visibility or option-driven rules are involved; `linkage.kind=reference_fill` means reference/default matching logic is involved; `linkage.kind=formula_fill` means formula/default auto-fill logic is involved.
120
+ - `record_update_schema_get` exposes the overall writable field set for the record, but not every field combination is guaranteed; `record_update` still needs one single matched accessible view that can cover the payload.
121
+ - `record_delete` deletes by `record_id` or `record_ids`.
122
+ - When readback shape matters after insert or update, prefer `record_get(..., output_profile="normalized")` or `record_list(..., output_profile="normalized")`.
123
+
124
+ - Read relation targets from `record_insert_schema_get` / `record_update_schema_get` relation metadata before preparing relation writes.
125
+ - Member and department fields may be written with natural strings directly on `record_insert` / `record_update`; only fall back to `record_member_candidates` or `record_department_candidates` when the user wants explicit candidate browsing or the write returns ambiguity that needs confirmation.
126
+ - If explicit candidate browsing is needed for default-all member or department fields, prefer those field candidate tools instead of starting with `directory_*`.
127
+
128
+ ## Code Block Path
129
+
130
+ Use `record_code_block_run` when the user wants to execute a form code-block field against an existing record.
131
+
132
+ - Always resolve the exact code-block field from `record_code_block_schema_get` first.
133
+ - Treat code-block execution as write-capable, not read-only.
134
+ - If the code block is bound to relation outputs, Qingflow may calculate target answers and write them back automatically.
135
+ - For safe debugging, pass `apply_writeback=false` and inspect the parsed alias results plus `relation.calculated_answers_preview` before allowing any writeback.
136
+ - In workflow context, pass `role=3` and the exact `workflow_node_id`.
137
+ - After execution, inspect `outputs.configured_aliases`, `outputs.alias_results`, `outputs.alias_map`, `relation.target_fields`, and `writeback.verification` before claiming success.
138
+
139
+ ## Import Path
140
+
141
+ `app_get -> record_import_schema_get -> record_import_template_get -> record_import_verify -> (optional authorized record_import_repair_local) -> record_import_start -> record_import_status_get`
142
+
143
+ - Check `app_get.data.import_capability` before doing import work.
144
+ - If `import_capability.can_import=false`, stop before template download, file repair, or import start.
145
+ - Import must go through `verify -> start`; do not start directly from a raw file path.
146
+ - `record_import_start` requires an explicit `being_enter_auditing` choice. Do not assume a default.
147
+ - Do not modify user-uploaded files unless the user explicitly authorizes repair.
148
+ - If repair is authorized, keep the original file and repair a copy, then run `record_import_verify` again before `record_import_start`.
149
+
150
+ ## Task Workflow Path
151
+
152
+ `task_list -> task_get -> task_action_execute`
153
+
154
+ - `task_list` returns task-card summaries keyed by `task_id`.
155
+ - Prefer `task_get(task_id=...)` for detail reads; MCP resolves the current todo locator internally.
156
+ - `task_action_execute(task_id=..., action=...)` is also supported; MCP resolves the current todo locator internally before calling the real action route.
157
+ - `task_workflow_log_get(task_id=...)` and `task_associated_report_detail_get(task_id=...)` are also supported for the current todo context.
158
+ - Use `task_associated_report_detail_get` for associated view or report details.
159
+ - Use `task_workflow_log_get` for full workflow log history.
160
+ - Task actions operate on `app_key + record_id + workflow_node_id`, not `task_id`.
161
+
162
+ ## Time Handling
163
+
164
+ Normalize relative dates before building DSL.
165
+
166
+ - If the user says `3月` without a year, use the current year: `{current_year}`
167
+ - Convert month-only phrases into explicit legal date ranges
168
+ - Never send impossible dates such as `2026-02-29`
169
+
170
+ ## Environment
171
+
172
+ Default to `prod` unless the user explicitly specifies `test`.
173
+
174
+ ## Constraints
175
+
176
+ Avoid builder-side app or schema changes here.
177
+
178
+ ## Feedback Path
179
+
180
+ If the current MCP capability is unsupported, the workflow is awkward, or the user's need still cannot be satisfied after reasonable use, offer to submit product feedback.
181
+
182
+ - First summarize what is still not working
183
+ - Ask the user whether to submit feedback
184
+ - Call `feedback_submit` only after explicit user confirmation""",
185
+ )
186
+ sessions = SessionStore()
187
+ backend = BackendClient()
188
+ AuthTools(sessions, backend).register(server)
189
+ FeedbackTools(backend, mcp_side="通用").register(server)
190
+ WorkspaceTools(sessions, backend).register(server)
191
+ FileTools(sessions, backend).register(server)
192
+ ImportTools(sessions, backend).register(server)
193
+ CodeBlockTools(sessions, backend).register(server)
194
+ TaskContextTools(sessions, backend).register(server)
195
+ RoleTools(sessions, backend).register(server)
196
+ AppTools(sessions, backend).register(server)
197
+ QingbiReportTools(sessions, backend).register(server)
198
+ PackageTools(sessions, backend).register(server)
199
+ NavigationTools(sessions, backend).register(server)
200
+ PortalTools(sessions, backend).register(server)
201
+ DirectoryTools(sessions, backend).register(server)
202
+ WorkflowTools(sessions, backend).register(server)
203
+ ViewTools(sessions, backend).register(server)
204
+ SolutionTools(sessions, backend).register(server)
205
+ return server
206
+
207
+
208
+ mcp = build_server()
209
+
210
+
211
+ def main() -> None:
212
+ mcp.run()
213
+
214
+
215
+ if __name__ == "__main__":
216
+ main()