ported MCP to http stream instead of SSE#761
Conversation
Summary of ChangesHello @CodeWithCJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the Model Context Protocol (MCP) server's communication layer by transitioning from Server-Sent Events (SSE) to a more modern Streamable HTTP transport. This change is accompanied by essential dependency updates and a shift to a stateless server design, enhancing the server's robustness and scalability. Furthermore, the update includes functional improvements to the food management tools, making food creation and logging more intuitive and reliable for users. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully migrates the MCP server from Server-Sent Events (SSE) to a stateless HTTP stream-based transport, which simplifies the connection handling logic. The dependency updates and code changes in index.ts reflect this transition well. I've also noticed some good defensive programming additions in the tool handlers. My feedback includes a few suggestions to improve error handling, ensure API consistency, and fix a potential bug in data logging logic.
| const date = args.entry_date || new Date().toISOString().split('T')[0]; | ||
|
|
||
| // Final quantity/unit for the log entry | ||
| const logQuantity = parseFloat(args.quantity) || macros?.serving_size || 100; |
There was a problem hiding this comment.
There's a potential bug here when args.quantity is 0. parseFloat('0') results in 0, which is a falsy value. This will cause the expression to incorrectly fall back to macros?.serving_size || 100 instead of using the provided quantity of 0. You should check for null or undefined explicitly to handle this case correctly.
| const logQuantity = parseFloat(args.quantity) || macros?.serving_size || 100; | |
| const logQuantity = args.quantity != null ? parseFloat(args.quantity) : (macros?.serving_size || 100); |
| res.status(404).send("Unknown session"); | ||
| // Clean up after the response is sent | ||
| res.on("finish", () => { | ||
| transport.close().catch(() => {}); |
There was a problem hiding this comment.
| app.use(express.json()); | ||
| // Simple tools discovery endpoint (no MCP protocol overhead) | ||
| app.get("/mcp/tools", (_req, res) => { | ||
| res.json({ tools: allTools }); |
There was a problem hiding this comment.
This endpoint returns the entire tool objects from allTools. For consistency and to prevent accidentally exposing internal properties, it should return the same sanitized data as the ListTools MCP handler, which maps over the tools to select specific properties (name, description, inputSchema).
| res.json({ tools: allTools }); | |
| res.json({ tools: allTools.map(tool => ({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema })) }); |
No description provided.