monitorQueue
Track queue changes for specific streamers with customizable polling intervals and duration using the MCP server for song request management.
Instructions
Monitor queue changes with configurable polling intervals
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| duration | No | How long to monitor in seconds (default: 300) | |
| interval | No | Polling interval in seconds (default: 30) | |
| streamerName | Yes | The name of the streamer whose queue to monitor |
Implementation Reference
- src/index.ts:220-257 (handler)Handler implementation for the 'monitorQueue' tool. Performs actual polling of the queue at specified intervals for the given duration, collects snapshots with timestamps and queue lengths, and returns the results.case "monitorQueue": { const streamerName = getEffectiveStreamer((args as any)?.streamerName); const interval = ((args as any)?.interval || 30) * 1000; // Convert to milliseconds const duration = ((args as any)?.duration || 300) * 1000; // Convert to milliseconds const startTime = Date.now(); const results: any[] = []; while (Date.now() - startTime < duration) { try { const data = await makeApiRequest(`/streamers/${encodeURIComponent(streamerName)}/queue`); results.push({ timestamp: new Date().toISOString(), queueLength: data.list?.length || 0, data: data, }); if (Date.now() - startTime + interval < duration) { await new Promise(resolve => setTimeout(resolve, interval)); } } catch (error: any) { results.push({ timestamp: new Date().toISOString(), error: error.message, }); break; } } return { content: [ { type: "text", text: JSON.stringify(results, null, 2), }, ], }; }
- src/index.ts:72-93 (schema)Input schema definition for the 'monitorQueue' tool, specifying parameters for streamerName, interval, and duration.name: "monitorQueue", description: "Monitor queue changes with configurable polling intervals", inputSchema: { type: "object", properties: { streamerName: { type: "string", description: "The name of the streamer whose queue to monitor", }, interval: { type: "number", description: "Polling interval in seconds (default: 30)", default: 30, }, duration: { type: "number", description: "How long to monitor in seconds (default: 300)", default: 300, }, }, required: [], },
- src/server.js:347-395 (handler)Alternative handler for 'monitorQueue' tool in the JS version. Simulates monitoring by fetching the initial queue and providing configuration details, with a note on real WebSocket/SSE implementation.case "monitorQueue": { const { streamerName = defaultStreamer, interval = 30, duration = 300 } = args; if (!streamerName) { throw new Error( "streamerName is required. Provide a streamerName or set the DEFAULT_STREAMER environment variable." ); } try { const updates = []; // Initial queue fetch const initialResponse = await fetch(`https://api.streamersonglist.com/v1/streamers/${encodeURIComponent(streamerName)}/queue`); if (initialResponse.ok) { const initialQueue = await initialResponse.json(); updates.push({ timestamp: new Date().toISOString(), type: 'initial', data: initialQueue }); } const monitoringId = `monitor_${streamerName}_${Date.now()}`; return { content: [{ type: "text", text: `Started monitoring queue for ${streamerName}\n` + `Monitoring ID: ${monitoringId}\n` + `Interval: ${interval} seconds\n` + `Duration: ${duration} seconds\n` + `\nNote: This is a simulation. In a real implementation, this would:\n` + `- Establish WebSocket or SSE connection\n` + `- Subscribe to queue updates for the streamer\n` + `- Send real-time notifications of queue changes\n` + `\nInitial queue data:\n${JSON.stringify(updates, null, 2)}` }] }; } catch (error) { return { content: [{ type: "text", text: `Error setting up monitoring: ${error instanceof Error ? error.message : 'Unknown error'}` }] }; } }
- src/server.js:167-188 (schema)Input schema definition for the 'monitorQueue' tool in the JS version, identical to the TS version.name: "monitorQueue", description: "Monitor queue changes with configurable polling intervals", inputSchema: { type: "object", properties: { streamerName: { type: "string", description: "The name of the streamer whose queue to monitor", }, interval: { type: "number", description: "Polling interval in seconds (default: 30)", default: 30, }, duration: { type: "number", description: "How long to monitor in seconds (default: 300)", default: 300, }, }, required: [], },
- src/server.js:258-262 (registration)Registration of all tools including 'monitorQueue' via the ListToolsRequestSchema handler that returns the tools array.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools, }; });