http_options
Send HTTP OPTIONS requests with headers, cookies, and timeout settings. Log all request details for security testing, API testing, and web automation workflows.
Instructions
HTTP OPTIONS request with full support (headers, cookies, timeout) - All requests logged
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cookies | No | ||
| headers | No | ||
| timeout | No | ||
| url | Yes |
Implementation Reference
- src/mcp_requests/main.py:194-206 (handler)The primary handler for the 'http_options' MCP tool. Decorated with @mcp.tool() for automatic registration and schema inference from type annotations. Executes HTTP OPTIONS request via shared helper.@mcp.tool() def http_options( url: str, headers: Optional[Dict[str, str]] = None, cookies: Optional[Dict[str, str]] = None, timeout: float = 30.0 ) -> str: """HTTP OPTIONS request with full support (headers, cookies, timeout) - All requests logged""" try: result = make_http_request_with_logging("OPTIONS", url, headers or {}, cookies or {}, "", timeout) return json.dumps(result, indent=2) except Exception as e: return f"Error: {str(e)}"
- src/mcp_requests/main.py:56-101 (helper)Core implementation logic for all HTTP tools including http_options. Performs the actual httpx request, captures full response details, logs everything, and returns structured JSON data.def make_http_request_with_logging(method: str, url: str, headers: dict, cookies: dict, body: str, timeout: float): """Universal HTTP request function with logging""" try: with httpx.Client(timeout=timeout) as client: response = client.request( method=method.upper(), url=url, headers=headers, cookies=cookies, content=body.encode('utf-8') if body else None ) # Log the request and response log_path = log_request_response( method=method.upper(), url=url, headers=headers, cookies=cookies, body=body, status_code=response.status_code, response_headers=dict(response.headers), response_content=response.text, response_length=len(response.text) ) return { "method": method.upper(), "url": url, "status_code": response.status_code, "response_headers": dict(response.headers), "response_content": response.text, "response_length": len(response.text), "request_headers": headers, "request_cookies": cookies, "request_body": body, "logged_to": log_path } except Exception as e: # Log the error log_request_response( method=method.upper(), url=url, headers=headers, cookies=cookies, body=body, status_code=0, response_headers={}, response_content="", response_length=0, error=str(e) ) raise e
- src/mcp_requests/main.py:30-55 (helper)Supporting logger helper that records full request/response details (including headers, cookies, body preview) to timestamped files in ~/mcp_requests_logs for auditing.def log_request_response(method: str, url: str, headers: dict, cookies: dict, body: str, status_code: int, response_headers: dict, response_content: str, response_length: int, error: str = None): """Log complete request and response details""" log_data = { "timestamp": datetime.datetime.now().isoformat(), "request": { "method": method, "url": url, "headers": headers, "cookies": cookies, "body": body, "body_length": len(body) if body else 0 }, "response": { "status_code": status_code if not error else "ERROR", "headers": response_headers if not error else {}, "content_length": response_length if not error else 0, "content_preview": response_content[:500] + "..." if response_content and len(response_content) > 500 else response_content }, "error": error } logger.info(f"HTTP_REQUEST: {json.dumps(log_data, indent=2, ensure_ascii=False)}") return log_path
- src/mcp_requests/main.py:103-103 (registration)MCP server initialization where all @mcp.tool() decorated functions (including http_options) are automatically registered.mcp = FastMCP("HTTP Requests")