Skip to content

fix connection refused error message #554

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 1 commit into
base: main
Choose a base branch
from

Conversation

nabuskey
Copy link

This PR makes the proxy server print "Connection refused" when the error message contains ECONNREFUSED only.

Motivation and Context

Currently, proxy server prints Connection refused. Is the MCP server running? under two circumstances:

  1. Error message contains Error POSTing to endpoint (HTTP 404) OR
  2. Error message contains ECONNREFUSED.

The term "Connection Refused" usually means it could not make connections at all.
I think it makes sense to print the error message in case of ECONNREFUSED because that's how node defines it.

I don't think it makes sense to print that when the connection was successful but a 404 was returned by the server.

fixes: #543

How Has This Been Tested?

  1. Have a MCP running.
  2. Open Inspector. Confirm it's accessible at /mcp.
  3. Change endpoint to /mcp1, then attempt to connect

Breaking Changes

No breaking changes.

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

Additional context

@cliffhall
Copy link
Contributor

cliffhall commented Jul 2, 2025

Hi @nabuskey!

We already have handlers for these conditions:
Screenshot 2025-07-02 at 4 10 43 PM

The reason the logic was put in place was to clean up the console output of useless stack traces and make it more understandable. In either case, an MCP connection was refused at the endpoint specified. A 404 and an ECONNREFUSED are functionally equivalent in this respect. You check your server and your URL and find that you've done something wrong.

If you feel strongly about it, please amend the PR to log the strings:

  • "Connection refused. Is the MCP server running?" for ECONNREFUSED
  • "Error accessing endpoint (HTTP 404)" for ANY message containing 404 (since it could be a GET, POST, or a DELETE)
  • And only if it isn't one of those, "Error from MCP server:" plus the error and its attendant stacktrace.

@cliffhall cliffhall closed this Jul 2, 2025
@cliffhall cliffhall reopened this Jul 2, 2025
@nabuskey
Copy link
Author

nabuskey commented Jul 3, 2025

Thanks for providing context! I understand where you are coming from now.

I will update this PR with your suggestions since I do think "connection refused" carries a specific meaning (the server was not listening on the port). It will help users troubleshoot issues faster.

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.

Improve connection refused error message
2 participants