change_preference
Modify existing Android app preferences by updating their values. Use device ID, app package name, and filename to target specific settings during development.
Instructions
Changes the value of an existing preference
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| appId | Yes | The application's package name. | |
| deviceId | Yes | The device's serial number. | |
| filename | Yes | The filename with or without the extension. | |
| name | Yes | The name/key of the user preference | |
| value | Yes | The value of user preference |
Implementation Reference
- src/tools/prefs.ts:18-49 (handler)The handler function for the 'change_preference' tool. It validates the input using EditPrefSchema, destructures the preference name, value, and connection details, constructs a PartialPreference object, calls the external changePreference function, and returns a success message or error response.async (input: z.infer<typeof EditPrefSchema>) => { try { validate(input, EditPrefSchema); const { name, value, ...connection } = input; const pref: PartialPreference = { value, key: name, }; await changePreference(pref, connection); return { content: [ { type: "text", text: `Preference changed`, }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: error instanceof Error ? error.message : "Unknown error", }, ], }; }
- src/tools/prefs.ts:14-51 (registration)Registers the 'change_preference' tool with the MCP server, providing the tool name, description, input schema (EditPrefSchema.shape), and the handler function.server.tool( "change_preference", "Changes the value of an existing preference", EditPrefSchema.shape, async (input: z.infer<typeof EditPrefSchema>) => { try { validate(input, EditPrefSchema); const { name, value, ...connection } = input; const pref: PartialPreference = { value, key: name, }; await changePreference(pref, connection); return { content: [ { type: "text", text: `Preference changed`, }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: error instanceof Error ? error.message : "Unknown error", }, ], }; } } );
- src/schema.ts:15-35 (schema)Defines EditPrefSchema by merging PrefSchema (name and value) with FileSchema (deviceId, appId, filename for connection), used for input validation in change_preference tool. Related schemas are also defined here.export const NameSchema = z.object({ name: z.string().describe("The name/key of the user preference"), }); export const PrefSchema = NameSchema.extend({ value: z.string().describe("The value of user preference"), }); export const TypedPrefSchema = PrefSchema.extend({ type: z .string() .describe( "The type of the preference value: integer, boolean, float, double, long or string" ), }); export const AddPrefSchema = TypedPrefSchema.merge(FileSchema); export const EditPrefSchema = PrefSchema.merge(FileSchema); export const DeletePrefSchema = NameSchema.merge(FileSchema);
- src/index.ts:21-21 (registration)Invokes configurePreferenceTools which registers the change_preference tool (among others) with the MCP server instance.configurePreferenceTools(server);
- src/utils.ts:13-21 (helper)The validate helper function used in the change_preference handler to validate input against the EditPrefSchema.export const validate = (input: unknown, type: ZodType) => { const validationResult = type.safeParse(input); if (!validationResult.success) throw new Error( `Invalid input: ${validationResult.error.errors .map((err) => err.message) .join(", ")}` ); };