-
Notifications
You must be signed in to change notification settings - Fork 23
fix: use factory to refresh session once it is finished #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,10 +27,10 @@ | |
| import httpx | ||
| import logging | ||
| import sys | ||
| from fastmcp import Client | ||
| from fastmcp.client import ClientTransport | ||
| from fastmcp.server.middleware.error_handling import RetryMiddleware | ||
| from fastmcp.server.middleware.logging import LoggingMiddleware | ||
| from fastmcp.server.proxy import FastMCPProxy, ProxyClient | ||
| from fastmcp.server.server import FastMCP | ||
| from mcp import McpError | ||
| from mcp.types import ( | ||
|
|
@@ -60,7 +60,7 @@ async def _initialize_client(transport: ClientTransport): | |
| # logger.debug('First line from kiro %s', line) | ||
| async with contextlib.AsyncExitStack() as stack: | ||
| try: | ||
| client = await stack.enter_async_context(Client(transport)) | ||
| client = await stack.enter_async_context(ProxyClient(transport)) | ||
| if client.initialize_result: | ||
| print( | ||
| client.initialize_result.model_dump_json( | ||
|
|
@@ -157,10 +157,20 @@ async def run_proxy(args) -> None: | |
| transport = create_transport_with_sigv4( | ||
| args.endpoint, service, region, metadata, timeout, profile | ||
| ) | ||
|
|
||
| async with _initialize_client(transport) as client: | ||
|
|
||
| async def client_factory(): | ||
| nonlocal client | ||
| if not client.is_connected(): | ||
| logger.debug('Reinitialize client') | ||
| client = ProxyClient(transport) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if you do
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It returns Client and not ProxyClient |
||
| await client._connect() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When this method throws, the client also hangs, the Can this be done here too? I think it is a bit tricky to get the new json rpc message id. |
||
| return client | ||
|
|
||
| try: | ||
| proxy = FastMCP.as_proxy( | ||
| client, | ||
| proxy = FastMCPProxy( | ||
| client_factory=client_factory, | ||
| name='MCP Proxy for AWS', | ||
| instructions=( | ||
| 'MCP Proxy for AWS provides access to SigV4 protected MCP servers through a single interface. ' | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The client should be a ProxyClient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? We are doing the same as
FastMCP.as_proxyhttps://github.com/jlowin/fastmcp/blob/ba69fba3055db6938ba368dc17275a85ca626ae3/src/fastmcp/server/server.py#L2612-L2634There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we probably want a mix of the if-else branches