Skip to content

Commit 2cb111f

Browse files
feat(ai): add neo4j knowledge base and remaining uncommitted files
- Add neo4j_kb.rs for security knowledge graph integration - Add .env.example with environment variable templates - Update Cargo.toml with neo4j feature dependencies - Update ollama.rs with advanced prompts support - Update .gitignore and CLAUDE.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 352a9d6 commit 2cb111f

9 files changed

Lines changed: 1844 additions & 1 deletion

File tree

.env.example

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# MCPLint AI Enhancement - Environment Variables (Example)
2+
# Copy this to .env and fill in your actual values
3+
# DO NOT commit .env to git!
4+
5+
# Neo4j Aura Configuration
6+
NEO4J_URI=neo4j+s://YOUR_INSTANCE_ID.databases.neo4j.io
7+
NEO4J_USERNAME=neo4j
8+
NEO4J_PASSWORD=your_neo4j_password_here
9+
NEO4J_DATABASE=neo4j
10+
AURA_INSTANCEID=your_instance_id
11+
AURA_INSTANCENAME=your_instance_name
12+
13+
# Voyage AI Embeddings (get from https://www.voyageai.com/)
14+
# Required for Week 2-3 (Neo4j vector search)
15+
VOYAGE_API_KEY=your_voyage_api_key_here
16+
17+
# Optional: AI Provider Keys (for explain command)
18+
# Anthropic Claude
19+
# ANTHROPIC_API_KEY=your_anthropic_key_here
20+
21+
# OpenAI
22+
# OPENAI_API_KEY=your_openai_key_here
23+
24+
# Ollama (local, no key needed)
25+
# OLLAMA_HOST=http://localhost:11434

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,15 @@ build_*.txt
3636

3737
# Windows special files
3838
nul
39+
40+
# Environment files with secrets
41+
.env
42+
.env.local
43+
.env.*.local
44+
45+
# Neo4j credentials
46+
neo4j.env
47+
48+
# AI API keys
49+
*.key
50+
keys/

CLAUDE.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ src/
6666
multi_scan.rs # Multi-server scanning
6767
ai/ # AI provider integration
6868
engine.rs # ExplainEngine
69+
prompt_templates.rs # Advanced prompt engineering (few-shot, CoT)
70+
neo4j_kb.rs # Neo4j knowledge graph (optional feature)
6971
provider/ # Provider implementations
7072
anthropic.rs # Claude API
7173
openai.rs # GPT API
@@ -168,6 +170,13 @@ OPENAI_API_KEY # For GPT models
168170
OLLAMA_BASE_URL # For local Ollama (default: http://localhost:11434)
169171
MCPLINT_CACHE_DIR # Cache directory
170172
MCPLINT_CACHE_BACKEND # Backend: filesystem, memory, redis
173+
174+
# Neo4j Knowledge Graph (optional, requires --features neo4j)
175+
NEO4J_URI # Neo4j connection URI (e.g., neo4j+s://xxx.databases.neo4j.io)
176+
NEO4J_USERNAME # Database username
177+
NEO4J_PASSWORD # Database password
178+
NEO4J_DATABASE # Database name (default: neo4j)
179+
VOYAGE_API_KEY # Voyage AI API key for embeddings
171180
```
172181

173182
## Exit Codes
@@ -187,6 +196,7 @@ Key crates:
187196
- serde/serde_json: Serialization
188197
- reqwest: HTTP client
189198
- tracing: Logging
199+
- neo4rs: Neo4j graph database (optional, `--features neo4j`)
190200

191201
## Test Coverage
192202

@@ -304,6 +314,45 @@ let engine = ExplainEngine::new(config, cache).await?;
304314
let explanation = engine.explain(&finding).await?;
305315
```
306316

317+
### Advanced Prompt Engineering
318+
319+
```rust
320+
use mcplint::ai::{AdvancedPromptBuilder, VulnCategory, FewShotExample};
321+
322+
// Build prompts with chain-of-thought reasoning and few-shot examples
323+
let builder = AdvancedPromptBuilder::new()
324+
.with_finding(finding.clone())
325+
.with_chain_of_thought(true)
326+
.with_confidence_scoring(true);
327+
328+
let (system_prompt, user_prompt) = builder.build_prompts();
329+
330+
// Categories: Injection, Authentication, Cryptographic, DataExposure,
331+
// Deserialization, Dos, ProtocolViolation, Generic
332+
```
333+
334+
### Neo4j Knowledge Graph (optional)
335+
336+
```rust
337+
#[cfg(feature = "neo4j")]
338+
use mcplint::ai::{
339+
Neo4jConfig, SecurityKnowledgeGraph, VoyageEmbedder, EmbeddingProvider,
340+
SimilarFinding, CweKnowledge,
341+
};
342+
343+
// Connect to Neo4j with vector search for similar vulnerabilities
344+
let config = Neo4jConfig::from_env()?;
345+
let embedder = Arc::new(VoyageEmbedder::new(api_key, "voyage-code-2", 1536));
346+
let kg = SecurityKnowledgeGraph::new(config, embedder).await?;
347+
348+
// Store and search findings
349+
kg.store_finding(&finding, "my-server").await?;
350+
let similar = kg.find_similar_vulnerabilities(&finding, 5, 0.7).await?;
351+
352+
// Retrieve CWE knowledge
353+
let cwe = kg.get_cwe_knowledge("CWE-78").await?;
354+
```
355+
307356
### Caching
308357

309358
```rust
@@ -454,6 +503,8 @@ User Command
454503
| `scanner` | Security vulnerability detection | `ScanEngine`, `Finding`, `Severity` |
455504
| `fuzzer` | Coverage-guided fuzzing | `FuzzSession`, `FuzzResults`, `FuzzCrash` |
456505
| `ai` | AI-powered explanations | `ExplainEngine`, `ExplanationResponse` |
506+
| `ai::prompt_templates` | Advanced prompt engineering | `AdvancedPromptBuilder`, `VulnCategory`, `FewShotExample` |
507+
| `ai::neo4j_kb` | Neo4j knowledge graph (optional) | `SecurityKnowledgeGraph`, `VoyageEmbedder` |
457508
| `cache` | Multi-backend caching | `CacheManager`, `CacheConfig` |
458509
| `baseline` | Diff comparison | `Baseline`, `DiffEngine`, `DiffResult` |
459510
| `fingerprinting` | Schema change detection | `FingerprintHasher`, `ToolFingerprint` |

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ serde_bytes = "0.11"
9595
redis = { version = "0.27", features = ["tokio-comp", "connection-manager"], optional = true }
9696
base64 = "0.22.1"
9797

98+
# Neo4j graph database driver (optional)
99+
neo4rs = { version = "0.7", optional = true }
100+
98101
[dev-dependencies]
99102
# Testing
100103
proptest = "1"
@@ -108,6 +111,7 @@ tokio-test = "0.4"
108111
default = []
109112
fuzz = []
110113
redis = ["dep:redis"]
114+
neo4j = ["dep:neo4rs"]
111115

112116
[lib]
113117
name = "mcplint"

0 commit comments

Comments
 (0)