create_file
Create a new file with specified content at a given path to organize code or documentation in development workflows.
Instructions
Creates a new file with content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| content | No |
Implementation Reference
- The core handler function for the create_file tool. It delegates to write_file and returns a success message.async def create_file(self, path: str, content: str = "") -> str: await self.write_file(path, content) return f"Created file: {path}"
- Pydantic model defining the input schema for the create_file tool: path and optional content.class FileCreate(BaseModel): path: str | Path content: str = ""
- src/mcp_server_code_assist/server.py:90-94 (registration)Registers the create_file tool in the MCP server's list_tools with name, description, and input schema.Tool( name=CodeAssistTools.CREATE_FILE, description="Creates a new file with content", inputSchema=FileCreate.model_json_schema(), ),
- Server-side handler in call_tool that parses arguments into FileCreate model and invokes the file_tools.create_file method.case CodeAssistTools.CREATE_FILE: model = FileCreate(path=arguments["path"], content=arguments["content"]) result = await file_tools.create_file(model.path, model.content) return [TextContent(type="text", text=result)]
- Helper method called by create_file to perform the actual file writing after validation.async def write_file(self, path: str, content: str) -> None: path = await self.validate_path(path) try: path.parent.mkdir(parents=True, exist_ok=True) path.write_text(content) except Exception as e: self.handle_error(e, {"operation": "write", "path": str(path)})