Is there an equivalent in the MCP sdk for a <reque...
# http4k
m
Is there an equivalent in the MCP sdk for a request context (e.g. capability request context)?
d
not directly, but if you want you can attach items through attaching things to the connectRequest using the standard mechanism
m
Ok, but to confirm, the connectRequest on the ToolRequest is not the same request that comes out the McpSecurity filters, correct? Because I tried to inject something from the McpSecurity filters but it didn't come through the connectRequest.
d
which security are you using?
m
"Custom"
McpSecurity
for the time being, receiving a special token, validating it and then trying to pass down a principal.
d
yes- if you look at SseFilter then you'll see that the original request is just passed through the security filter in order to check the request - so it's not in the direct path of the MCP call
we might want to update SseFilter to be more like:
Copy code
fun SseFilter(security: Security) = SseFilter { next ->
    {
        var targetRequest = it
        val authResponse = security.filter.then {
            targetRequest = it
            Response(OK)
        }(it)
        when {
            authResponse.status.successful -> next(targetRequest)
            else -> SseResponse(authResponse.status, authResponse.headers, true) { it.close() }
        }
    }
}
and then you can capture the request that gets passed through
there's also the option of doing this through the McpFilter that is passed into the protocol
m
I think the problem is the McpSecurity, since it only accepts a Filter, with no SseFilters, maybe should accept PolyFilter?
d
not really doable because the McpSecurity also contains the routes defined by it (this is used for the oauth one to add teh well known routes - and these need to be unsecured (and hence you can't wrap the entire polyhandler)
m
I see
d
for the moment, you might want to inject an McpFilter and then attach your context there (which will mean checking the security token again, but 🤷 ). Then when SseFilter goes out with that change you can use the standard RequestContext on the input
m
Do you think it make sense to move even the authentication/authorisation at the tool level, ToolFilter, and then have an SseFilter at the end that translate into an actual 401 and 403?
d
well you can - but you'll be allowing anyone to even initialise a connection to your server
m
mhm yeah that's true
Ok maybe keeping some validation results in memory, might be ok, so that the duplicated check in the McpFilter is short-circuited. I'll try that for now.
Anyway this was super useful, thanks!
👍 1