Skip to main content
Glama
hofill
by hofill

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

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
confirmYes
body_textNo
body_base64No
status_codeNo
headersNo

Implementation Reference

  • 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],
        }
  • 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,
        )
  • 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
  • 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)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hofill/RequestRepo-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server