ios_background_test
Verify Lightning Network background tasks like sync, monitor, and payment processing on iOS using LDK MCP Server’s testing tool. Ensure reliable wallet functionality.
Instructions
Test Lightning background processing and channel monitoring
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| taskType | No | Type of background task to test | sync |
Input Schema (JSON Schema)
{
"properties": {
"taskType": {
"default": "sync",
"description": "Type of background task to test",
"enum": [
"sync",
"monitor",
"payment"
],
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/tools/iosBackgroundTest.ts:20-69 (handler)The execute handler function for the 'ios_background_test' tool. It calls IOSService.testBackgroundProcessing() and enriches the response with best practices and Info.plist configuration examples.execute: async (args: any): Promise<ToolResult> => { try { const result = await iosService.testBackgroundProcessing(); return { content: [{ type: 'text', text: JSON.stringify({ success: result.success, message: result.message, swiftExample: result.swiftCode, taskType: args.taskType, bestPractices: [ 'Register background tasks in Info.plist', 'Use BGProcessingTask for longer operations', 'Implement proper task expiration handling', 'Schedule tasks based on user behavior', 'Monitor battery and network conditions', 'Persist state before task completion' ], plistConfiguration: ` <!-- Add to Info.plist --> <key>BGTaskSchedulerPermittedIdentifiers</key> <array> <string>com.yourapp.lightning.sync</string> <string>com.yourapp.lightning.monitor</string> <string>com.yourapp.lightning.payment</string> </array> <key>UIBackgroundModes</key> <array> <string>fetch</string> <string>processing</string> </array>`.trim() }, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: error instanceof Error ? error.message : 'Unknown error' }, null, 2) }], isError: true }; } }
- src/tools/iosBackgroundTest.ts:9-19 (schema)Input schema definition for the tool, specifying an optional taskType parameter.inputSchema: { type: 'object', properties: { taskType: { type: 'string', enum: ['sync', 'monitor', 'payment'], description: 'Type of background task to test', default: 'sync' } } },
- src/index.ts:19-19 (registration)Import statement registering the backgroundTestTool (named 'ios_background_test') into the MCP server.import { backgroundTestTool } from './tools/iosBackgroundTest.js';
- src/index.ts:45-45 (registration)Inclusion of the tool in the aggregated tools array used by the MCP server handlers.backgroundTestTool,
- src/services/iosService.ts:60-128 (helper)Helper method in IOSService that provides detailed Swift code examples for implementing iOS background tasks with Lightning network synchronization.async testBackgroundProcessing(): Promise<{ success: boolean; message: string; swiftCode: string; }> { const swiftCode = ` import BackgroundTasks import LightningDevKit class LightningBackgroundTask { static let taskIdentifier = "com.yourapp.lightning.sync" static func register() { BGTaskScheduler.shared.register( forTaskWithIdentifier: taskIdentifier, using: nil ) { task in self.handleBackgroundTask(task: task as! BGProcessingTask) } } static func schedule() { let request = BGProcessingTaskRequest(identifier: taskIdentifier) request.requiresNetworkConnectivity = true request.requiresExternalPower = false request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60) // 15 minutes do { try BGTaskScheduler.shared.submit(request) } catch { print("Failed to schedule background task: \\(error)") } } static func handleBackgroundTask(task: BGProcessingTask) { // Schedule next task schedule() task.expirationHandler = { // Clean up if task expires task.setTaskCompleted(success: false) } // Perform Lightning sync Task { do { // Sync chain data await ldkManager.syncToTip() // Process pending events await ldkManager.processPendingEvents() // Persist state await ldkManager.persistState() task.setTaskCompleted(success: true) } catch { task.setTaskCompleted(success: false) } } } }`.trim(); return { success: true, message: 'Background processing test completed', swiftCode }; }