-
-
Notifications
You must be signed in to change notification settings - Fork 101
Add custom authentication strategies (#24) #37
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
a9ffe6b to
e43b629
Compare
e43b629 to
c357ac9
Compare
| if authenticate_request(request) | ||
| super | ||
| else | ||
| unauthorized_response(request) |
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.
Should we support Forbidden error responses as well as mentioned in the protocol specs? Maybe is something we want to do at resource/tool level? 🤔
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.
@JulianPasquale I don't think Forbidden should exist at this layer -- it is too difficult when the application knows permission levels with-respect-to resources.
However we could implement some kind of Forbidden response if there is no access to the application point-blank. We would need some kind of RBAC integration or usage of JWT.
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.
Yep, I agree this adds complexity and depends on the specific implementation/use case.
I was just thinking we could provide some kind of "hook" or method to trigger a forbidden response from a resource/tool.
class MyTool < ActionTool::Base
description "My awesome tool"
arguments do
...
end
authorized? do
true # return true by default
user.admin? # or any business logic needed here
end
def call(input:)
...
end
endI realise now this is a candidate for a follow up PR 😁 but you made some really good progress towards that!
|
@JulianPasquale yes the updated protocol specs should have us rethink this a bit 🤔 . Maybe an extension to this work is properly handling oauth flows by providing various |
|
any updates here? i'd really like to get this merged |
|
An idea — passing the token so it's accessible in the |
|
Plus 1 to getting this added. the proc-based auth looks flexible enough to support my desires to do Rails active-record lookups for API tokens. |
|
Would also love to see this merged, the proc-based auth seems perfect to authenticate with custom JWTs. |
|
As it stands, it is impossible to use this gem for multi-tenant, multi-user applications. proc based auth that passes the token/user/context back to the tools/resources/etc. would be invaluable. the modelcontextprotocol/ruby-sdk currently does this: class ApplicationController < ActionController::Base
def index
server = MCP::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))
end
end |
Add support for custom authentication strategies in FastMCP
This PR updates the authentication system with more flexible configuration options. This is outlined in #24 as a feature request.
auth_optionshashMCP_AUTH_TOKEN: Token for token-based authenticationMCP_AUTH_HEADER: Custom header name (defaults to 'Authorization')MCP_AUTH_USER: Username for HTTP Basic authenticationMCP_AUTH_PASSWORD: Password for HTTP Basic authenticationUpdated the documentation, code commentary and default boiler installation code to handle these changes.