spring-ai
spring-ai copied to clipboard
mcp: support auth provider by request params
Support a way to auth client-server connection by request params. I think it's necessary, such as, When using Claude Desktop to connect to a remote MCP Server, only one URL can be filled in. If identity authentication and authorization are implemented, passing information from the request parameters is a good choice.
Thank you for taking time to contribute this pull request! You might have already read the [contributor guide][1], but as a reminder, please make sure to:
- Sign the contributor license agreement
- Rebase your changes on the latest
mainbranch and squash your commits - Add/Update unit tests as needed
- Run a build and make sure all tests pass prior to submission
Issue: https://github.com/spring-projects/spring-ai/issues/2888
McpServerAuthProvider example
McpServerAuthProvider implement example
import io.modelcontextprotocol.server.McpServerAuthParam;
import io.modelcontextprotocol.server.McpServerAuthProvider;
import org.springframework.stereotype.Component;
@Component
public class CustomMcpServerAuthProvider implements McpServerAuthProvider {
@Override
public boolean authenticate(McpServerAuthParam param) {
// example: get token param
String token = param.getParams().get("token");
// TODO do something
return true;
}
}
MCP Client(eg: Claude) config
{
"mcpServers": {
"mcp-remote-server-example": {
"url": "http://{your mcp server}/sse?token=xxx"
}
}
}
We are investigating how to add hooks into the core java sdk that then spring can plug into.
We are investigating how to add hooks into the core java sdk that then spring can plug into.
@markpollack Is there a discussion link for this? I'm also very interested