snow-flow 8.3.2 → 8.4.0

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 (45) hide show
  1. package/OPENCODE-SETUP.md +312 -0
  2. package/OPENCODE-TROUBLESHOOTING.md +381 -0
  3. package/dist/agents/index.d.ts +2 -2
  4. package/dist/agents/index.d.ts.map +1 -1
  5. package/dist/agents/index.js +2 -4
  6. package/dist/agents/index.js.map +1 -1
  7. package/dist/cli.js +208 -244
  8. package/dist/cli.js.map +1 -1
  9. package/dist/memory/session-memory.d.ts +80 -0
  10. package/dist/memory/session-memory.d.ts.map +1 -0
  11. package/dist/memory/session-memory.js +468 -0
  12. package/dist/memory/session-memory.js.map +1 -0
  13. package/dist/sdk/claude-agent-sdk-integration.d.ts +4 -1
  14. package/dist/sdk/claude-agent-sdk-integration.d.ts.map +1 -1
  15. package/dist/sdk/claude-agent-sdk-integration.js.map +1 -1
  16. package/dist/sdk/index.d.ts +2 -7
  17. package/dist/sdk/index.d.ts.map +1 -1
  18. package/dist/sdk/index.js +2 -7
  19. package/dist/sdk/index.js.map +1 -1
  20. package/dist/snow-flow-system.d.ts +3 -7
  21. package/dist/snow-flow-system.d.ts.map +1 -1
  22. package/dist/snow-flow-system.js +59 -40
  23. package/dist/snow-flow-system.js.map +1 -1
  24. package/dist/utils/mcp-output-formatter.d.ts +128 -0
  25. package/dist/utils/mcp-output-formatter.d.ts.map +1 -0
  26. package/dist/utils/mcp-output-formatter.js +442 -0
  27. package/dist/utils/mcp-output-formatter.js.map +1 -0
  28. package/dist/utils/opencode-output-interceptor.d.ts +40 -0
  29. package/dist/utils/opencode-output-interceptor.d.ts.map +1 -0
  30. package/dist/utils/opencode-output-interceptor.js +258 -0
  31. package/dist/utils/opencode-output-interceptor.js.map +1 -0
  32. package/package.json +4 -2
  33. package/scripts/bulk-optimize-tools.js +486 -0
  34. package/scripts/cleanup-mcp-servers.js +115 -0
  35. package/scripts/generate-mcp-config.js +45 -0
  36. package/scripts/mcp-server-manager.sh +320 -0
  37. package/scripts/optimize-mcp-tools.ts +410 -0
  38. package/scripts/reset-mcp-servers.js +266 -0
  39. package/scripts/safe-mcp-cleanup.js +151 -0
  40. package/scripts/setup-mcp.js +106 -0
  41. package/scripts/start-mcp-proper.js +76 -0
  42. package/scripts/start-opencode.sh +123 -0
  43. package/scripts/start-sysprops-mcp.js +43 -0
  44. package/scripts/test-todowrite-timeout.js +108 -0
  45. package/scripts/update-version.js +31 -0
