change_preference
Modify Android app preference values during development by specifying device, app, and preference details.
Instructions
Changes the value of an existing preference
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | The name/key of the user preference | |
| value | Yes | The value of user preference | |
| deviceId | Yes | The device's serial number. | |
| appId | Yes | The application's package name. | |
| filename | Yes | The filename with or without the extension. |
Implementation Reference
- src/tools/prefs.ts:18-50 (handler)Handler function executing the tool logic: validates input with EditPrefSchema, constructs PartialPreference from name and value, calls external changePreference, returns success or error message.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:11-33 (schema)Schema definitions culminating in EditPrefSchema = PrefSchema.merge(FileSchema), providing input validation for name, value, filename, appId, deviceId.export const FileSchema = AppSchema.extend({ filename: z.string().describe("The filename with or without the extension."), }); 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);
- src/tools/prefs.ts:15-51 (registration)Registration of the change_preference tool using server.tool with name, description, EditPrefSchema.shape, and handler function."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/index.ts:21-21 (registration)Top-level call to configurePreferenceTools(server), which registers the change_preference tool among others.configurePreferenceTools(server);