add_preference
Add a new preference to an Android app's configuration by specifying name, value, and type during development.
Instructions
Adds a new preference given the name, value and type.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | The name/key of the user preference | |
| value | Yes | The value of user preference | |
| type | Yes | The type of the preference value: integer, boolean, float, double, long or string | |
| 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:91-124 (handler)The handler function that executes the 'add_preference' tool logic: validates input, constructs Preference object using parseDataType, calls imported addPreference, returns success/error text response.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)Registration of the 'add_preference' MCP tool using server.tool() with name, description, AddPrefSchema.shape, 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:15-35 (schema)Zod schema definitions for preference tools, including AddPrefSchema = TypedPrefSchema.merge(FileSchema) used for input validation of 'add_preference'.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-22 (registration)Invocation of configurePreferenceTools which registers the 'add_preference' tool (and others) on the MCP server.configurePreferenceTools(server); configureCommonTools(server);