BA
Better Auth•3mo ago
Leonardo

Session from MCP call

I have a function on my server code that automatically filters by logged user. That's easy with const session = auth.api.getSession({ headers }) and from there I grab the userId Now I want to call the same function but from an MCP server. This time session will be undefined. I see I can use auth.api.getMcpSession({ headers }) to get the userId from an MCP call and this works fine. So two solutions for the two usecases, that's ok. Question: Is there a quick way to retrieve the userId regardless if this is a regular request from the browser vs a request from an MCP server? Or should I simply try the first, if undefined try the second, if undefined again I assume there's no user logged in and call it a day 😄
1 Reply
Nick
Nick•5w ago
I'm also trying to get hold of user claims, oauth typically has a /userinfo endpoint and one is advertised in .well-known/oauth-authorization-server when using the mcp() plugin, but it doesn't exist in the plugin and returns 404 Did you manage to figure this one out? I'm planning to just implement the userinfo endpoint myself for now which is a bit hacky but should get me moving

Did you find this page helpful?