Skip to content

Conversation

@jlowin
Copy link
Owner

@jlowin jlowin commented Jun 8, 2025

In-memory transports were inadvertently sending the initialization request twice - once in the low-level SDK and once in FastMCP. This also explains a confusing request_id increment that we couldn't understand last month!

Copilot AI review requested due to automatic review settings June 8, 2025 18:48
@jlowin jlowin added the bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. label Jun 8, 2025
@github-actions github-actions bot added tests client Related to the FastMCP client SDK or client-side functionality. labels Jun 8, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that the client initializes only once by adjusting test expectations and modifying client initialization behavior. Key changes include:

  • Updating expected text results in several server interaction tests to reflect a single initialization.
  • Adding a new test to verify that the initialize method is called only once.
  • Introducing a new parameter (“raise_exceptions” in FastMCPTransport and “client_info” in Client) to improve error handling and information flow.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
tests/server/test_server_interactions.py Updated expected response values reflecting single initialization.
tests/client/test_client.py Added a new test ensuring initialize is invoked only once.
src/fastmcp/client/transports.py Introduced raise_exceptions parameter and reworked session connection logic.
src/fastmcp/client/client.py Added client_info parameter and forwarded it within session kwargs.
Comments suppressed due to low confidence (2)

src/fastmcp/client/transports.py:654

  • Consider updating the docstring of FastMCPTransport.init to document the new 'raise_exceptions' parameter and its intended use.
def __init__(self, mcp: FastMCP | FastMCP1Server, raise_exceptions: bool = False):

src/fastmcp/client/client.py:148

  • Update the Client.init docstring to include a description for the 'client_info' parameter and explain its purpose.
client_info: mcp.types.Implementation | None = None,

@jlowin jlowin merged commit 7fbefe9 into main Jun 8, 2025
5 checks passed
@jlowin jlowin deleted the initialize branch June 8, 2025 18:53
jordicore pushed a commit to jordicore/fastmcp that referenced this pull request Jul 2, 2025
Ensure client is only initialized once
wkpark added a commit to wkpark/langchain-mcp-adapters that referenced this pull request Oct 13, 2025
In-memory transport is officially supported by FastMCP v2. However,
FastMCP v1 already supports in-memory transport (but undocumented)

See also:
 jlowin/fastmcp#758
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. client Related to the FastMCP client SDK or client-side functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants