create_mode
Generate custom operational modes by defining unique slugs, display names, role capabilities, allowed tool groups, and optional instructions on the Modes MCP Server for enhanced mode management.
Instructions
Create a new custom mode
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| customInstructions | No | Optional additional instructions for the mode | |
| groups | Yes | Array of allowed tool groups | |
| name | Yes | Display name for the mode | |
| roleDefinition | Yes | Detailed description of the mode's role and capabilities | |
| slug | Yes | Unique slug for the mode (lowercase letters, numbers, and hyphens) |
Implementation Reference
- src/index.ts:362-393 (handler)Handler for the 'create_mode' tool: parses arguments as CustomModeSchema, checks for existing slug, validates with Zod, appends to config array, writes config file atomically, returns success message.case 'create_mode': { const mode = request.params.arguments as z.infer<typeof CustomModeSchema>; const config = await this.readConfig(); if (config.customModes.some((m) => m.slug === mode.slug)) { throw new McpError( ErrorCode.InvalidParams, `Mode with slug "${mode.slug}" already exists` ); } try { CustomModeSchema.parse(mode); } catch (error) { throw new McpError( ErrorCode.InvalidParams, `Invalid mode configuration: ${error instanceof Error ? error.message : String(error)}` ); } config.customModes.push(mode); await this.writeConfig(config); return { content: [ { type: 'text', text: `Mode "${mode.name}" created successfully`, }, ], }; }
- src/index.ts:50-56 (schema)Zod schema defining the structure and validation rules for a custom mode object, used for input validation in create_mode handler.const CustomModeSchema = z.object({ slug: z.string().regex(/^[a-z0-9-]+$/), name: z.string().min(1), roleDefinition: z.string().min(1), groups: z.array(GroupSchema), customInstructions: z.string().optional(), });
- src/index.ts:31-40 (schema)Zod schema for mode groups, supporting simple string groups or tuples with fileRegex and description, referenced by CustomModeSchema.const GroupSchema = z.union([ z.string(), z.tuple([ z.string(), z.object({ fileRegex: z.string(), description: z.string(), }), ]), ]);
- src/index.ts:198-246 (registration)Tool registration in list_tools response, defining name, description, and JSON inputSchema matching the Zod CustomModeSchema.{ name: 'create_mode', description: 'Create a new custom mode', inputSchema: { type: 'object', properties: { slug: { type: 'string', description: 'Unique slug for the mode (lowercase letters, numbers, and hyphens)', }, name: { type: 'string', description: 'Display name for the mode', }, roleDefinition: { type: 'string', description: 'Detailed description of the mode\'s role and capabilities', }, groups: { type: 'array', items: { oneOf: [ { type: 'string' }, { type: 'array', items: [ { type: 'string' }, { type: 'object', properties: { fileRegex: { type: 'string' }, description: { type: 'string' }, }, required: ['fileRegex', 'description'], }, ], }, ], }, description: 'Array of allowed tool groups', }, customInstructions: { type: 'string', description: 'Optional additional instructions for the mode', }, }, required: ['slug', 'name', 'roleDefinition', 'groups'], }, },
- src/index.ts:155-168 (helper)Helper function to atomically write the modes configuration to the JSON file, used by create_mode after updating the config.private async writeConfig(config: z.infer<typeof CustomModesConfigSchema>) { try { await fs.writeFile( this.configPath, JSON.stringify(config, null, 2), 'utf-8' ); } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to write config: ${error instanceof Error ? error.message : String(error)}` ); } }