Skip to content

chore: address more comments from #361 #389

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

Merged
merged 7 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,8 @@ async function main() {
try {
await transportRunner.start();
} catch (error: unknown) {
logger.emergency(LogId.serverStartFailure, "server", `Fatal error running server: ${error as string}`);
try {
await transportRunner.close();
logger.error(LogId.serverClosed, "server", "Server closed");
} catch (error: unknown) {
logger.error(LogId.serverCloseFailure, "server", `Error closing server: ${error as string}`);
} finally {
process.exit(1);
}
await transportRunner.close();
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

The transportRunner.close() call in the catch block may fail and throw an error, which would mask the original error. Consider wrapping this in a try-catch block to ensure the original error is preserved and re-thrown.

Suggested change
await transportRunner.close();
try {
await transportRunner.close();
} catch (closeError: unknown) {
logger.error(LogId.serverCloseFailure, "server", `Error closing server during shutdown: ${closeError as string}`);
}

Copilot uses AI. Check for mistakes.

Copy link
Collaborator

@gagik gagik Jul 22, 2025

Choose a reason for hiding this comment

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

hmm.. this is a good point, maybe we can log the error beforehand? I guess we can also preserve the old structure

throw error;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/transports/streamableHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class StreamableHttpRunner extends TransportRunnerBase {
app.enable("trust proxy"); // needed for reverse proxy support
app.use(express.json());

const handleRequest = async (req: express.Request, res: express.Response) => {
const handleSessionRequest = async (req: express.Request, res: express.Response) => {
const sessionId = req.headers["mcp-session-id"];
if (!sessionId) {
res.status(400).json({
Expand Down Expand Up @@ -91,7 +91,7 @@ export class StreamableHttpRunner extends TransportRunnerBase {
promiseHandler(async (req: express.Request, res: express.Response) => {
const sessionId = req.headers["mcp-session-id"];
if (sessionId) {
await handleRequest(req, res);
await handleSessionRequest(req, res);
return;
}

Expand Down Expand Up @@ -141,8 +141,8 @@ export class StreamableHttpRunner extends TransportRunnerBase {
})
);

app.get("/mcp", promiseHandler(handleRequest));
app.delete("/mcp", promiseHandler(handleRequest));
app.get("/mcp", promiseHandler(handleSessionRequest));
app.delete("/mcp", promiseHandler(handleSessionRequest));

this.httpServer = await new Promise<http.Server>((resolve, reject) => {
const result = app.listen(this.userConfig.httpPort, this.userConfig.httpHost, (err?: Error) => {
Expand Down
Loading