Generate scoped tokens on the fly

  1. in a multi tenant application, how can i limit the MCP responses via API? im thinking it could be token driven, but how can i get a token for that tenant? considering tokens are hashed so like, i can have a related user to that tenant that is the MCP_USER for that tenant but i dont believe i can programmatically grab the token can i use an extension to make a JWT? another thing i thought of – if i want to guarantee the scope of an MCP request to one specific item, i could, on the fly, generate a token scoped to that item in that collection. from my experiments, the MCP server is smart enough to pick out items but for safety it could be done with a token

  2. really im just looking into generating scoped access tokens on the fly I did think about a tenant having an “agents” collection on the tenant of AI users with specific permissions, but there is no way to pull the token for that “agent” based on the request, IE,

Tenant Y makes request → Look at tenant Ys agent → get the token for that agent → make the MCP request using that token

Ideally, my MCP application

  1. Understands the scope of the request (this is for tenant “X” so it generates a token scoped to only their collections or this is for tenant “X” looking at order “Y” – this token can only grab and make edits to that order)
  2. Uses said token
  3. Destroys it afterwards

The goal is to make the MCP use case smarter and more secure by forcing it to see data only for that tenant.

The authentication and permissions are connected to users, so for this use case I’d make new directus_users for each mcp permission set you want to differentiate, and then use the static tokens of those users for the MCP authentication :slight_smile: