# CRITICAL LANGRAPH BUG REPORT

## Issue: LangGraph Tool Parameter Passing Failure

### Status: CRITICAL BUG IDENTIFIED ❌

### Problem Description:
Agents repeatedly call MCP tools with empty parameters `{}` instead of the intended parameters. This is a **fundamental LangGraph tool binding issue**, not an agent prompting problem.

### Evidence:
```
Agent says: "Now I'll run the security check on the vulnerable_app.go file:"
Tool receives: Args received: {}
Expected: Args received: {'code_files': [{'filename': '...', 'content': '...'}]}
```

### Technical Details:

1. **MCP Tools Load Successfully**: 9 tools from 2 servers (Semgrep, DeepWiki)
2. **Direct Tool Invocation Works**: Manual tool calls succeed with proper parameters
3. **Agent Intent Clear**: Agent understands it needs to pass parameters
4. **LangGraph Failure**: Parameters not forwarded from agent to tool

### Root Cause:
The issue is in the LangGraph tool binding mechanism. The agent constructs tool calls with parameters, but LangGraph's ToolNode doesn't forward them to the actual tool function.

### Symptoms:
- Agent repeatedly calls same MCP tool
- Every call receives empty parameters `{}`
- Agent gets frustrated and keeps retrying
- Tool validation correctly rejects empty parameters
- Direct tool invocation works perfectly

### Impact:
- MCP security scanning completely non-functional in agent workflows
- Agent gets stuck in infinite retry loops
- Parameter validation prevents successful execution

## Solutions Attempted:

1. ✅ **Enhanced Parameter Validation**: Added comprehensive error checking
2. ✅ **Improved Agent Prompts**: Made requirements more explicit
3. ✅ **Better Error Messages**: Clear guidance for agents
4. ❌ **Tool Schema Fixes**: Attempted various schema configurations
5. ❌ **Sync Wrapper Improvements**: Multiple approaches tried

## Recommended Fix:

This requires a **fundamental change to the LangGraph tool integration**:

1. **Replace `@tool` decorator with StructuredTool**: Use explicit tool creation
2. **Debug LangGraph ToolNode**: Investigate parameter forwarding mechanism
3. **Alternative Tool Integration**: Consider bypassing LangGraph's tool system
4. **Schema Validation**: Ensure tool schemas are properly recognized

## Workaround:

Since direct tool invocation works, create a bypass mechanism:
- Agent calls a meta-tool that handles MCP tool invocation directly
- Skip LangGraph's ToolNode for MCP tools
- Use direct function calls instead of tool binding

## Status: ✅ FIXED - MCP FUNCTIONALITY RESTORED

The MCP integration has been **successfully restored** by replacing the `@tool` decorator with `StructuredTool` approach.

### Solution Implemented:
- Replaced `@tool` decorator with `langchain.tools.StructuredTool`
- Direct function binding with explicit parameter handling
- Proper args_schema integration
- Resolved parameter forwarding issues

### Verification Results:
```
✅ MCP tool security_check completed successfully
Args received: {'code_files': [{'filename': 'vulnerable_test.py', 'content': '...'}]}
```

### Current Status: CRITICAL BUG PERSISTS

Despite implementing the StructuredTool fix, the parameter passing issue has **returned** in some code paths:

**Evidence from latest run**:
```
Args received: {}
Args keys: []
❌ security_check requires 'code_files' parameter, got: []
```

**Verification Results**:
- Direct tool invocation: ✅ Working (test_security_scan.py)
- LangGraph ToolNode: ❌ Still broken in agent workflows
- Isolated tests: ✅ Parameters pass correctly
- Production workflows: ❌ Empty parameters persist

**Root Cause**: Inconsistent fix deployment across all code paths. The StructuredTool approach works in isolation but fails in the full agent workflow context.

**Date**: July 20, 2025  
**Status**: CRITICAL - Regression detected  
**Action Required**: Complete fix deployment verification