@@ -0,0 +1,320 @@
1
+ #!/bin/bash
2
+ #
3
+ # MCP Server Manager for Snow-Flow
4
+ # Helps start, stop, and monitor MCP servers for OpenCode
5
+ #
6
+
7
+ set -e
8
+
9
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10
+ PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
11
+ MCP_SERVER_PATH="$PROJECT_ROOT/dist/mcp/servicenow-mcp-unified/index.js"
12
+ PID_FILE="/tmp/snow-flow-mcp.pid"
13
+ LOG_FILE="/tmp/snow-flow-mcp.log"
14
+
15
+ # Colors
16
+ RED='\033[0;31m'
17
+ GREEN='\033[0;32m'
18
+ YELLOW='\033[1;33m'
19
+ BLUE='\033[0;34m'
20
+ NC='\033[0m' # No Color
21
+
22
+ # Load .env file if exists
23
+ load_env() {
24
+ if [ -f "$PROJECT_ROOT/.env" ]; then
25
+ echo -e "${BLUE}Loading environment from .env...${NC}"
26
+ export $(cat "$PROJECT_ROOT/.env" | grep -v '^#' | grep -v '^$' | xargs)
27
+ else
28
+ echo -e "${YELLOW}Warning: No .env file found${NC}"
29
+ echo "Please create one from .env.example:"
30
+ echo " cp .env.example .env"
31
+ echo " # Then edit .env with your credentials"
32
+ exit 1
33
+ fi
34
+ }
35
+
36
+ # Check if MCP server is built
37
+ check_build() {
38
+ if [ ! -f "$MCP_SERVER_PATH" ]; then
39
+ echo -e "${RED}Error: MCP server not built!${NC}"
40
+ echo "Run: npm run build"
41
+ exit 1
42
+ fi
43
+ echo -e "${GREEN}✓ MCP server binary found${NC}"
44
+ }
45
+
46
+ # Check if MCP server is running
47
+ is_running() {
48
+ if [ -f "$PID_FILE" ]; then
49
+ PID=$(cat "$PID_FILE")
50
+ if ps -p "$PID" > /dev/null 2>&1; then
51
+ return 0
52
+ else
53
+ rm -f "$PID_FILE"
54
+ return 1
55
+ fi
56
+ fi
57
+ return 1
58
+ }
59
+
60
+ # Start MCP server
61
+ start_server() {
62
+ echo -e "${BLUE}Starting MCP server...${NC}"
63
+
64
+ load_env
65
+ check_build
66
+
67
+ if is_running; then
68
+ echo -e "${YELLOW}MCP server is already running (PID: $(cat $PID_FILE))${NC}"
69
+ return 0
70
+ fi
71
+
72
+ # Prepare environment variables
73
+ export SERVICENOW_INSTANCE_URL="https://${SNOW_INSTANCE}"
74
+
75
+ # Try OAuth first, fall back to username/password
76
+ if [ -n "$SNOW_CLIENT_ID" ] && [ -n "$SNOW_CLIENT_SECRET" ]; then
77
+ echo -e "${GREEN}Using OAuth authentication${NC}"
78
+ export SERVICENOW_CLIENT_ID="$SNOW_CLIENT_ID"
79
+ export SERVICENOW_CLIENT_SECRET="$SNOW_CLIENT_SECRET"
80
+ elif [ -n "$SNOW_USERNAME" ] && [ -n "$SNOW_PASSWORD" ]; then
81
+ echo -e "${GREEN}Using Username/Password authentication${NC}"
82
+ export SERVICENOW_USERNAME="$SNOW_USERNAME"
83
+ export SERVICENOW_PASSWORD="$SNOW_PASSWORD"
84
+ else
85
+ echo -e "${RED}Error: No authentication credentials found!${NC}"
86
+ echo "Set either:"
87
+ echo " - SNOW_CLIENT_ID + SNOW_CLIENT_SECRET (OAuth)"
88
+ echo " - SNOW_USERNAME + SNOW_PASSWORD"
89
+ exit 1
90
+ fi
91
+
92
+ # Start server in background
93
+ nohup node "$MCP_SERVER_PATH" > "$LOG_FILE" 2>&1 &
94
+ PID=$!
95
+ echo $PID > "$PID_FILE"
96
+
97
+ # Wait for server to start
98
+ echo -e "${BLUE}Waiting for server to start...${NC}"
99
+ sleep 2
100
+
101
+ if is_running; then
102
+ echo -e "${GREEN}✓ MCP server started (PID: $PID)${NC}"
103
+ echo -e "${BLUE}Log file: $LOG_FILE${NC}"
104
+ return 0
105
+ else
106
+ echo -e "${RED}✗ Failed to start MCP server${NC}"
107
+ echo "Check logs: cat $LOG_FILE"
108
+ return 1
109
+ fi
110
+ }
111
+
112
+ # Stop MCP server
113
+ stop_server() {
114
+ echo -e "${BLUE}Stopping MCP server...${NC}"
115
+
116
+ if ! is_running; then
117
+ echo -e "${YELLOW}MCP server is not running${NC}"
118
+ return 0
119
+ fi
120
+
121
+ PID=$(cat "$PID_FILE")
122
+ kill $PID 2>/dev/null || true
123
+ sleep 1
124
+
125
+ if ! is_running; then
126
+ echo -e "${GREEN}✓ MCP server stopped${NC}"
127
+ rm -f "$PID_FILE"
128
+ else
129
+ echo -e "${YELLOW}Forcing server shutdown...${NC}"
130
+ kill -9 $PID 2>/dev/null || true
131
+ rm -f "$PID_FILE"
132
+ echo -e "${GREEN}✓ MCP server killed${NC}"
133
+ fi
134
+ }
135
+
136
+ # Check MCP server status
137
+ status_check() {
138
+ echo -e "${BLUE}Checking MCP server status...${NC}"
139
+
140
+ check_build
141
+
142
+ if is_running; then
143
+ PID=$(cat "$PID_FILE")
144
+ echo -e "${GREEN}✓ MCP server is running (PID: $PID)${NC}"
145
+
146
+ # Check tool count
147
+ TOOL_COUNT=$(grep -c "Registered:" "$LOG_FILE" 2>/dev/null || echo "0")
148
+ echo -e "${GREEN}✓ Tools loaded: $TOOL_COUNT${NC}"
149
+
150
+ # Check last 10 log lines
151
+ echo -e "\n${BLUE}Recent logs:${NC}"
152
+ tail -n 10 "$LOG_FILE" 2>/dev/null || echo "No logs available"
153
+
154
+ return 0
155
+ else
156
+ echo -e "${RED}✗ MCP server is not running${NC}"
157
+ return 1
158
+ fi
159
+ }
160
+
161
+ # Health check with tool test
162
+ health_check() {
163
+ echo -e "${BLUE}Running health check...${NC}"
164
+
165
+ if ! is_running; then
166
+ echo -e "${RED}✗ MCP server is not running${NC}"
167
+ echo "Start it with: $0 start"
168
+ return 1
169
+ fi
170
+
171
+ load_env
172
+
173
+ # Test JSON-RPC communication
174
+ echo -e "${BLUE}Testing JSON-RPC communication...${NC}"
175
+
176
+ cat > /tmp/mcp_health_check.js << 'EOF'
177
+ const { spawn } = require('child_process');
178
+
179
+ const mcp = spawn('node', [process.argv[2]], {
180
+ env: process.env,
181
+ stdio: ['pipe', 'pipe', 'pipe']
182
+ });
183
+
184
+ let buffer = '';
185
+ let testPassed = false;
186
+
187
+ mcp.stdout.on('data', (data) => {
188
+ buffer += data.toString();
189
+ const lines = buffer.split('\n');
190
+ buffer = lines.pop();
191
+
192
+ lines.forEach(line => {
193
+ if (line.trim() && line.startsWith('{')) {
194
+ try {
195
+ const msg = JSON.parse(line);
196
+ if (msg.result && msg.result.tools) {
197
+ console.log(`✓ Health check passed - ${msg.result.tools.length} tools available`);
198
+ testPassed = true;
199
+ mcp.kill();
200
+ process.exit(0);
201
+ }
202
+ } catch (e) {}
203
+ }
204
+ });
205
+ });
206
+
207
+ mcp.stderr.on('data', (data) => {
208
+ // Ignore stderr logs from server
209
+ });
210
+
211
+ // Initialize and list tools
212
+ setTimeout(() => {
213
+ const initRequest = {
214
+ jsonrpc: '2.0',
215
+ id: 1,
216
+ method: 'initialize',
217
+ params: {
218
+ protocolVersion: '2024-11-05',
219
+ capabilities: {},
220
+ clientInfo: { name: 'health-check', version: '1.0.0' }
221
+ }
222
+ };
223
+ mcp.stdin.write(JSON.stringify(initRequest) + '\n');
224
+ }, 500);
225
+
226
+ setTimeout(() => {
227
+ const toolsRequest = {
228
+ jsonrpc: '2.0',
229
+ id: 2,
230
+ method: 'tools/list'
231
+ };
232
+ mcp.stdin.write(JSON.stringify(toolsRequest) + '\n');
233
+ }, 1500);
234
+
235
+ setTimeout(() => {
236
+ if (!testPassed) {
237
+ console.log('✗ Health check failed - timeout');
238
+ mcp.kill();
239
+ process.exit(1);
240
+ }
241
+ }, 5000);
242
+ EOF
243
+
244
+ SERVICENOW_INSTANCE_URL="https://${SNOW_INSTANCE}" \
245
+ SERVICENOW_CLIENT_ID="$SNOW_CLIENT_ID" \
246
+ SERVICENOW_CLIENT_SECRET="$SNOW_CLIENT_SECRET" \
247
+ SERVICENOW_USERNAME="$SNOW_USERNAME" \
248
+ SERVICENOW_PASSWORD="$SNOW_PASSWORD" \
249
+ node /tmp/mcp_health_check.js "$MCP_SERVER_PATH"
250
+
251
+ rm -f /tmp/mcp_health_check.js
252
+ }
253
+
254
+ # Show logs
255
+ show_logs() {
256
+ if [ -f "$LOG_FILE" ]; then
257
+ echo -e "${BLUE}MCP Server Logs:${NC}"
258
+ tail -f "$LOG_FILE"
259
+ else
260
+ echo -e "${YELLOW}No logs available${NC}"
261
+ fi
262
+ }
263
+
264
+ # Restart server
265
+ restart_server() {
266
+ stop_server
267
+ sleep 1
268
+ start_server
269
+ }
270
+
271
+ # Main menu
272
+ show_help() {
273
+ echo "MCP Server Manager for Snow-Flow"
274
+ echo ""
275
+ echo "Usage: $0 [command]"
276
+ echo ""
277
+ echo "Commands:"
278
+ echo " start Start MCP server"
279
+ echo " stop Stop MCP server"
280
+ echo " restart Restart MCP server"
281
+ echo " status Show server status"
282
+ echo " health Run health check"
283
+ echo " logs Show server logs (live)"
284
+ echo " help Show this help"
285
+ echo ""
286
+ echo "Examples:"
287
+ echo " $0 start # Start MCP server in background"
288
+ echo " $0 health # Test JSON-RPC communication"
289
+ echo " $0 logs # Follow server logs"
290
+ }
291
+
292
+ # Parse command
293
+ case "${1:-help}" in
294
+ start)
295
+ start_server
296
+ ;;
297
+ stop)
298
+ stop_server
299
+ ;;
300
+ restart)
301
+ restart_server
302
+ ;;
303
+ status)
304
+ status_check
305
+ ;;
306
+ health)
307
+ health_check
308
+ ;;
309
+ logs)
310
+ show_logs
311
+ ;;
312
+ help|--help|-h)
313
+ show_help
314
+ ;;
315
+ *)
316
+ echo -e "${RED}Unknown command: $1${NC}"
317
+ show_help
318
+ exit 1
319
+ ;;
320
+ esac