viewgate-mcp 1.0.45 → 1.0.47
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/dist/index.js +21 -25
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27,9 +27,10 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
27
27
|
const __dirname = path.dirname(__filename);
|
|
28
28
|
dotenv.config({ path: path.join(__dirname, "..", ".env") });
|
|
29
29
|
const port = process.env.PORT || 3000;
|
|
30
|
-
const BACKEND_URL = process.env.
|
|
30
|
+
const BACKEND_URL = process.env.VIEWGATE_BACKEND_URL || "https://view-gate.vercel.app";
|
|
31
31
|
console.error(`[MCP Config] BACKEND_URL: ${BACKEND_URL}`);
|
|
32
|
-
|
|
32
|
+
const LOG_API_KEY = (process.env.VIEWGATE_API_KEY || process.env.API_KEY || "");
|
|
33
|
+
console.error(`[MCP Config] API_KEY Prefix: ${LOG_API_KEY.substring(0, 5)}...`);
|
|
33
34
|
const agentId = `${os.hostname()}-${process.pid}`;
|
|
34
35
|
console.error(`[MCP Identity] Agent ID: ${agentId}`);
|
|
35
36
|
// Store active sessions for SSE: sessionId -> { server, transport }
|
|
@@ -75,8 +76,8 @@ function createMcpServer(apiKey, personalKey) {
|
|
|
75
76
|
case "planning":
|
|
76
77
|
return "planning";
|
|
77
78
|
case "sync_endpoints":
|
|
78
|
-
case "get_synced_endpoints":
|
|
79
79
|
return "sync";
|
|
80
|
+
case "get_synced_endpoints":
|
|
80
81
|
case "get_ai_resolved_tickets":
|
|
81
82
|
return "idle";
|
|
82
83
|
default:
|
|
@@ -89,15 +90,14 @@ function createMcpServer(apiKey, personalKey) {
|
|
|
89
90
|
resetGuard();
|
|
90
91
|
}
|
|
91
92
|
const desiredFlow = getToolFlow(toolName);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
throw new Error("TOOL_CALL_BLOCKED: tool not allowed in active flow");
|
|
95
|
-
}
|
|
93
|
+
// Neutral tools (idle flow) are always allowed and don't interrupt active flows
|
|
94
|
+
if (desiredFlow === "idle") {
|
|
96
95
|
guard.lastTool = toolName;
|
|
97
96
|
guard.lastActivityAt = now;
|
|
98
97
|
return;
|
|
99
98
|
}
|
|
100
|
-
if (guard.flow === "idle") {
|
|
99
|
+
if (guard.flow === "idle" || desiredFlow !== guard.flow) {
|
|
100
|
+
// Implicit flow reset if we are starting a new flow with a "start tool"
|
|
101
101
|
switch (toolName) {
|
|
102
102
|
case "get_ui_components":
|
|
103
103
|
guard.flow = "ui_components";
|
|
@@ -123,16 +123,18 @@ function createMcpServer(apiKey, personalKey) {
|
|
|
123
123
|
guard.step = 1;
|
|
124
124
|
break;
|
|
125
125
|
default:
|
|
126
|
-
|
|
126
|
+
if (guard.flow === "idle") {
|
|
127
|
+
throw new Error("TOOL_CALL_BLOCKED: tool not allowed in idle");
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
throw new Error("TOOL_CALL_BLOCKED: tool not allowed in active flow");
|
|
131
|
+
}
|
|
127
132
|
}
|
|
128
133
|
guard.startedAt = now;
|
|
129
134
|
guard.lastTool = toolName;
|
|
130
135
|
guard.lastActivityAt = now;
|
|
131
136
|
return;
|
|
132
137
|
}
|
|
133
|
-
if (desiredFlow !== guard.flow) {
|
|
134
|
-
throw new Error("TOOL_CALL_BLOCKED: tool not allowed in active flow");
|
|
135
|
-
}
|
|
136
138
|
if (guard.flow === "ui_components") {
|
|
137
139
|
if (toolName === "get_ui_components") {
|
|
138
140
|
if (guard.step > 2)
|
|
@@ -155,18 +157,17 @@ function createMcpServer(apiKey, personalKey) {
|
|
|
155
157
|
}
|
|
156
158
|
else if (guard.flow === "annotations") {
|
|
157
159
|
if (toolName === "get_annotations") {
|
|
158
|
-
|
|
159
|
-
throw new Error("TOOL_CALL_BLOCKED: cannot restart flow at this step");
|
|
160
|
+
// Allow re-fetching at any time during the flow
|
|
160
161
|
guard.step = 1;
|
|
161
162
|
}
|
|
162
163
|
else if (toolName === "mark_annotation_ready") {
|
|
163
164
|
if (guard.step !== 1)
|
|
164
165
|
throw new Error("TOOL_CALL_BLOCKED: unexpected step");
|
|
165
|
-
|
|
166
|
+
// Stop here and reset flow as per USER_REQUEST (MCP only reaches 'applied')
|
|
167
|
+
resetGuard();
|
|
166
168
|
}
|
|
167
169
|
else if (toolName === "mark_annotations_as_live") {
|
|
168
|
-
|
|
169
|
-
throw new Error("TOOL_CALL_BLOCKED: unexpected step");
|
|
170
|
+
// Optional step if the model decides to use it, but no longer part of the required chain
|
|
170
171
|
resetGuard();
|
|
171
172
|
}
|
|
172
173
|
else {
|
|
@@ -175,18 +176,14 @@ function createMcpServer(apiKey, personalKey) {
|
|
|
175
176
|
}
|
|
176
177
|
else if (guard.flow === "ui_improvements") {
|
|
177
178
|
if (toolName === "get_ui_improvements") {
|
|
178
|
-
if (guard.step > 2)
|
|
179
|
-
throw new Error("TOOL_CALL_BLOCKED: cannot restart flow at this step");
|
|
180
179
|
guard.step = 1;
|
|
181
180
|
}
|
|
182
181
|
else if (toolName === "mark_annotation_ready") {
|
|
183
182
|
if (guard.step !== 1)
|
|
184
183
|
throw new Error("TOOL_CALL_BLOCKED: unexpected step");
|
|
185
|
-
|
|
184
|
+
resetGuard();
|
|
186
185
|
}
|
|
187
186
|
else if (toolName === "mark_annotations_as_live") {
|
|
188
|
-
if (guard.step !== 2)
|
|
189
|
-
throw new Error("TOOL_CALL_BLOCKED: unexpected step");
|
|
190
187
|
resetGuard();
|
|
191
188
|
}
|
|
192
189
|
else {
|
|
@@ -216,8 +213,7 @@ function createMcpServer(apiKey, personalKey) {
|
|
|
216
213
|
guard.step = 2;
|
|
217
214
|
}
|
|
218
215
|
else if (toolName === "get_synced_endpoints") {
|
|
219
|
-
if
|
|
220
|
-
throw new Error("TOOL_CALL_BLOCKED: unexpected step");
|
|
216
|
+
// Actually get_synced_endpoints is now neutral, but if called as part of flow, reset.
|
|
221
217
|
resetGuard();
|
|
222
218
|
}
|
|
223
219
|
else {
|
|
@@ -758,7 +754,7 @@ Lang: ${rawData.preferredLanguage === 'es' ? 'ES' : 'EN'}
|
|
|
758
754
|
const useSSE = process.argv.includes("--sse") || process.env.MCP_TRANSPORT === "sse";
|
|
759
755
|
if (!useSSE) {
|
|
760
756
|
const apiKey = process.env.VIEWGATE_API_KEY || process.env.API_KEY || "";
|
|
761
|
-
const personalKey = process.env.VIEWGATE_PERSONAL_KEY || "";
|
|
757
|
+
const personalKey = process.env.VIEWGATE_PERSONAL_KEY || process.env.PERSONAL_KEY || "";
|
|
762
758
|
if (!apiKey) {
|
|
763
759
|
console.error("Error: VIEWGATE_API_KEY environment variable is required.");
|
|
764
760
|
process.exit(1);
|