adb-shell
Execute Android Debug Bridge shell commands with built-in safety controls like timeouts and output limits to manage Android devices securely.
Instructions
Execute shell commands with safety guards.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | ||
| timeout | No | ms, default: 30000, max: 120000 | |
| maxChars | No | Truncate output to N chars | |
| summaryOnly | No | Compact preview only | |
| previewChars | No | Preview length (default: 200) |
Implementation Reference
- src/tools/adb-shell.ts:14-57 (handler)The handleAdbShellTool function serves as the handler for the adb-shell tool, executing shell commands on an Android device via ADB and formatting/truncating the output based on provided input parameters.
export async function handleAdbShellTool( input: AdbShellInput, context: ServerContext ): Promise<Record<string, unknown>> { const device = await context.deviceState.ensureDevice(context.adb); const deviceId = device.id; const ADB_SHELL_MAX_TIMEOUT = 120_000; const timeout = input.timeout ? Math.min(input.timeout, ADB_SHELL_MAX_TIMEOUT) : undefined; const result = await context.adb.shell(deviceId, input.command, timeout); if (input.summaryOnly) { const previewChars = input.previewChars ?? 200; return { exitCode: result.exitCode, deviceId, summarized: true, stdoutPreview: result.stdout.slice(0, previewChars), stderrPreview: result.stderr.slice(0, previewChars), originalStdoutChars: result.stdout.length, originalStderrChars: result.stderr.length, }; } const maxChars = input.maxChars; const stdout = maxChars ? result.stdout.slice(0, maxChars) : result.stdout; const stderr = maxChars ? result.stderr.slice(0, maxChars) : result.stderr; const truncated = !!maxChars && (result.stdout.length > maxChars || result.stderr.length > maxChars); const response: Record<string, unknown> = { stdout, stderr, exitCode: result.exitCode, deviceId, truncated, }; if (maxChars !== undefined) { response.originalStdoutChars = result.stdout.length; response.originalStderrChars = result.stderr.length; } return response; } - src/tools/adb-shell.ts:4-10 (schema)The Zod schema defining the input requirements and validation for the adb-shell tool.
export const adbShellInputSchema = z.object({ command: z.string(), timeout: z.number().optional(), maxChars: z.number().min(1).optional(), summaryOnly: z.boolean().optional(), previewChars: z.number().min(1).optional(), }); - src/tools/adb-shell.ts:59-79 (registration)The MCP tool definition object for adb-shell, including metadata like name, description, and input schema.
export const adbShellToolDefinition = { name: "adb-shell", description: "Execute shell commands with safety guards.", inputSchema: { type: "object", properties: { command: { type: "string" }, timeout: { type: "number", description: "ms, default: 30000, max: 120000" }, maxChars: { type: "number", description: "Truncate output to N chars" }, summaryOnly: { type: "boolean", description: "Compact preview only" }, previewChars: { type: "number", description: "Preview length (default: 200)" }, }, required: ["command"], }, annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true, }, };