create
Generate and write files with specific content to designated paths using structured input, ensuring controlled and secure file creation on the MCP server.
Instructions
Create a new file with specified content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_text | Yes | Content to write to the file | |
| path | Yes | Absolute path where file should be created |
Implementation Reference
- src/editor.ts:84-94 (handler)The core handler function for the 'create' tool in the FileEditor class. It validates the path, writes the provided file_text to the path using writeFile utility, initializes and updates the file history, and returns a success message.async create(args: CreateArgs): Promise<string> { await validatePath('create', args.path); await writeFile(args.path, args.file_text); if (!this.fileHistory[args.path]) { this.fileHistory[args.path] = []; } this.fileHistory[args.path].push(args.file_text); return `File created successfully at: ${args.path}`; }
- src/server.ts:63-80 (registration)Registration of the 'create' tool in the ListToolsRequestSchema handler, defining name, description, and input schema.{ name: "create", description: "Create a new file with specified content", inputSchema: { type: "object", properties: { path: { type: "string", description: "Absolute path where file should be created" }, file_text: { type: "string", description: "Content to write to the file" } }, required: ["path", "file_text"] } },
- src/server.ts:156-161 (registration)Dispatch logic in the CallToolRequestSchema handler for the 'create' tool: validates arguments using isCreateArgs and invokes the editor.create method.case "create": if (!request.params.arguments || !isCreateArgs(request.params.arguments)) { throw new ToolError("Invalid arguments for create command"); // Fixed } result = await this.editor.create(request.params.arguments); break;
- src/types.ts:19-22 (schema)TypeScript interface defining the input arguments for the 'create' tool.export interface CreateArgs extends Record<string, unknown> { path: string; file_text: string; }
- src/types.ts:48-50 (schema)Type guard function for validating 'create' tool arguments at runtime.export function isCreateArgs(args: Record<string, unknown>): args is CreateArgs { return typeof args.path === "string" && typeof args.file_text === "string"; }