Skip to main content
Glama
jau123

MeiGen AI Image Generation MCP

manage_preferences

Read or update default style, aspect ratio, model, style notes, and favorite prompts. Use 'get' at conversation start to load preferences.

Instructions

Read or update user preferences: default style, aspect ratio, model, style notes, and favorite prompts. Call with action "get" at conversation start to load preferences.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform: "get" reads all preferences, "set" updates defaults/styleNotes, "add_favorite" saves a prompt, "remove_favorite" removes by index
styleNoset: preferred default style (e.g. "realistic", "anime", "illustration")
aspectRatioNoset: preferred default aspect ratio. Use "auto" (recommended) to let MeiGen infer per-prompt, or pin a value like "16:9", "1:1", "9:16".
modelNoset: preferred default model name
providerNoset: preferred default provider
styleNotesNoset: free-text style notes (e.g. "cinematic lighting, shallow DOF, brand colors #1A1A2E")
promptNoadd_favorite: the prompt text to save
indexNoremove_favorite: 0-based index of the favorite to remove

Implementation Reference

  • Main tool implementation: exports schema (managePreferencesSchema) and handler function (registerManagePreferences) that registers a 'manage_preferences' tool with 4 actions (get, set, add_favorite, remove_favorite) for reading/writing user preferences.
    /**
     * manage_preferences Tool — read/write user preferences
     *
     * Single tool with action parameter to keep context footprint small (~600 tokens).
     * Storage: ~/.config/meigen/preferences.json (separate from provider config).
     */
    
    import { z } from 'zod'
    import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
    import {
      loadPreferences,
      updateDefaults,
      addFavorite,
      removeFavorite,
    } from '../lib/preferences.js'
    
    export const managePreferencesSchema = {
      action: z.enum(['get', 'set', 'add_favorite', 'remove_favorite'])
        .describe('Action to perform: "get" reads all preferences, "set" updates defaults/styleNotes, "add_favorite" saves a prompt, "remove_favorite" removes by index'),
    
      // For 'set' action
      style: z.string().optional()
        .describe('set: preferred default style (e.g. "realistic", "anime", "illustration")'),
      aspectRatio: z.string().optional()
        .describe('set: preferred default aspect ratio. Use "auto" (recommended) to let MeiGen infer per-prompt, or pin a value like "16:9", "1:1", "9:16".'),
      model: z.string().optional()
        .describe('set: preferred default model name'),
      provider: z.enum(['openai', 'meigen', 'comfyui']).optional()
        .describe('set: preferred default provider'),
      styleNotes: z.string().optional()
        .describe('set: free-text style notes (e.g. "cinematic lighting, shallow DOF, brand colors #1A1A2E")'),
    
      // For 'add_favorite' action
      prompt: z.string().optional()
        .describe('add_favorite: the prompt text to save'),
    
      // For 'remove_favorite' action
      index: z.number().optional()
        .describe('remove_favorite: 0-based index of the favorite to remove'),
    }
    
    export function registerManagePreferences(server: McpServer) {
      server.tool(
        'manage_preferences',
        'Read or update user preferences: default style, aspect ratio, model, style notes, and favorite prompts. Call with action "get" at conversation start to load preferences.',
        managePreferencesSchema,
        { readOnlyHint: false },
        async ({ action, style, aspectRatio, model, provider, styleNotes, prompt, index }) => {
          switch (action) {
            case 'get': {
              const prefs = loadPreferences()
              return {
                content: [{
                  type: 'text' as const,
                  text: JSON.stringify(prefs, null, 2),
                }],
              }
            }
    
            case 'set': {
              const updates: Record<string, string | undefined> = {}
              if (style !== undefined) updates.style = style
              if (aspectRatio !== undefined) updates.aspectRatio = aspectRatio
              if (model !== undefined) updates.model = model
              if (provider !== undefined) updates.provider = provider
    
              const prefs = updateDefaults(updates, styleNotes)
              return {
                content: [{
                  type: 'text' as const,
                  text: `Preferences updated.\n${JSON.stringify(prefs.defaults, null, 2)}` +
                    (styleNotes !== undefined ? `\nStyle notes: ${prefs.styleNotes}` : ''),
                }],
              }
            }
    
            case 'add_favorite': {
              if (!prompt) {
                return {
                  content: [{ type: 'text' as const, text: 'Missing "prompt" parameter for add_favorite action.' }],
                  isError: true,
                }
              }
              const prefs = addFavorite({ prompt, model, aspectRatio })
              return {
                content: [{
                  type: 'text' as const,
                  text: `Saved to favorites (${prefs.favorites.length} total).`,
                }],
              }
            }
    
            case 'remove_favorite': {
              if (index === undefined || index === null) {
                return {
                  content: [{ type: 'text' as const, text: 'Missing "index" parameter for remove_favorite action.' }],
                  isError: true,
                }
              }
              const prefs = removeFavorite(index)
              return {
                content: [{
                  type: 'text' as const,
                  text: `Favorite removed (${prefs.favorites.length} remaining).`,
                }],
              }
            }
    
            default:
              return {
                content: [{ type: 'text' as const, text: `Unknown action: ${action}` }],
                isError: true,
              }
          }
        }
      )
    }
  • Zod schema defining the tool's input: action enum (get/set/add_favorite/remove_favorite) with optional parameters style, aspectRatio, model, provider, styleNotes, prompt, index.
    export const managePreferencesSchema = {
      action: z.enum(['get', 'set', 'add_favorite', 'remove_favorite'])
        .describe('Action to perform: "get" reads all preferences, "set" updates defaults/styleNotes, "add_favorite" saves a prompt, "remove_favorite" removes by index'),
    
      // For 'set' action
      style: z.string().optional()
        .describe('set: preferred default style (e.g. "realistic", "anime", "illustration")'),
      aspectRatio: z.string().optional()
        .describe('set: preferred default aspect ratio. Use "auto" (recommended) to let MeiGen infer per-prompt, or pin a value like "16:9", "1:1", "9:16".'),
      model: z.string().optional()
        .describe('set: preferred default model name'),
      provider: z.enum(['openai', 'meigen', 'comfyui']).optional()
        .describe('set: preferred default provider'),
      styleNotes: z.string().optional()
        .describe('set: free-text style notes (e.g. "cinematic lighting, shallow DOF, brand colors #1A1A2E")'),
    
      // For 'add_favorite' action
      prompt: z.string().optional()
        .describe('add_favorite: the prompt text to save'),
    
      // For 'remove_favorite' action
      index: z.number().optional()
        .describe('remove_favorite: 0-based index of the favorite to remove'),
    }
  • src/server.ts:16-16 (registration)
    Import of registerManagePreferences from the tool module.
    import { registerManagePreferences } from './tools/manage-preferences.js'
  • src/server.ts:269-269 (registration)
    Registration call to registerManagePreferences(server) in the createServer() function.
    registerManagePreferences(server)
  • Helper module with persistence logic: loadPreferences, savePreferences, updateDefaults, addFavorite, removeFavorite, addRecentGeneration. Stores/reads from ~/.config/meigen/preferences.json.
    /**
     * User preferences persistence
     * Storage: ~/.config/meigen/preferences.json
     *
     * Completely independent from config.ts (which handles provider credentials).
     * All functions are safe — read errors return defaults, write errors are silently ignored.
     */
    
    import { readFileSync, writeFileSync, mkdirSync } from 'fs'
    import { join } from 'path'
    import { homedir } from 'os'
    
    // ── Types ──────────────────────────────────────────────────────
    
    export interface UserPreferences {
      version: number
      defaults: {
        style?: string
        aspectRatio?: string
        model?: string
        provider?: string
      }
      styleNotes: string
      favorites: FavoriteEntry[]
      recentSuccessful: RecentEntry[]
    }
    
    export interface FavoriteEntry {
      prompt: string
      model?: string
      aspectRatio?: string
      savedAt: string
    }
    
    export interface RecentEntry {
      prompt: string
      provider: string
      model?: string
      aspectRatio?: string
      generatedAt: string
    }
    
    // ── Constants ──────────────────────────────────────────────────
    
    const MAX_FAVORITES = 20
    const MAX_RECENT = 10
    
    function prefsPath(): string {
      return join(homedir(), '.config', 'meigen', 'preferences.json')
    }
    
    function emptyPreferences(): UserPreferences {
      return {
        version: 1,
        defaults: {},
        styleNotes: '',
        favorites: [],
        recentSuccessful: [],
      }
    }
    
    // ── Read / Write ───────────────────────────────────────────────
    
    export function loadPreferences(): UserPreferences {
      try {
        const raw = readFileSync(prefsPath(), 'utf-8')
        const parsed = JSON.parse(raw) as Partial<UserPreferences>
        // Merge with defaults to ensure all fields exist
        return {
          ...emptyPreferences(),
          ...parsed,
          defaults: { ...emptyPreferences().defaults, ...parsed.defaults },
        }
      } catch {
        return emptyPreferences()
      }
    }
    
    export function savePreferences(prefs: UserPreferences): void {
      const filePath = prefsPath()
      mkdirSync(join(homedir(), '.config', 'meigen'), { recursive: true })
      writeFileSync(filePath, JSON.stringify(prefs, null, 2) + '\n')
    }
    
    // ── Mutations (used by the tool) ───────────────────────────────
    
    export function updateDefaults(
      updates: Partial<UserPreferences['defaults']>,
      styleNotes?: string,
    ): UserPreferences {
      const prefs = loadPreferences()
      for (const [key, value] of Object.entries(updates)) {
        if (value !== undefined) {
          (prefs.defaults as Record<string, string | undefined>)[key] = value || undefined
        }
      }
      if (styleNotes !== undefined) {
        prefs.styleNotes = styleNotes
      }
      savePreferences(prefs)
      return prefs
    }
    
    export function addFavorite(entry: Omit<FavoriteEntry, 'savedAt'>): UserPreferences {
      const prefs = loadPreferences()
      prefs.favorites.unshift({
        ...entry,
        savedAt: new Date().toISOString(),
      })
      if (prefs.favorites.length > MAX_FAVORITES) {
        prefs.favorites = prefs.favorites.slice(0, MAX_FAVORITES)
      }
      savePreferences(prefs)
      return prefs
    }
    
    export function removeFavorite(index: number): UserPreferences {
      const prefs = loadPreferences()
      if (index >= 0 && index < prefs.favorites.length) {
        prefs.favorites.splice(index, 1)
      }
      savePreferences(prefs)
      return prefs
    }
    
    // ── Auto-save (fire-and-forget, called from generate-image.ts) ─
    
    export function addRecentGeneration(entry: {
      prompt: string
      provider: string
      model?: string
      aspectRatio?: string
    }): void {
      try {
        const prefs = loadPreferences()
        prefs.recentSuccessful.unshift({
          ...entry,
          generatedAt: new Date().toISOString(),
        })
        if (prefs.recentSuccessful.length > MAX_RECENT) {
          prefs.recentSuccessful = prefs.recentSuccessful.slice(0, MAX_RECENT)
        }
        savePreferences(prefs)
      } catch {
        // Never fail — this is a background enhancement
      }
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations set readOnlyHint=false, implying mutation, and the description confirms 'Read or update'. No additional behavioral traits are disclosed (e.g., side effects, permissions, rate limits). The description adds minimal value beyond the annotation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, front-loaded with purpose, no wasted words. Efficient and clear.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description lacks details about return values for each action, especially since no output schema is provided. It mentions one usage scenario (get at conversation start) but not the semantics of other actions. Overall adequate but with noticeable gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so each parameter is already documented. The tool description lists the preferences categories but does not add significant new meaning beyond the schema. Baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool reads or updates user preferences and lists specific preferences (style, aspect ratio, model, style notes, favorite prompts). It is a specific verb+resource combination that distinguishes it from sibling tools like generate_image or list_models.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly advises calling with action 'get' at conversation start to load preferences. However, it does not provide guidance on when to use 'set', 'add_favorite', or 'remove_favorite', nor does it mention when not to use this tool or alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jau123/mei-gen-ai-design-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server