mqscript_file_read
Reads file content from specified paths for mobile automation scripts, supporting multiple encodings and storing results in variables for device control operations.
Instructions
Read file content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| encoding | No | File encoding | UTF-8 |
| filePath | Yes | File path to read | |
| resultVariable | No | Variable name to store file content | fileContent |
Implementation Reference
- src/tools/plugin-commands.ts:321-332 (handler)The handler function that implements the core logic of the 'mqscript_file_read' tool by generating an MQScript command to read file content and formatting a response message.handler: async (args: { filePath: string; encoding?: string; resultVariable?: string }) => { const { filePath, encoding = 'UTF-8', resultVariable = 'fileContent' } = args; const script = `${resultVariable} = File.Read("${filePath}", "${encoding}")`; return { content: [ { type: 'text', text: `Generated MQScript file read command:\n\`\`\`\n${script}\n\`\`\`\n\nThis reads file "${filePath}" with encoding "${encoding}" and stores content in "${resultVariable}".` } ] }; }
- src/tools/plugin-commands.ts:300-320 (schema)The input schema defining the parameters for the 'mqscript_file_read' tool: filePath (required), encoding (optional, default UTF-8), resultVariable (optional, default 'fileContent').inputSchema: { type: 'object' as const, properties: { filePath: { type: 'string', description: 'File path to read' }, encoding: { type: 'string', description: 'File encoding', enum: ['UTF-8', 'GBK', 'ASCII'], default: 'UTF-8' }, resultVariable: { type: 'string', description: 'Variable name to store file content', default: 'fileContent' } }, required: ['filePath'] },
- src/index.ts:32-61 (registration)The central tool registry ALL_TOOLS object that spreads FileCommands (containing 'mqscript_file_read') into the list of available tools for MCP requests.const ALL_TOOLS = { // Basic Commands - 基础命令 ...TouchCommands, ...ControlCommands, ...ColorCommands, ...OtherCommands, // Standard Library - 标准库函数 ...MathFunctions, ...StringFunctions, ...TypeConversionFunctions, ...ArrayFunctions, // UI Commands - 界面命令 ...UIControlCommands, ...UIPropertyCommands, ...FloatingWindowCommands, // Extension Commands - 扩展命令 ...ElementCommands, ...DeviceCommands, ...PhoneCommands, ...SysCommands, // Plugin Commands - 插件命令 ...CJsonCommands, ...DateTimeCommands, ...FileCommands, ...TuringCommands, };
- src/index.ts:64-72 (registration)The MCP server request handler for listing tools, which includes 'mqscript_file_read' from ALL_TOOLS in the response.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: Object.values(ALL_TOOLS).map(tool => ({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema, })), }; });
- src/index.ts:75-88 (registration)The MCP server request handler for calling tools, which dispatches to the 'mqscript_file_read' handler when invoked.server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest) => { const { name, arguments: args } = request.params; const tool = Object.values(ALL_TOOLS).find(t => t.name === name); if (!tool) { throw new Error(`Unknown tool: ${name}`); } try { return await tool.handler(args as any || {}); } catch (error) { throw new Error(`Error executing tool ${name}: ${error instanceof Error ? error.message : String(error)}`); } });