Description
When using the FastApiMCP server, custom headers (particularly those starting with 'x-') are not automatically forwarded from the original HTTP request to the API calls. This can be problematic when working with APIs that rely on custom headers for functionality or authentication.
I would like to modify the header handling logic in the _execute_api_tool
method to explicitly forward all custom headers that start with 'x-' from the original HTTP request. This would involve adding a new section in the header processing block that copies all x- prefixed headers from the original request.
- Forwarding all headers from the original request
The change would be made in the _execute_api_tool
method around line 411, where headers are currently being processed. The modification would look something like this:
if http_request_info and http_request_info.headers:
# Forward Authorization header
if "Authorization" in http_request_info.headers:
headers["Authorization"] = http_request_info.headers["Authorization"]
elif "authorization" in http_request_info.headers:
headers["Authorization"] = http_request_info.headers["authorization"]
# Forward all x- prefixed headers
for header_name, header_value in http_request_info.headers.items():
if header_name.lower().startswith('x-'):
headers[header_name] = header_value
This change would maintain backward compatibility while adding support for custom headers.