pentestthinkingMCP
Plan penetration testing attack paths with AI reasoning using Beam Search or MCTS strategies to guide CTF and HTB challenge progression.
Instructions
Advanced reasoning tool with multiple strategies including Beam Search and Monte Carlo Tree Search
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| attackStep | Yes | Current attack step or action in the penetration test | |
| attackStepNumber | Yes | Current step number in the attack chain | |
| totalAttackSteps | Yes | Total expected steps in the attack chain | |
| nextAttackStepNeeded | Yes | Whether another attack step is needed | |
| strategyType | No | Attack strategy to use (beam_search or mcts) |
Implementation Reference
- src/index.ts:86-149 (handler)Core handler for CallToolRequestSchema that executes the pentestthinkingMCP tool logic: checks tool name, processes and validates input, invokes Reasoner.processAttackStep, retrieves stats, formats response as JSON.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name !== "pentestthinkingMCP") { return { content: [{ type: "text", text: JSON.stringify({ error: "Unknown tool", success: false }) }], isError: true }; } try { // Process and validate input const step = processInput(request.params.arguments); // Process attack step with selected strategy const response = await reasoner.processAttackStep({ attackStep: step.attackStep, attackStepNumber: step.attackStepNumber, totalAttackSteps: step.totalAttackSteps, nextAttackStepNeeded: step.nextAttackStepNeeded, strategyType: step.strategyType }); // Get attack chain stats const stats = await reasoner.getStats(); // Return enhanced response const result = { attackStepNumber: step.attackStepNumber, totalAttackSteps: step.totalAttackSteps, nextAttackStepNeeded: step.nextAttackStepNeeded, attackStep: step.attackStep, nodeId: response.nodeId, score: response.score, strategyUsed: response.strategyUsed, stats: { totalNodes: stats.totalNodes, averageScore: stats.averageScore, maxDepth: stats.maxDepth, branchingFactor: stats.branchingFactor, strategyMetrics: stats.strategyMetrics } }; return { content: [{ type: "text", text: JSON.stringify(result) }] }; } catch (error) { return { content: [{ type: "text", text: JSON.stringify({ error: error instanceof Error ? error.message : String(error), success: false }) }], isError: true }; } });
- src/index.ts:53-81 (schema)Input schema definition for the pentestthinkingMCP tool, specifying properties, types, descriptions, and required fields.inputSchema: { type: "object", properties: { attackStep: { type: "string", description: "Current attack step or action in the penetration test" }, attackStepNumber: { type: "integer", description: "Current step number in the attack chain", minimum: 1 }, totalAttackSteps: { type: "integer", description: "Total expected steps in the attack chain", minimum: 1 }, nextAttackStepNeeded: { type: "boolean", description: "Whether another attack step is needed" }, strategyType: { type: "string", enum: Object.values(ReasoningStrategy), description: "Attack strategy to use (beam_search or mcts)" } }, required: ["attackStep", "attackStepNumber", "totalAttackSteps", "nextAttackStepNeeded"] }
- src/index.ts:49-83 (registration)Registers the pentestthinkingMCP tool with the MCP server via ListToolsRequestSchema handler.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [{ name: "pentestthinkingMCP", description: "Advanced reasoning tool with multiple strategies including Beam Search and Monte Carlo Tree Search", inputSchema: { type: "object", properties: { attackStep: { type: "string", description: "Current attack step or action in the penetration test" }, attackStepNumber: { type: "integer", description: "Current step number in the attack chain", minimum: 1 }, totalAttackSteps: { type: "integer", description: "Total expected steps in the attack chain", minimum: 1 }, nextAttackStepNeeded: { type: "boolean", description: "Whether another attack step is needed" }, strategyType: { type: "string", enum: Object.values(ReasoningStrategy), description: "Attack strategy to use (beam_search or mcts)" } }, required: ["attackStep", "attackStepNumber", "totalAttackSteps", "nextAttackStepNeeded"] } }] }));
- src/index.ts:25-46 (helper)Helper function to process and validate input arguments for the pentestthinkingMCP tool.function processInput(input: any) { const result = { attackStep: String(input.attackStep || ""), attackStepNumber: Number(input.attackStepNumber || 0), totalAttackSteps: Number(input.totalAttackSteps || 0), nextAttackStepNeeded: Boolean(input.nextAttackStepNeeded), strategyType: input.strategyType as ReasoningStrategy | undefined }; // Validate if (!result.attackStep) { throw new Error("attackStep must be provided"); } if (result.attackStepNumber < 1) { throw new Error("attackStepNumber must be >= 1"); } if (result.totalAttackSteps < 1) { throw new Error("totalAttackSteps must be >= 1"); } return result; }
- src/reasoner.ts:31-45 (helper)Core method in Reasoner class that delegates tool logic to the selected strategy (Beam Search or MCTS) and adds strategy metadata.public async processAttackStep(request: ReasoningRequest): Promise<ReasoningResponse> { // Switch strategy if requested if (request.strategyType && this.strategies.has(request.strategyType as ReasoningStrategy)) { this.currentStrategy = this.strategies.get(request.strategyType as ReasoningStrategy)!; } // Process attack step using current strategy const response = await this.currentStrategy.processAttackStep(request); // Add strategy information to response return { ...response, strategyUsed: this.getCurrentStrategyName() }; }