mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 18:04:18 +00:00
feat(plugins): mcp:tools permission and the mcpToolProvider hook
Modelled on the hook:* family rather than on geolocation:read. The host dispatches INTO the child for every tool call, so it needs what HOOK_PERMISSION buys: providersOf()'s active-and-holds-the-grant check, the second gate in invokeHook, and the acting-user binding. That last one is the point. The user is bound host-side from the supervisor's invocation map, so a tool called by user A reaches A's data whatever the model puts in args. The permission keeps no hook: prefix because the surface it opens is MCP, not a TREK render slot, and nothing keys off that prefix. It is the first HOOK_PERMISSION value shaped that way; `satisfies` still holds. One commit, because it cannot be split. requireTotalCoverage makes a HOOK_PERMISSION key with no @PluginHook consumer a boot failure, not a test failure, and PluginRpcRegistryService.onModuleInit runs in every buildApp() — so a half-landed version breaks every integration test in the repo. The generator is chained to it too: it refuses to run without both the en admin label and the CLI hint. 15s is the longest budget of any read hook. The others back a render someone is waiting on and fall back when they time out; this one backs a chat turn, and the plugin is likely calling a third-party API of its own. Still under the supervisor's unused 30s default, which is a hung client rather than a budget. One callTool fn for every tool, since tool names are runtime data and hookContracts() is keyed by (hook, fn). PluginDefinition exists in two copies with no generator between them, so both get McpToolProvider. grantGaps and the dev mock host need no change: both read HOOK_PERMISSION, which is generated. PLUGHOOK-010, plus the CONTRACTS row.
This commit is contained in:
@@ -45,6 +45,7 @@ const CONTRACTS: Array<[hook: string, fn: string, timeoutMs: number]> = [
|
||||
['tripCardProvider', 'getCards', 5000],
|
||||
['notificationChannel', 'send', 8000],
|
||||
['notificationChannel', 'test', 8000],
|
||||
['mcpToolProvider', 'callTool', 15_000],
|
||||
];
|
||||
|
||||
describe('PluginHooks contracts', () => {
|
||||
@@ -137,6 +138,16 @@ describe('PluginHooks contracts', () => {
|
||||
expect(invokeHook).toHaveBeenCalledWith('p', 'notificationChannel', 'test', [{ token: 'x' }], undefined, 8000);
|
||||
});
|
||||
|
||||
it('PLUGHOOK-010 an MCP tool call binds the requesting user and takes the long budget', async () => {
|
||||
// The acting user is the whole reason this goes through a hook rather than a
|
||||
// bespoke invoke: it is bound host-side from the supervisor's invocation map,
|
||||
// so a tool called by user A reaches A's data whatever the model put in args.
|
||||
const { hooks: h, invokeHook } = hooks();
|
||||
const call = { name: 'echo', args: { value: 'x' } };
|
||||
await h.callMcpTool('p', call, 7);
|
||||
expect(invokeHook).toHaveBeenCalledWith('p', 'mcpToolProvider', 'callTool', [call], 7, 15_000);
|
||||
});
|
||||
|
||||
it('PLUGHOOK-009 the class is listed in its module providers', () => {
|
||||
// A decorated class no module registers is invisible to discovery, which would
|
||||
// now fail boot on "no host-side consumer" rather than fail quietly. Cheapest
|
||||
|
||||
Reference in New Issue
Block a user