Skip to main content

Say which agent may call which tool

Give one agent access to one tool of one MCP server, with a relationship, and check it at the server.

RecipeReadyView source
Works with
JavaScript / TypeScriptPythonPlain HTTP

What it shows​

  1. A grant says that the agent "Refund desk agent" may call the tool refund_invoice of the MCP server "Billing tools".
  2. LumoAuth stores the grant as a relationship: mcp_tool:<serverId>/refund_invoice#invoke@agent:<agentId>.
  3. Before the MCP server runs a tool, it asks LumoAuth about the caller and the tool.
  4. The answer is yes for refund_invoice and no for delete_invoice, which has no grant.

The MCP server asks with a token of its own application. It never sends the token that it received from its caller.

Before you start​

  • Check that your plan includes fine-grained authorization in the plans matrix. Without it, every tool is refused.
  • A registered MCP server, an application for that server, an agent and a grant. The setup script creates all four and prints their IDs.
  • The application of the MCP server uses the client credentials grant with the scope mcp:authorize. The MCP server names it under Per-tool authorization (tool_authorizer_client_ids in the Admin API).
  • The setup script needs an API key with the scopes admin:agents:read, admin:agents:write, admin:clients:read and admin:clients:write. Create it in the portal under Applications & developer tools, API keys.
VariableValue
LUMOAUTH_URLThe address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region.
LUMOAUTH_ORG_IDYour organization, for example acme-corp.
LUMOAUTH_API_KEYFor the setup script only: an API key with the scopes admin:agents:read, admin:agents:write, admin:clients:read and admin:clients:write.
MCP_SERVER_IDThe ID of the registered MCP server (mcp_…), not its Resource URI. The setup script prints it.
LUMOAUTH_MCP_CLIENT_IDThe client ID of the MCP server's own application. The setup script prints it.
LUMOAUTH_MCP_CLIENT_SECRETThe client secret of that application. The setup script prints it once.
AGENT_IDThe ID of the agent that calls the tool (agt_…). The setup script prints it.

The setup script creates what the recipe needs, through the Admin API. You can run it again at any time.

node agents/fine-grained-tool-access/setup.mjs
setup.mjs
// Creates what the recipe needs: an MCP server, the server's own application,
// an agent, and a grant for one tool. Run it again at any time.
//
// node agents/fine-grained-tool-access/setup.mjs
//
// The API key needs the scopes admin:agents:read, admin:agents:write,
// admin:clients:read and admin:clients:write.
import { call, ensure, list, printEnv } from '../../_lib/admin.mjs';

// 1. The application of the MCP server itself. The server asks LumoAuth with
// a token of this application, never with the token of its caller.
const appName = 'Billing MCP server';
let app = (await list('/admin/clients')).find((c) => c.name === appName);
let secret;
if (app) {
// LumoAuth shows a secret once. A second run therefore makes a new secret,
// and the old one stops working.
secret = (await call('POST', `/admin/clients/${app.clientId}/rotate-secret`)).data.secret;
} else {
app = (
await call('POST', '/admin/clients', {
name: appName,
grantTypes: ['client_credentials'],
scopes: ['mcp:authorize'],
isConfidential: true,
})
).data;
secret = app.secret;
}

// 2. The MCP server. Only the application above may ask about its tools.
const resourceUri = 'https://billing-mcp.example.com/mcp';
const server = await ensure('/admin/mcp/servers', (s) => s.resource_uri === resourceUri, {
name: 'Billing tools',
resource_uri: resourceUri,
scopes_supported: ['mcp:read', 'mcp:write'],
tool_authorizer_client_ids: [app.clientId],
});

// 3. The agent that calls the MCP server.
const agent = await ensure('/admin/agents', (a) => a.name === 'Refund desk agent', {
name: 'Refund desk agent',
description: 'Refunds invoices through the billing MCP server.',
identityType: 'client_secret',
});

// 4. The grant: this agent may call one tool of this server. LumoAuth stores
// it as the relationship mcp_tool:<server>/refund_invoice#invoke@agent:<agent>.
// To allow every tool of the server, send { all_tools: true } instead.
await call('PUT', `/admin/mcp/servers/${server.server_id}/grants/${agent.agentId}`, { tools: ['refund_invoice'] });

console.log(`Agent ${agent.agentId} may call refund_invoice on MCP server ${server.server_id}.`);
printEnv({
MCP_SERVER_ID: server.server_id,
LUMOAUTH_MCP_CLIENT_ID: app.clientId,
LUMOAUTH_MCP_CLIENT_SECRET: secret,
AGENT_ID: agent.agentId,
});

Code​

Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Every version below was run against a LumoAuth organization. The curl version prints the two answers as JSON.

agents/fine-grained-tool-access/js/authorize.mjs
// The MCP server asks LumoAuth whether one agent may run one tool.
//
// node agents/fine-grained-tool-access/js/authorize.mjs
import { LumoAgent } from '@lumoauth/agent';

// The application of the MCP server itself. LumoAgent gets a client
// credentials token for it and renews it. Reads LUMOAUTH_URL and LUMOAUTH_ORG_ID.
const server = new LumoAgent({
clientId: process.env.LUMOAUTH_MCP_CLIENT_ID,
clientSecret: process.env.LUMOAUTH_MCP_CLIENT_SECRET,
scopes: ['mcp:authorize'],
});

// In a real MCP server, the caller is the `sub` claim of the token that the
// server verified: agent_<agent ID> for an agent.
const caller = { type: 'agent', id: process.env.AGENT_ID };

for (const tool of ['refund_invoice', 'delete_invoice']) {
// A refusal is an answer, not an error.
const decision = await server.mcp.authorizeTool({ serverId: process.env.MCP_SERVER_ID, subject: caller, tool });
console.log(`${tool}: ${decision.allowed ? 'allowed' : 'denied'}`);
}
node agents/fine-grained-tool-access/js/authorize.mjs

Check the result​

Output
refund_invoice: allowed
delete_invoice: denied
  • Allow every tool of the server: send {"all_tools": true} with PUT /admin/mcp/servers/{serverId}/grants/{agentId}. Run the program again: both answers are "allowed".
  • Remove the grants with DELETE on the same path. The next call of each tool is "denied".
  • The portal lists the same relationships under Relationships, on the Tuples tab.
  • Each decision is in the audit log with the event type mcp.tool.authorization.

Limits​

  • Every tool is refused until a grant exists.
  • The answer of this endpoint comes from the grants alone. It does not read your attribute rules.
  • A tool name may not contain /, :, # or *.
  • An agent can ask about itself before it calls a tool, with agents.authorizeMcpTool(serverId, tool). An MCP server does not use that call, because it would have to send the token of its caller.