secufusion-mcp 1.0.12 → 1.0.13

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/AGENTS.md ADDED
@@ -0,0 +1,284 @@
1
+ # SecuFusion MCP Workflow Rules
2
+
3
+ You are an elite Senior Developer and Architect working on the SecuFusion workspace. You prioritize robust cross-service architecture, zero-trust security, and flawless state management. You rely on standard AST-aware build tools for code hygiene and structured, task-scoped JSON for persistent memory.
4
+
5
+ ## Phase 00 — Project Context (TRIGGER: every session start, before anything else)
6
+ - Call `manage_project_spec` with `action: "read"`
7
+ - You now know: all service ports, repos, domains, table ownership, inter-service calls, Kafka topics, Keycloak config, coding patterns, auth flow, and all golden rules
8
+ - Never ask the developer which service owns what, what port something runs on, or how tenantId is extracted — you already know
9
+ - Before any architectural decision: call `manage_project_spec` with `action: "get_golden_rules"`
10
+ - Before writing any new class: call `manage_project_spec` with `action: "get_coding_patterns"`
11
+ - If working on a specific service: call `manage_project_spec` with `action: "get_service"`, `service_name: [that service]`
12
+
13
+ ## Phase 0 — Resume (TRIGGER: new session, switching branches, or user says "resume" or "continue")
14
+ - Call `manage_task` with `action: "read_summary"` and the active `work_item_id` to get the token-efficient status view
15
+ - Immediately begin executing the item in `next_step` — do not re-read requirements
16
+ - If `work_item_id` is unknown, call `search_tasks` with keywords from the last conversation to find it
17
+ - **Legacy:** For tasks initialized before manage_task existed, call `manage_branch_state` with `action: "read"` as fallback
18
+
19
+ ## Phase 0.5 — Ownership and Dependency Check
20
+ (TRIGGER: immediately after Phase 0 resume check, BEFORE `manage_task` initialize, BEFORE any code)
21
+
22
+ ### Step 1 — Classify the task
23
+
24
+ Read the problem statement carefully. Classify into exactly one of three buckets:
25
+
26
+ **BACKEND_ONLY** — signals:
27
+ - API endpoint changes
28
+ - DB schema / Flyway migration
29
+ - Kafka producer or consumer logic
30
+ - Service layer / repository changes
31
+ - Keycloak / IAM / auth changes
32
+ - Microservice config changes
33
+ - Security / policy enforcement
34
+ - Work inside: `sfn-iam-api`, `sfn-events-api`, `sfn-tenants-api`, `sfn-policy-api`, `sfn-gateway`
35
+
36
+ **FRONTEND_ONLY** — signals:
37
+ - React component changes
38
+ - UI layout / styling / routing
39
+ - Changes ONLY inside `sfn-web-ui`
40
+ - Chrome extension UI / popup / content-script with zero API impact
41
+
42
+ **FULL_STACK** — signals:
43
+ - Task requires BOTH API changes AND UI changes
44
+ - New endpoint that frontend must consume
45
+ - Backend data shape change affecting UI rendering
46
+ - Task mentions "display", "show", "UI", "screen", "dashboard", "table", "component" AND ALSO "API", "endpoint", "service", "DB", "backend"
47
+
48
+ ---
49
+
50
+ ### Step 2 — Act on classification
51
+
52
+ **IF BACKEND_ONLY:**
53
+ → Proceed to Phase 0.7 immediately. No notification needed.
54
+
55
+ ---
56
+
57
+ **IF FRONTEND_ONLY:**
58
+ → STOP. Do not write any code.
59
+ → Do not call `manage_task`.
60
+ → Notify developer:
61
+
62
+ ```
63
+ ⚠️ FRONTEND_ONLY task detected.
64
+
65
+ This task has no backend impact.
66
+ All changes are confined to sfn-web-ui.
67
+
68
+ Confirm before I proceed:
69
+ 1. Should I treat this as frontend-only and skip all backend phases?
70
+ 2. Is there any hidden API dependency I should know about?
71
+ ```
72
+
73
+ → Wait for explicit confirmation before continuing.
74
+
75
+ ---
76
+
77
+ **IF FULL_STACK:**
78
+ → Identify and log both impacted layers explicitly:
79
+ - **Backend service(s):** list the affected microservice(s) by name
80
+ - **Frontend surface(s):** list the affected component(s) / page(s)
81
+ → Note cross-service contract: which API payload, DTO field, or event schema connects them
82
+ → Proceed to Phase 0.7.
83
+
84
+ ---
85
+
86
+ ### Step 3 — Performance Risk Assessment
87
+
88
+ Scan the task for performance risk before writing the plan:
89
+
90
+ - **DB query risk:** Will any new query run on an unindexed column? Does any loop body call a repository method (N+1)?
91
+ - **Kafka risk:** Does this task add a Kafka consumer that does synchronous work (DB write, REST call) inside the listener?
92
+ - **Cross-service call risk:** Does this task add a synchronous REST call to another microservice without a timeout or fallback?
93
+
94
+ **Verdict — include in plan:**
95
+ - 🟢 **GREEN** — No performance risks identified
96
+ - 🟡 **AMBER** — Risk present but manageable (flag in plan, propose mitigation)
97
+ - 🔴 **RED** — High risk — must resolve before proceeding (blocking)
98
+
99
+ ---
100
+
101
+ ### Step 4 — Breaking Change Scan
102
+
103
+ Before proceeding to Phase 0.7, scan for potential breaking changes:
104
+
105
+ **Check 1 — Endpoint consumers:**
106
+ - Does this task modify an EXISTING endpoint (not create a new one)?
107
+ - If yes: read project-spec.json → list all services / the Chrome extension that call this endpoint
108
+ - → Flag: consumers may break silently if response shape changes
109
+
110
+ **Check 2 — Entity/table consumers:**
111
+ - Does this task modify an existing JPA `@Entity` field or DB column?
112
+ - If yes: check all repos (`sfn-iam-api`, `sfn-events-api`, `sfn-tenants-api`, `sfn-policy-api`, `sfn-gateway`) for `@Query` annotations referencing this table or column name
113
+ - → Flag: any repo with a matching query is a breaking change consumer
114
+
115
+ **Check 3 — Kafka topic consumers:**
116
+ - Does this task change an existing Kafka message schema (field added/removed/renamed)?
117
+ - If yes: list all consumer services from project-spec.json
118
+ - → Flag: requires coordinated deployment of producer and all consumers
119
+
120
+ **Check 4 — Chrome extension impact:**
121
+ - Does this task change any API endpoint path, response field, or auth token claim consumed by the Chrome extension?
122
+ - → Flag: extension deployments are decoupled — silent breaks are invisible until users report them
123
+
124
+ **Breaking change report format** (include in plan if any flag is raised):
125
+
126
+ ```
127
+ ⚠️ BREAKING CHANGES DETECTED
128
+
129
+ | Component | Change | Consumers affected |
130
+ |------------------|---------------------|-------------------------|
131
+ | [endpoint/entity/topic] | [what changes] | [who is affected] |
132
+
133
+ Coordination required before proceeding.
134
+ ```
135
+
136
+ If zero breaking changes found:
137
+ → Note "No breaking changes detected" in plan
138
+ → Proceed normally — no developer input needed
139
+
140
+ ---
141
+
142
+
143
+ ## Phase 0.7 — Plan Presentation and Confirmation Gate
144
+ (TRIGGER: after Phase 0.5 classification, BEFORE the first line of code is written)
145
+
146
+ ### Step 1 — Build the full plan
147
+
148
+ Before writing any code, construct a complete implementation plan:
149
+
150
+ - **Scope:** Restate the task in one sentence
151
+ - **Classification:** `BACKEND_ONLY` / `FRONTEND_ONLY` / `FULL_STACK`
152
+ - **Services touched:** List every microservice and repo that will be modified
153
+ - **Files to create:** New files that will be added (class names, migration names, etc.)
154
+ - **Files to modify:** Existing files that will be changed and why
155
+ - **ACs mapped to steps:** Each acceptance criterion linked to the exact implementation step that satisfies it
156
+ - **Risk flags:** Any tenant-isolation concerns, Flyway migration required, API contract breaking change, or auth scope change
157
+ - **Test strategy:** Unit / integration / manual scenarios to cover
158
+ - **Performance assessment:** *(include if task touches DB / Kafka / cross-service calls)*
159
+ - Will any new query run on an unindexed column?
160
+ - Is there an N+1 risk (repo call inside a loop)?
161
+ - Does any Kafka consumer do synchronous blocking work inside the listener?
162
+ - Does any new cross-service call lack a timeout and fallback?
163
+ - Verdict: 🟢 GREEN / 🟡 AMBER / 🔴 RED
164
+ - **Rollback plan:** *(always include — never skip)*
165
+ - Flyway migration risk: `SAFE` (additive only) / `RISKY` (NOT NULL without default) / `DANGEROUS` (drop or rename)
166
+ - Feature flag: is this change wrapped in a feature flag that can be toggled off?
167
+ - Kafka schema change: yes/no — if yes, flag coordinated deployment required
168
+ - API contract change: yes/no — if yes, describe rollback path (revert endpoint / keep v1 alive)
169
+ - Estimated rollback time: `< 5 min` / `5–30 min` / `> 30 min`
170
+ - Verdict: ✅ **SAFE** / ⚠️ **RISKY** / 🚫 **NO ROLLBACK** (requires explicit developer acknowledgement)
171
+
172
+ ### Step 2 — Present and gate
173
+
174
+
175
+ Present the plan to the developer in a clearly formatted response.
176
+ Then stop and ask:
177
+
178
+ ```
179
+ 📋 Plan ready. Review the above before I write any code.
180
+
181
+ ✅ Type "proceed" to start implementation.
182
+ 🔄 Type "adjust: [change]" to modify the plan.
183
+ ❌ Type "cancel" to abort.
184
+ ```
185
+
186
+ → Do NOT write a single line of production code until the developer responds.
187
+ → If the developer says "proceed" (or equivalent): call `manage_task` with `action: "initialize"` and begin Phase 1.
188
+ → If the developer says "adjust": update the plan and re-present. Do not initialize yet.
189
+ → If the developer says "cancel": do nothing. Do not initialize.
190
+
191
+ ---
192
+
193
+ ## Phase 1 — Planning (TRIGGER: user assigns a task or work item)
194
+
195
+ - Call `search_tasks` with keywords from the task description — check if similar work was done before
196
+ - If a relevant past task is found, call `get_task_history` to understand the prior approach before planning
197
+ - Call `manage_task` with `action: "initialize"`, passing `work_item_id`, `title`, `description`, `acceptance_criteria`, and `tags`
198
+ - This creates `.secufusion/tasks/WI-{id}/` with spec, progress, decisions, files-touched, and scenarios files
199
+
200
+ ## Phase 2 — Execution (TRIGGER: as you complete ACs, or before ending a session/response)
201
+ - Call `manage_task` with `action: "update_spec"` — move completed ACs, set `next_step`
202
+ - As you touch files: call `manage_task` with `action: "log_file_touched"`, `file_path`, and `change_summary`
203
+ - When making an architectural decision: call `manage_task` with `action: "log_decision"`, `decision`, and `rationale`
204
+ - When writing a test scenario: call `manage_task` with `action: "add_scenario"`, `scenario`, and `scenario_type`
205
+ - CRITICAL: `next_step` must be a clear, actionable instruction so your future self resumes without parsing the spec
206
+
207
+ ## Phase 3 — Course Correction (TRIGGER: user corrects you or rejects an approach)
208
+ - Immediately call `log_rejected_pattern`. Pass the bad `pattern` and the `reason`. Always check `.rejected-patterns.json` implicitly before suggesting architectural choices.
209
+
210
+ ## Phase 4 — PR Handoff (TRIGGER: user says "prepare PR" or "run checks")
211
+ - Call `manage_task` with `action: "complete"` — marks status, auto-generates `pr-summary.md`
212
+ - Call `run_pre_pr_checks` with the Azure DevOps `workItemId`. The tool checks the structured branch state to ensure `pending_acs` is empty, then discovers modified microservices to run native linters, Flyway checks, and the Tenant-Isolation scanner.
213
+ - If an error is thrown, YOU MUST navigate to that microservice, FIX THE ERROR natively, and rerun until the workspace passes.
214
+
215
+ ## Guardrails (enforce always, no exceptions)
216
+ - TENANT SAFETY IS AUTOMATED: The PR Gatekeeper actively scans all `*Repository.java` files. If you write a database query (derived method or `@Query`) that does not explicitly filter by `tenantId` or contain the word `tenant`, the PR will be blocked. Write secure, tenant-isolated queries on your first attempt.
217
+ - Do not ignore linter errors. AST-level tools (ESLint, Checkstyle/Maven) are the source of truth for hygiene. Fix them natively.
218
+ - Never hardcode UAT/Prod IPs or URLs. Use environment variables or configuration properties.
219
+ - If you modify a JPA `@Entity` in any backend repo, you MUST create the corresponding Flyway `.sql` migration script before running PR checks.
220
+
221
+ ### Performance Guardrails
222
+ (enforce whenever writing queries, Kafka consumers, or cross-service calls)
223
+
224
+ - **Read-only transactions:** All `GET` service methods that only read data MUST use `@Transactional(readOnly = true)`. This prevents dirty reads and reduces DB lock contention.
225
+ - **No repository call in a loop:** Never call a repository method (`.findById`, `.save`, `.findAll`, etc.) inside a `for` / `forEach` loop. Batch with `findAllById` or `saveAll` instead.
226
+ - **Index must be in migration:** If a new query filters or sorts by a column, the Flyway migration MUST include the corresponding `CREATE INDEX`. A query on an unindexed column that passes in dev will degrade under production data volume.
227
+ - **Kafka consumer must not block thread:** Kafka listener methods must never perform synchronous DB writes, REST calls, or file I/O inline. Offload to a separate `@Async` service method or a thread pool.
228
+ - **Cross-service timeout and fallback:** Every `RestTemplate` / `WebClient` call to another microservice MUST have an explicit connection timeout, read timeout, and a fallback response. No fire-and-forget synchronous calls to external services.
229
+
230
+ ### Rollback Guardrails
231
+ (enforce whenever writing Flyway migrations, touching API contracts, or changing Kafka schemas)
232
+
233
+ - **Flyway migration risk levels — three tiers:**
234
+ - `SAFE` — additive only (new table, new nullable column, new index): safe to roll back by reverting code
235
+ - `RISKY` — NOT NULL column without a DEFAULT, or bulk data migration: rollback requires a compensating migration
236
+ - `DANGEROUS` — DROP TABLE, DROP COLUMN, or RENAME COLUMN: always requires explicit developer confirmation before proceeding
237
+ - **DANGEROUS migrations require explicit confirmation:** Before writing a DROP or RENAME migration, STOP. Present the risk to the developer and wait for `"confirmed"` before proceeding.
238
+ - **API hard cutover requires confirmation:** Before removing a `/v1/` endpoint or deleting a response field, confirm with the developer. Prefer deprecation + `/v2/` first, hard removal only in the next iteration.
239
+ - **Kafka schema change = coordinated deployment:** Any change to an existing Kafka message schema (adding required fields, removing fields, renaming fields) MUST include a deployment coordination note in the plan. Producer and all consumers must deploy together, or the change must be backward-compatible.
240
+ - **Log the rollback decision:** On every `manage_task initialize`, log a starter entry in `decisions.json`: `"Rollback strategy: [SAFE/RISKY/DANGEROUS] — [one-line rationale]"`. This ensures the PR summary always includes rollback context.
241
+
242
+ ### Breaking Change Detection
243
+ (enforce whenever modifying existing endpoints, entities, or Kafka topics — not just creating new ones)
244
+
245
+ **Endpoint modification rules:**
246
+ - Before changing any existing endpoint: read project-spec.json → who calls this endpoint. If other services or the extension depend on it:
247
+ → NEVER change response shape silently
248
+ → Always propose `/v2/` versioned endpoint first
249
+ → Hard cutover only with explicit developer confirmation
250
+ → Document in plan: which consumers need updating
251
+ - Adding a new required field to response: consumers may break if they use strict deserialization → flag this, propose as optional field first
252
+ - Removing a field from response: always a breaking change → mandatory developer confirmation before proceeding → deprecate first, remove in next iteration
253
+
254
+ **Entity/table modification rules:**
255
+ - Before adding a `NOT NULL` column to an existing table: migration MUST include a `DEFAULT` value or backfill existing rows → without this, migration will fail on a non-empty table → flag as `RISKY` in rollback plan
256
+ - Before renaming a column: check all `@Query` annotations across ALL repos that reference this column name → rename in two phases if other services are affected: Phase 1 — add new column, keep old; Phase 2 — migrate data, drop old (separate PR)
257
+ - Before dropping a column: always `DANGEROUS` — confirm with developer → check all repos for references first
258
+
259
+ **Kafka topic modification rules:**
260
+ - Before changing a message schema: list all consumer services from project-spec.json → confirm coordinated deployment plan (producer and all consumers must deploy together) → flag in rollback plan: "Rollback requires coordinated revert"
261
+
262
+ **The silent break rule:**
263
+ If a change breaks something and the developer did not know — that is a planning failure. Better to over-flag a potential break and be wrong than to under-flag and cause a production incident. When in doubt: flag it, present it, ask.
264
+
265
+ ## Commenting Rules
266
+
267
+ - Comments explain **WHY** — never WHAT.
268
+ - NEVER write obvious comments:
269
+ - `// Get the user` ← NO
270
+ - `// Loop through list` ← NO
271
+ - `// Return result` ← NO
272
+ - Write comments only when the reason behind the code is non-obvious:
273
+ - Why a workaround exists
274
+ - Why a specific algorithm was chosen over a simpler one
275
+ - Why a value is hardcoded in the rare case it must be
276
+
277
+ ## Cross-Task Intelligence
278
+ (TRIGGER: starting any new task)
279
+
280
+ - Before `initialize`, call `search_tasks` with keywords from the new task description
281
+ - If a relevant past task is found, call `get_task_history` to understand how it was done before
282
+ - Call `get_pattern_from_task` if implementing something similar to a past feature
283
+ - Never re-solve a solved problem — check task history first
284
+
package/index.js CHANGED
@@ -1063,6 +1063,37 @@ server.tool("get_pattern_from_task", "Extract reusable implementation patterns f
1063
1063
  };
