-
Notifications
You must be signed in to change notification settings - Fork 60
Add Model Context Protocol support with fast-mcp #78
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @jjmata, 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 integrates the fast-mcp
gem to add Model Context Protocol (MCP) support to the application. This enables the application to expose JSON-RPC and Server-Sent Events (SSE) endpoints for interacting with defined tools and resources, facilitating external communication and real-time updates.
Highlights
- MCP Integration: I've added the
fast-mcp
gem to the project, which provides a Ruby implementation of the Model Context Protocol. - Endpoint Exposure: The PR configures and mounts the MCP middleware in the Rails application, exposing
/mcp/messages
for JSON-RPC requests and/mcp/sse
for Server-Sent Events. - Base Classes for MCP Components: I've introduced
ApplicationTool
andApplicationResource
as base classes for defining custom MCP tools and resources, respectively, ensuring automatic registration with the MCP server. - Documentation: Comprehensive documentation (
docs/MCP.md
) has been added to explain how to define tools and resources, and how to interact with the new MCP endpoints.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
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 issue 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 or fill out our survey to provide feedback.
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
-
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. ↩
There was a problem hiding this 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 integrates the fast-mcp
gem to add Model Context Protocol (MCP) support. The changes include adding the gem, creating base classes for resources and tools, providing documentation, and setting up an initializer. The implementation is solid, but I have a couple of suggestions for the initializer file to improve maintainability and ensure correct behavior in the development environment.
server.register_tools(*ApplicationTool.descendants) | ||
server.register_resources(*ApplicationResource.descendants) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the development environment, Rails lazy-loads classes, so ApplicationTool.descendants
and ApplicationResource.descendants
will likely be empty when this initializer runs. This will prevent your tools and resources from being registered. You should explicitly eager-load these directories to ensure all tool and resource classes are loaded before registration.
# Eager-load tools and resources to ensure they are discovered, especially in development.
Rails.autoloaders.main.eager_load_dir(Rails.root.join("app/tools"))
Rails.autoloaders.main.eager_load_dir(Rails.root.join("app/resources"))
server.register_tools(*ApplicationTool.descendants)
server.register_resources(*ApplicationResource.descendants)
config/initializers/fast_mcp.rb
Outdated
FastMcp.mount_in_rails( | ||
Rails.application, | ||
name: Rails.application.class.module_parent_name.underscore.dasherize, | ||
version: '1.0.0', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve maintainability and avoid using a 'magic string', it's a good practice to define the version as a constant. This makes it easier to manage and update the version number, especially if it's referenced elsewhere in the application.
MCP_VERSION = '1.0.0'
FastMcp.mount_in_rails(
Rails.application,
name: Rails.application.class.module_parent_name.underscore.dasherize,
version: MCP_VERSION,
Signed-off-by: Juan José Mata <[email protected]>
Summary
Testing
bundle exec rails test
(fails: ActiveRecord::DatabaseConnectionError: There is an issue connecting with your hostname: 127.0.0.1)https://chatgpt.com/codex/tasks/task_e_6891a4e9a218833284588e9f072ae5db