set_file
Configure HTTP responses for specific file paths by setting status codes, headers, and content to simulate server behavior for testing and development.
Instructions
Set one file response.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| confirm | Yes | ||
| body_text | No | ||
| body_base64 | No | ||
| status_code | No | ||
| headers | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/requestrepo_mcp/server.py:261-291 (handler)The set_file handler method in RequestrepoMCPService that contains the core business logic: validates confirm flag, checks that exactly one of body_text or body_base64 is provided, decodes base64 if needed, converts header models, and calls the underlying client.set_file method.
def set_file( self, *, path: str, confirm: bool, body_text: str | None = None, body_base64: str | None = None, status_code: int = 200, headers: list[HeaderInput] | None = None, ) -> dict[str, Any]: self._require_confirm(confirm, "set_file") if (body_text is None) == (body_base64 is None): raise ValueError("Provide exactly one of body_text or body_base64.") body: str | bytes if body_base64 is not None: try: body = base64.b64decode(body_base64, validate=True) except binascii.Error as exc: raise ValueError(f"body_base64 must be valid base64: {exc}") from exc else: body = body_text if body_text is not None else "" header_models = [Header(header=header.header, value=header.value) for header in (headers or [])] updated = self._client().set_file(path, body, status_code=status_code, headers=header_models) return { "updated": updated, "path": path, "status_code": status_code, "headers": [header.model_dump() for header in header_models], } - src/requestrepo_mcp/server.py:456-473 (registration)The MCP tool registration for set_file using the @mcp.tool() decorator, which exposes the set_file functionality to the MCP protocol. This function wraps the service method and defines the tool signature.
@mcp.tool() def set_file( path: str, confirm: bool, body_text: str | None = None, body_base64: str | None = None, status_code: int = 200, headers: list[HeaderInput] | None = None, ) -> dict[str, Any]: """Set one file response.""" return resolved_service.set_file( path=path, confirm=confirm, body_text=body_text, body_base64=body_base64, status_code=status_code, headers=headers, ) - src/requestrepo_mcp/schemas.py:21-25 (schema)The HeaderInput schema class that defines the structure for HTTP headers used in set_file and other file response operations.
class HeaderInput(BaseModel): """HTTP header payload for file responses.""" header: str value: str - src/requestrepo_mcp/schemas.py:28-33 (schema)The FileResponseInput schema class that defines the structure for file responses, used by update_files (related to set_file functionality).
class FileResponseInput(BaseModel): """File response payload for update_files.""" raw_base64: str headers: list[HeaderInput] = Field(default_factory=list) status_code: int = Field(default=200, ge=100, le=599)