Skip to content
Draft
Changes from all 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
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ requests.
You can use the `Server#handle_json` method to handle requests.

```ruby
module ModelContextProtocol
class ApplicationController < ActionController::Base

def index
server = ModelContextProtocol::Server.new(
name: "my_server",
version: "1.0.0",
tools: [SomeTool, AnotherTool],
prompts: [MyPrompt],
server_context: { user_id: current_user.id },
)
render(json: server.handle_json(request.body.read).to_h)
end
class MyMcpController < ApplicationController
def index
Copy link

Choose a reason for hiding this comment

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

I would suggest changing the index action (list of results) to show.

Suggested change
def index
def show

server = ModelContextProtocol::Server.new(
name: "my_server",
version: "1.0.0",
tools: [SomeTool, AnotherTool],
prompts: [MyPrompt],
server_context: { user_id: current_user.id },
)

mcp_response = server.handle_json(request.body.read)

render(json: mcp_response ? JSON.parse(mcp_response) : {})
end
end
```
Expand Down Expand Up @@ -275,11 +275,9 @@ class MyTool < ModelContextProtocol::Tool
)

def self.call(message:, server_context:)
Tool::Response.new([{ type: "text", text: "OK" }])
ModelContextProtocol::Tool::Response.new([{ type: "text", text: "OK" }])
end
end

tool = MyTool
```

2. By using the `ModelContextProtocol::Tool.define` method with a block:
Expand Down