Normalize the reporting of connection setup and connection errors. The logging is verbose and different for every server type. This is an attempt to make the console output cleaner and more readable.
* In server/index.js
- in createTransport()
- stringify query params to put them on one line
- remove logging of transport creation (done in callers)
- in /mcp POST handler
- report POST request if session id is present
- otherwise, report new StreamableHttp connection request
- report creation of server transport
- report creation of client transport
- in /stdio GET handler
- report new STDIO connection request
- report creation of server transport
- report creation of client transport
- report 401 as authentication error without stack
- in stderr data handler
- if it includes "MODULE_NOT_FOUND"
- report "Command not found"
- remove transports
- otherwise send to client as usual
- in /sse GET handler
- report SSE connection request
- report 401 as authentication error without stack
- report 404 as server that may not support SSE
- report error with "ECONNREFUSED" as "Connection refused" without stack
- only create, map, and proxy transports if serverTransport was successfully created
- in /message POST handler
- report received POST message
* In mcpProxy.ts
- in onServerError()
- if error message includes 404 OR error.cause includes ECONNREFUSED, report "Connection refused."
This commit is contained in:
parent
438390ecd5
commit
2df723804b
1 changed files with 68 additions and 45 deletions
|
|
@ -6,7 +6,14 @@ function onClientError(error: Error) {
|
|||
}
|
||||
|
||||
function onServerError(error: Error) {
|
||||
console.error("Error from MCP server:", error);
|
||||
if (
|
||||
(error?.message && error.message.includes("Error POSTing to endpoint (HTTP 404)")) ||
|
||||
(error?.cause && JSON.stringify(error.cause).includes('ECONNREFUSED'))
|
||||
) {
|
||||
console.error("Connection refused. Is the MCP server running?");
|
||||
} else {
|
||||
console.error("Error from MCP server:", error);
|
||||
}
|
||||
}
|
||||
|
||||
export default function mcpProxy({
|
||||
|
|
|
|||
Loading…
Reference in a new issue