write_file
Create or overwrite files with automatic parent directory creation. Returns an error in read-only mode to prevent unintended modifications.
Instructions
Write content to a file (create or overwrite). Creates parent dirs. Returns error in read-only mode.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | ||
| path | Yes |
Implementation Reference
- The chisel_write_file function is the handler that delegates to chisel's 'write_file' tool via a client session. It takes a path and content, and calls _chisel_call('write_file', ...) which opens a streaming HTTP session to the chisel MCP server and invokes the 'write_file' tool.
async def chisel_write_file(path: str, content: str) -> str: return await _chisel_call("write_file", path=path, content=content) - The _chisel_call helper function opens a streamable HTTP client session to the chisel server, initializes it, and calls the specified tool with keyword arguments. It is used by chisel_write_file to delegate to the remote 'write_file' tool.
async def _chisel_call(tool: str, **kwargs) -> str: """Open a session to chisel, call one tool, return the text result.""" async with streamablehttp_client(CHISEL_URL, headers=_HEADERS) as (read, write, _): async with ClientSession(read, write) as session: await session.initialize() result = await session.call_tool(tool, kwargs) return result.content[0].text - examples/python-mcp-server/server.py:61-85 (registration)The 'scaffold_module' tool is registered via @mcp.tool() decorator and internally calls chisel_write_file to create a file. While write_file itself isn't directly registered as an MCP tool in this server, it's called as a dependency of registered tools.
@mcp.tool() async def scaffold_module(name: str, directory: str) -> str: """ Scaffold a new Python module with a class stub. Args: name: snake_case module name, e.g. user_service directory: Path relative to the project root, e.g. src/services """ path = f"{CHISEL_ROOT}/{directory}/{name}.py" class_name = "".join(word.title() for word in name.split("_")) content = textwrap.dedent(f"""\ from dataclasses import dataclass @dataclass class {class_name}: \"\"\"TODO: document {class_name}.\"\"\" def run(self) -> None: raise NotImplementedError """) result = await chisel_write_file(path, content) return f"Created {path}\n{result}"