spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

mcp: support auth provider by request params

Open lambochen opened this issue 6 months ago • 2 comments
trafficstars

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 main branch and squash your commits
  • Add/Update unit tests as needed
  • Run a build and make sure all tests pass prior to submission

lambochen avatar Apr 25 '25 14:04 lambochen

Issue: https://github.com/spring-projects/spring-ai/issues/2888

lambochen avatar Apr 25 '25 15:04 lambochen

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"
    }
  }
}

lambochen avatar Apr 27 '25 03:04 lambochen

We are investigating how to add hooks into the core java sdk that then spring can plug into.

markpollack avatar Apr 29 '25 14:04 markpollack

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

lambochen avatar May 14 '25 02:05 lambochen