Skip to content

Commit bcb9754

Browse files
committed
add basic authenticate example
1 parent 0b45f31 commit bcb9754

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

.vscode/mcp.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"servers": {
33
"rails-app-mcp": {
44
"type": "http",
5-
"url": "http://localhost:3000/mcp"
5+
"url": "http://localhost:3000/mcp",
6+
// "headers": {
7+
// // "Basic #{Base64.strict_encode64("mcp_username:mcp_password")}"
8+
// "Authorization": "Basic bWNwX3VzZXJuYW1lOm1jcF9wYXNzd29yZA=="
9+
// }
610
}
711
}
812
}

app/controllers/mcp_controller.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
class McpController < ApplicationController
2+
# Add authenticate_or_request_with_http_basic
3+
include ActionController::HttpAuthentication::Basic::ControllerMethods
4+
5+
# before_action :authenticate!
6+
27
INSTRUCTIONS = <<~INSTRUCTIONS
38
Você é um assistente especializado em gerenciamento de postagens de blog.
49
@@ -36,4 +41,13 @@ def handle
3641

3742
render json: server.handle_json(request.body.read)
3843
end
44+
45+
46+
private
47+
48+
def authenticate!
49+
authenticate_or_request_with_http_basic do |username, password|
50+
username == "mcp_username" && password == "mcp_password"
51+
end
52+
end
3953
end

app/tools/posts/update_tool.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ class UpdateTool < MCP::Tool
1111
},
1212
title: {
1313
type: "string",
14-
description: "Novo título da postagem (opcional)"
14+
description: "Novo título da postagem (opcional)",
15+
minLength: 3,
16+
maxLength: 255
1517
},
1618
description: {
1719
type: "string",
18-
description: "Nova descrição da postagem (opcional)"
20+
description: "Nova descrição da postagem (opcional)",
21+
minLength: 10,
22+
maxLength: 10000
1923
}
2024
},
2125
required: [ "id" ]

0 commit comments

Comments
 (0)