Skip to content

Support customizing the Faraday client in MCP::Client::HTTP#306

Merged
koic merged 1 commit intomodelcontextprotocol:mainfrom
koic:support_customizing_faraday_client_in_mcp_client_http
Apr 10, 2026
Merged

Support customizing the Faraday client in MCP::Client::HTTP#306
koic merged 1 commit intomodelcontextprotocol:mainfrom
koic:support_customizing_faraday_client_in_mcp_client_http

Conversation

@koic
Copy link
Copy Markdown
Member

@koic koic commented Apr 8, 2026

Motivation and Context

MCP::Client::HTTP builds its Faraday connection internally in a private client method with no way to customize the middleware stack or adapter. Users who need observability (request/response recording, failure logging) or a different HTTP adapter must override a private method, coupling to an internal API.

This accepts an optional block in MCP::Client::HTTP.new that yields the Faraday builder after default middleware is configured, allowing users to add custom middleware or swap the HTTP adapter.

How Has This Been Tested?

Added a test that verifies custom headers set via the block are included in requests. All existing tests continue to pass.

Breaking Changes

None. The block argument is optional, so existing code is unaffected.

Resolves #303

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

## Motivation and Context

`MCP::Client::HTTP` builds its Faraday connection internally in a private `client` method
with no way to customize the middleware stack or adapter.
Users who need observability (request/response recording, failure logging) or
a different HTTP adapter must override a private method, coupling to an internal API.

This accepts an optional block in `MCP::Client::HTTP.new` that yields the Faraday builder
after default middleware is configured, allowing users to add custom middleware or swap
the HTTP adapter.

## How Has This Been Tested?

Added a test that verifies custom headers set via the block are included in requests.
All existing tests continue to pass.

## Breaking Changes

None. The block argument is optional, so existing code is unaffected.

Resolves modelcontextprotocol#303
@koic koic merged commit a05d941 into modelcontextprotocol:main Apr 10, 2026
11 checks passed
@koic koic deleted the support_customizing_faraday_client_in_mcp_client_http branch April 10, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support customizing the Faraday client in MCP::Client::HTTP

2 participants