add_preference
Adds a new user preference with specified name, value, and type to an Android app via the Android Preference Editor MCP Server. Requires device ID, app package name, and filename for precise configuration during development.
Instructions
Adds a new preference given the name, value and type.
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 | |
| type | Yes | The type of the preference value: integer, boolean, float, double, long or string | |
| value | Yes | The value of user preference |
Implementation Reference
- src/tools/prefs.ts:91-123 (handler)The handler function that executes the 'add_preference' tool: validates input using AddPrefSchema, constructs a Preference object, calls the imported addPreference function, and returns a structured response or error.async (input: z.infer<typeof AddPrefSchema>) => { try { validate(input, AddPrefSchema); const { name, value, type, ...connection } = input; const pref: Preference = { key: name, value, type: parseDataType(type), }; await addPreference(pref, connection); return { content: [ { type: "text", text: `Preference added`, }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: error instanceof Error ? error.message : "Unknown error", }, ], }; }
- src/tools/prefs.ts:87-125 (registration)Direct registration of the 'add_preference' MCP tool using server.tool(), including name, description, input schema, and inline handler.server.tool( "add_preference", "Adds a new preference given the name, value and type.", AddPrefSchema.shape, async (input: z.infer<typeof AddPrefSchema>) => { try { validate(input, AddPrefSchema); const { name, value, type, ...connection } = input; const pref: Preference = { key: name, value, type: parseDataType(type), }; await addPreference(pref, connection); return { content: [ { type: "text", text: `Preference added`, }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: error instanceof Error ? error.message : "Unknown error", }, ], }; } } );
- src/schema.ts:23-31 (schema)Zod schema definition for 'add_preference' tool inputs: AddPrefSchema merges TypedPrefSchema (name, value, type) with FileSchema (device/app/file context).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);
- src/index.ts:21-21 (registration)Top-level invocation of configurePreferenceTools(server), which registers the 'add_preference' tool among others on the MCP server.configurePreferenceTools(server);