Implementation:0sec labs 0 McpServer Setup
| Knowledge Sources | |
|---|---|
| Domains | MCP, Server, Agent_Integration |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Wrapper for the Model Context Protocol SDK's McpServer and StdioServerTransport that exposes 0security tools to external AI agents, provided by the 0security CLI package.
Description
This is a Wrapper Doc for the @modelcontextprotocol/sdk library. The mcp-server.ts command configures a McpServer instance connected via StdioServerTransport, exposing selected 0security tools to external AI agents. It accepts McpServerOptions controlling backend, target, scope, tools, rate limit, workflows, engagement profile, and WAF evasion. The server resolves tool names via resolveMcpToolNames, builds Zod schemas per tool via zodForParam, and dispatches calls to ToolExecutor.
Usage
Import this when you need to expose 0security analysis tools to an external AI agent via the MCP stdio protocol. It is Step 1 of the MCP server integration workflow.
Code Reference
Source Location
- Repository: 0security
- File: packages/cli/src/commands/mcp-server.ts:L1-150
Signature
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
type McpServerOptions = {
backend?: string; // engine backend
backendsConfig?: string;
target?: string; // scan target
scanId?: string;
workflows?: boolean; // expose workflow tools
session?: string;
engineUrl?: string;
workspace?: string;
allowApply?: boolean;
dbPath?: string;
timeout?: string;
scope?: string; // JSON scope file path
tools?: string; // comma-separated tool allowlist
rateLimit?: string; // per-host rps spec
allowScanners?: boolean;
engagementProfile?: string; // standard | conservative
wafEvasion?: boolean;
};
// Tool name sets
const MCP_LIVE_TOOL_NAMES: Set<string>; // http_request, crawl, submit_form, ...
const MCP_WORKFLOW_TOOL_NAMES: Set<string>; // list_workflows, start_run, ...
function resolveMcpToolNames(raw: string | undefined, workflows?: boolean): ReadonlySet<string>;
Import
// The MCP server is launched via CLI:
// 0 mcp-server --tools http_request,crawl --scope scope.json
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| options | McpServerOptions | No /// Server configuration (backend, target, scope, tools, rate limit) | |
| env | Record | No /// Environment variables (ZERO_MCP_AUTH_JSON, ZERO_SCOPE_FILE, ...) |
Outputs
| Name | Type | Description |
|---|---|---|
| server | McpServer /// Configured MCP server instance on stdio transport |
Usage Examples
Via CLI
# Start MCP server with live tools and scope enforcement
0 mcp-server --scope scope.json --rate-limit "5" --engagement-profile standard
# Expose workflow tools
0 mcp-server --workflows --db-path ./0.db
# With specific tool allowlist
0 mcp-server --tools http_request,crawl,submit_form,save_finding
# Allow scanner traffic
0 mcp-server --allow-scanners --scope scope.json