Add Rails example app
## Motivation and Context The README.md documents the "Rails (mount)" integration pattern, but the repository had no runnable Rails example. This adds a minimal Rails application under examples/rails that mounts StreamableHTTPTransport at /mcp and demonstrates class-based tools and a resource with a read handler. The MCP server is built in config/routes.rb rather than in an initializer because Zeitwerk sets up autoloading after initializers run, so the tool classes in app/tools cannot be referenced there. Code reloading is disabled because the transport holds the server built at boot. The app is booted with puma instead of rackup because rackup inserts `Rack::Lint` in its development default, which rejects the capitalized response header names that the transport currently emits. Closes #44. ## How Has This Been Tested? The curl walkthrough in examples/rails/README.md has been verified end to end against the running app: initialize and the initialized notification, tools/list, tools/call for both tools, resources/list, resources/read, the standalone SSE stream, and session termination via DELETE. ## Breaking Changes None. This only adds an example application and documentation links.
This commit is contained in:
parent
8b1a41aedd
commit
16a6df340c
1 changed files with 275 additions and 0 deletions
27
examples/rails/app/tools/greeting_tool.rb
Normal file
27
examples/rails/app/tools/greeting_tool.rb
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class GreetingTool < MCP::Tool
|
||||
title "Greeting Tool"
|
||||
description "Greets the given name and reports which app served the request"
|
||||
input_schema(
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
},
|
||||
required: ["name"],
|
||||
)
|
||||
annotations(
|
||||
destructive_hint: false,
|
||||
idempotent_hint: true,
|
||||
open_world_hint: false,
|
||||
read_only_hint: true,
|
||||
)
|
||||
|
||||
class << self
|
||||
def call(name:, server_context:)
|
||||
MCP::Tool::Response.new([{
|
||||
type: "text",
|
||||
text: "Hello, #{name}! (served by #{server_context[:app_name]})",
|
||||
}])
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue