Skip to content

Add logging support to local transport used for proxy #69

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ooojustin
Copy link

@ooojustin ooojustin commented May 8, 2025

Adds support for the notifications/message method from the official MCP spec to support sending custom logs to the mcpProxy client, independent of the ones relayed from the server.
It is currently used in connectToRemoteServer to send information which was only logged via console, so that clients have the ability to display status and react to different scenarios.

Using a simple callback from the official SDK in a custom client:

async def _logging_callback(
    params: LoggingMessageNotificationParams,
) -> None:
    logging.info(f"({params.level}) {params.data}")

You can see the connection logs reflected in the following output:

[info] Connecting to MCP server: log_test
[info] Server parameters: command='node' args=['C:\\Users\\justi\\OneDrive\\Documents\\Programming\\mcp-remote\\dist\\proxy.js', 'http://127.0.0.1:8888/sse'] env={} cwd=None encoding='utf-8' encoding_error_handler='strict'       
[info] Creating transport for server: log_test...
[info] Transport created for server: log_test
[info] Creating session for server: log_test...
[info] Initializing session for server: log_test...
--- calls the mcp-remote code here ---
[info] (info) {'status': 'connecting', 'message': '[40756] Connecting to remote server: http://127.0.0.1:8888/sse'}
[info] (info) {'status': 'connecting', 'message': 'Using transport strategy: http-first'}
[info] (error) {'status': 'error', 'message': 'Received error: Error POSTing to endpoint (HTTP 405): Method Not Allowed'}
[info] (info) {'status': 'reconnecting', 'message': 'Recursively reconnecting for reason: falling-back-to-alternate-transport'}
[info] (info) {'status': 'connecting', 'message': '[40756] Connecting to remote server: http://127.0.0.1:8888/sse'}
[info] (info) {'status': 'connecting', 'message': 'Using transport strategy: sse-only'}
[info] (info) {'status': 'connected', 'message': 'Connected to remote server using SSEClientTransport'}
[info] Session initialized for server: log_test
[info] Successfully connected to MCP server 'log_test' with 1 tools
--- internal code to test the MCP and confirm normal logs are still relayed as expected ---
[info] Received message of type: MessageType.TEXT
finish_reason tool_calls
[info] Handling tool call: log_test_log_test
[info] (info) Initial log message # <- normal log relayed from remote MCP
[info] (info) Delayed log message # <- normal log relayed from remote MCP
[info] Successfully called MCP tool 'log_test' on server 'log_test'
finish_reason stop

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.

1 participant