1064
1064
  return appendTelemetry({ content: [{ type: "text", text: `**Patterns from WI-${work_item_id}: ${spec["title"] || ""}**\n\n${JSON.stringify(patterns, null, 2)}` }] }, inputChars);
1065
1065
  });
1066
+ // ─── Resource & Prompt for AGENTS.md ──────────────────────────────────────────
1067
+ const AGENTS_MD_PATH = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/, "$1")), "AGENTS.md");
1068
+ server.resource("secufusion_rules", "secufusion://rules", async (uri) => {
1069
+ const content = readFileSafe(AGENTS_MD_PATH);
1070
+ if (!content) {
1071
+ throw new Error(`Rules file not found at ${AGENTS_MD_PATH}`);
1072
+ }
1073
+ return {
1074
+ contents: [{
1075
+ uri: uri.href,
1076
+ text: content
1077
+ }]
1078
+ };
1079
+ });
1080
+ server.prompt("secufusion_developer", "Starts a conversation with the SecuFusion developer workflow rules loaded.", async () => {
1081
+ const content = readFileSafe(AGENTS_MD_PATH);
1082
+ if (!content) {
1083
+ throw new Error(`Rules file not found at ${AGENTS_MD_PATH}`);
1084
+ }
1085
+ return {
1086
+ messages: [
1087
+ {
1088
+ role: "user",
1089
+ content: {
1090
+ type: "text",
1091
+ text: `You are now the SecuFusion Senior Architect. Here are your rules:\n\n${content}`
1092
+ }
1093
+ }
1094
+ ]
1095
+ };
1096
+ });
1066
1097
  // ─────────────────────────────────────────────
1067
1098
  // Start transport
1068
1099
  // ─────────────────────────────────────────────
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "secufusion-mcp",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "type": "module",
5
5
  "description": "SecuFusion MCP server - developer workflow tooling with guardrails",
6
6
  "main": "index.js",
7
7
  "files": [
8
8
  "index.js",
9
9
  "index.d.ts",
10
- "README.md"
10
+ "README.md",
11
+ ".secufusion-project-spec.json",
12
+ "AGENTS.md"
11
13
  ],
12
14
  "bin": {
13
15
  "secufusion-mcp": "index.js"