Implementation:0sec labs 0 getToolsForRole
| Knowledge Sources | |
|---|---|
| Domains | MCP, Tool_Exposure, Agent_Tools |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete tool for resolving the set of available tools for a given agent role and the ToolExecutor that dispatches tool calls to core implementations, provided by the 0security core agent module.
Description
The getToolsForRole function returns the ToolDefinition[] array for a given agent role, gated by scope authorization, feature flags, and engagement posture. It assembles common tools (query_findings, update_todos, done), network tools (http_request, crawl, submit_form, bash), browser tools, scanner tools, binary tools, cloud tools, OAST tools, and more — each gated by its feature flag and scope authorization. The ToolExecutor class dispatches tool calls (http_request, crawl, submit_form, save_finding, etc.) to core implementations. Zod schemas are built per-tool from ToolDefinition.parameters for MCP parameter validation.
Usage
Import these when you need to expose tools to an MCP server or resolve the tool surface for an agent role. They are Step 3 of the MCP server integration workflow.
Code Reference
Source Location
- Repository: 0security
- File: packages/core/src/agent/tools.ts:L9524-9573+ (getToolsForRole), tools.ts:L2862+ (ToolExecutor)
Signature
export function getToolsForRole(
role: string,
opts?: {
hasScope?: boolean;
webMode?: boolean;
hasBrowser?: boolean;
allowScanners?: boolean;
},
): ToolDefinition[];
export class ToolExecutor {
constructor(ctx: ToolContext);
// dispatches tool calls to core implementations
}
interface ToolDefinition {
name: string;
description: string;
parameters: Record<string, ToolParam>;
// ... handler, feature flags, etc.
}
Import
import { getToolsForRole, ToolExecutor } from "@0/core";
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| role | string | Yes /// Agent role name | |
| opts.hasScope | boolean | No /// Scope authorized (gates offensive tools) | |
| opts.allowScanners | boolean | No /// Permit scanner traffic | |
| opts.hasBrowser | boolean | No /// Browser tools available |
Outputs
| Name | Type | Description |
|---|---|---|
| return | ToolDefinition[] /// Array of available tool definitions for the role |
Usage Examples
Resolve tools for MCP server
import { getToolsForRole, ToolExecutor } from "@0/core";
const tools = getToolsForRole("network", {
hasScope: true,
allowScanners: false,
hasBrowser: true,
});
// Register each tool with the MCP server
for (const tool of tools) {
console.log(`Tool: ${tool.name}`);
// Zod schema built from tool.parameters for MCP validation
}
ToolExecutor dispatch
import { ToolExecutor } from "@0/core";
import { osecDB } from "@0/db";
const executor = new ToolExecutor({ db: osecDB("./0.db") });
// MCP tool calls are dispatched via executor