Skip to content

ported MCP to http stream instead of SSE#761

Merged
CodeWithCJ merged 1 commit intomainfrom
dev
Feb 26, 2026
Merged

ported MCP to http stream instead of SSE#761
CodeWithCJ merged 1 commit intomainfrom
dev

Conversation

@CodeWithCJ
Copy link
Owner

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Protocol Migration: The Model Context Protocol (MCP) server has been migrated from using Server-Sent Events (SSE) to a Streamable HTTP transport. This change streamlines communication and improves handling of requests.
  • Dependency Updates: The @modelcontextprotocol/sdk dependency has been updated to version 1.27.1, and the hono framework has been updated to 4.12.3, bringing in the latest features and bug fixes.
  • Stateless Server Architecture: The MCP server now operates in a stateless mode, creating a fresh server and transport instance for each incoming request. This ensures isolation and prevents reuse issues across requests.
  • Enhanced Food Creation and Logging: The createFood tool now automatically logs newly created food items to the user's diary if a meal_type is specified. Additionally, the logFood and logMeal functions have been made more robust by explicitly parsing quantity as a numeric value and improving meal_name fallback logic.
  • Improved Tool Descriptions: The manage_food tool description has been updated to provide clearer instructions regarding numeric quantity values and the distinction between food_name and meal_name.
Changelog
  • SparkyFitnessMCP/package-lock.json
    • Updated @modelcontextprotocol/sdk to version 1.27.1.
    • Updated hono to version 4.12.3.
  • SparkyFitnessMCP/package.json
    • Updated @modelcontextprotocol/sdk dependency to ^1.27.1.
  • SparkyFitnessMCP/src/index.ts
    • Replaced SSE and Stdio server transports with StreamableHTTPServerTransport.
    • Introduced ErrorCode and McpError for improved error handling.
    • Refactored MCP server creation and request handling to be stateless.
    • Added a new /mcp/tools endpoint for simplified tool discovery.
    • Removed legacy SSE connection and message handling routes.
    • Updated server startup log to reflect Streamable HTTP mode.
  • SparkyFitnessMCP/src/tests/logic_verification.ts
    • Updated import paths for handleNutritionTool and handleCoachTool to their new module locations.
  • SparkyFitnessMCP/src/tools/food/database.ts
    • Implemented automatic logging of newly created food items to the diary if meal_type is provided.
  • SparkyFitnessMCP/src/tools/food/index.ts
    • Updated the manage_food tool description with clarifications on quantity and food_name/meal_name usage.
    • Revised the entry_date description.
  • SparkyFitnessMCP/src/tools/food/log.ts
    • Ensured quantity is explicitly parsed as a number in logFood and logMeal.
    • Added fallback logic for meal_name in logMeal to use food_name if available.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@CodeWithCJ CodeWithCJ merged commit 2b02324 into main Feb 26, 2026
1 check passed
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
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(() => {});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Swallowing errors with an empty catch block can hide potential issues during resource cleanup. It's better to at least log the error to aid in debugging if transport.close() fails for some reason.

Suggested change
transport.close().catch(() => {});
transport.close().catch(console.error);

app.use(express.json());
// Simple tools discovery endpoint (no MCP protocol overhead)
app.get("/mcp/tools", (_req, res) => {
res.json({ tools: allTools });
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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).

Suggested change
res.json({ tools: allTools });
res.json({ tools: allTools.map(tool => ({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema })) });

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