Skip to content

Commit 22704bd

Browse files
refactor(docs): code analysis engine
changes: - file: mcp_demo.py area: core added: [example_syntax_validation, example_selective_validation, example_security_validation, main, example_full_pipeline] - file: _tools_vallm.py area: util added: [handle_validate_imports, validate_code, handle_validate_syntax, validate_syntax, validate_imports, handle_validate_security, +2 more] - file: self_server.py area: core added: [main, handle_tools_call, handle_tools_list, handle_initialize, handle_request] - file: container_e2e.py area: test added: [request, MCPServerSession, main, _read_stderr, unwrap_tool_result, __init__, +1 more] new_tests: 7 - file: quick_test.py area: test added: [main] new_tests: 4 - file: test_client_integration.py area: cli added: [MCPClient, wait_for_server, main, send_request, __init__] new_tests: 6 - file: test_e2e.py area: test added: [run_command, main] new_tests: 6 - file: test_mcp.py area: test added: [main] new_tests: 4 testing: new_tests: 27 scenarios: - tools_list - initialize - validate_imports - validate_security - validate_code - invalid_tool - validate_syntax - tool_schema - security_validation - syntax_validation # +17 more dependencies: flow: "_tools_vallm→validation, test_mcp→validation" - _tools_vallm.py -> validation.py - test_mcp.py -> validation.py stats: lines: "+4288/-1317 (net +2971)" files: 34 complexity: "Large structural change (normalized)"
1 parent 7c8263b commit 22704bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+4317
-1320
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
124124
- **Tree-sitter for all** — syntax validation for 165+ languages
125125
- **Example 07** — comprehensive multi-language demo with 8 languages
126126

127+
## [0.1.53] - 2026-03-24
128+
129+
### Docs
130+
- Update MCP_INTEGRATION_SUMMARY.md
131+
- Update README.md
132+
- Update docs/README.md
133+
- Update mcp/README.md
134+
- Update project/README.md
135+
- Update project/context.md
136+
137+
### Test
138+
- Update test_mcp.py
139+
140+
### Other
141+
- Update examples/mcp_demo.py
142+
- Update mcp/__init__.py
143+
- Update mcp/server/__init__.py
144+
- Update mcp/server/_tools_vallm.py
145+
- Update mcp/server/self_server.py
146+
- Update mcp/tests/Dockerfile.client
147+
- Update mcp/tests/Dockerfile.test
148+
- Update mcp/tests/__init__.py
149+
- Update mcp/tests/container_e2e.py
150+
- Update mcp/tests/docker-compose.yml
151+
- ... and 22 more files
152+
127153
## [0.1.52] - 2026-03-24
128154

129155
### Test

MCP_INTEGRATION_SUMMARY.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# MCP Vallm Integration - Summary
2+
3+
## ✅ Integration Complete
4+
5+
The MCP (Model Context Protocol) integration for vallm has been successfully implemented and tested.
6+
7+
## 📁 Files Created/Modified
8+
9+
### Core MCP Integration
10+
- `mcp/server/_tools_vallm.py` - Complete MCP tools implementation (509 lines)
11+
- `mcp/server/self_server.py` - MCP server with fixed imports (184 lines)
12+
- `mcp_server.py` - Startup script for project root (38 lines)
13+
14+
### Testing & Documentation
15+
- `test_mcp.py` - Comprehensive manual test suite
16+
- `mcp/tests/quick_test.py` - Fast local validation checks
17+
- `mcp/tests/container_e2e.py` - Container-side end-to-end runner
18+
- `mcp/tests/test_e2e.py` - Host-side Docker build/run checks
19+
- `examples/mcp_demo.py` - Working examples and demonstrations
20+
- `README.md` - Updated with MCP integration section
21+
- `mcp/README.md` - Updated with quick start guide
22+
23+
## 🛠 Available MCP Tools
24+
25+
| Tool | Description | Status |
26+
|------|-------------|--------|
27+
| `validate_syntax` | Multi-language syntax checking | ✅ Working |
28+
| `validate_imports` | Import resolution validation | ✅ Working |
29+
| `validate_security` | Security issue detection | ✅ Working |
30+
| `validate_code` | Full pipeline validation | ✅ Working |
31+
32+
## 🚀 Usage
33+
34+
### Start MCP Server
35+
```bash
36+
python3 mcp_server.py
37+
38+
# Or use the packaged module directly
39+
python3 -m mcp.server.self_server
40+
```
41+
42+
### Claude Desktop Configuration
43+
```json
44+
{
45+
"mcpServers": {
46+
"vallm": {
47+
"command": "python3",
48+
"args": ["/path/to/vallm/mcp_server.py"],
49+
"env": {
50+
"PYTHONPATH": "/path/to/vallm/src"
51+
}
52+
}
53+
}
54+
}
55+
```
56+
57+
### Example Tool Call
58+
```json
59+
{
60+
"method": "tools/call",
61+
"params": {
62+
"name": "validate_security",
63+
"arguments": {
64+
"code": "eval('1+1')",
65+
"language": "python"
66+
}
67+
}
68+
}
69+
```
70+
71+
## ✅ Testing Results
72+
73+
All tests pass successfully:
74+
- ✅ Syntax validation (Python, JavaScript, error detection)
75+
- ✅ Import validation (valid/invalid imports)
76+
- ✅ Security validation (secure/insecure code patterns)
77+
- ✅ Full pipeline validation (multiple validators, selective enabling)
78+
- ✅ MCP server communication (initialize, tools/list, tools/call)
79+
- ✅ Container-side e2e runner (`mcp/tests/container_e2e.py`)
80+
- ✅ Quick local validation (`mcp/tests/quick_test.py`)
81+
82+
## 📊 Features
83+
84+
### Multi-Language Support
85+
- Python, JavaScript, TypeScript, Go, Rust, Java, C/C++, Ruby, PHP, Swift, Kotlin, Scala, and more
86+
87+
### Validation Types
88+
- **Syntax**: AST parsing and tree-sitter error detection
89+
- **Imports**: Module resolution and dependency checking
90+
- **Security**: Pattern-based vulnerability detection
91+
- **Complexity**: Cyclomatic complexity and maintainability metrics
92+
- **Full Pipeline**: Combined validation with configurable options
93+
94+
### Response Format
95+
Consistent JSON responses with:
96+
- Success status and verdict
97+
- Detailed scores and weights
98+
- Structured issue reporting
99+
- Validator-specific details
100+
101+
## 🔧 Integration Details
102+
103+
### Architecture
104+
- `_tools_vallm.py` provides the core validation functions
105+
- `self_server.py` handles MCP protocol communication
106+
- `mcp_server.py` provides easy startup from project root
107+
108+
### Error Handling
109+
- Graceful failure with detailed error messages
110+
- Consistent response format across all tools
111+
- Proper exception handling and logging
112+
113+
### Performance
114+
- Fast syntax validation (milliseconds)
115+
- Efficient import resolution
116+
- Pattern-based security scanning
117+
- Configurable validation pipeline
118+
119+
## 🎯 Next Steps
120+
121+
The MCP integration is ready for production use. Users can:
122+
1. Start the MCP server
123+
2. Configure their LLM client (Claude Desktop, etc.)
124+
3. Use vallm validation tools directly in conversations
125+
126+
All validation capabilities of vallm are now available through the MCP interface, making it easy to integrate code validation into AI-assisted development workflows.

README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ vallm validates code proposals through a **four-tier pipeline** — from millise
3737
- **AST similarity scoring** with normalized fingerprinting
3838
- **Pluggy-based plugin system** for custom validators
3939
- **Rich CLI** with JSON/text output formats
40+
- **MCP integration** — Model Context Protocol server for LLM tool calling
4041

4142
## Supported Languages
4243

@@ -516,6 +517,116 @@ llm_provider = "ollama"
516517
llm_model = "qwen2.5-coder:7b"
517518
```
518519

520+
## MCP Integration
521+
522+
vallm provides **Model Context Protocol (MCP)** server integration, exposing validation tools as MCP endpoints for LLM tool calling.
523+
524+
### Starting the MCP Server
525+
526+
```bash
527+
# Start the MCP server from project root
528+
python3 mcp_server.py
529+
530+
# Or start the packaged module directly
531+
python3 -m mcp.server.self_server
532+
```
533+
534+
### Claude Desktop Configuration
535+
536+
Add to your `claude_desktop_config.json`:
537+
538+
```json
539+
{
540+
"mcpServers": {
541+
"vallm": {
542+
"command": "python3",
543+
"args": ["/path/to/vallm/mcp_server.py"],
544+
"env": {
545+
"PYTHONPATH": "/path/to/vallm/src"
546+
}
547+
}
548+
}
549+
}
550+
```
551+
552+
### Available MCP Tools
553+
554+
| Tool | Description | Parameters |
555+
|------|-------------|------------|
556+
| `validate_syntax` | Multi-language syntax checking | `code`, `language`, `filename` |
557+
| `validate_imports` | Import resolution validation | `code`, `language`, `filename` |
558+
| `validate_security` | Security issue detection | `code`, `language`, `filename` |
559+
| `validate_code` | Full pipeline validation | `code`, `language`, `filename`, `reference_code`, `enable_*` flags |
560+
561+
### Example Tool Calls
562+
563+
```json
564+
{
565+
"method": "tools/call",
566+
"params": {
567+
"name": "validate_security",
568+
"arguments": {
569+
"code": "eval('1+1')",
570+
"language": "python"
571+
}
572+
}
573+
}
574+
```
575+
576+
```json
577+
{
578+
"method": "tools/call",
579+
"params": {
580+
"name": "validate_code",
581+
"arguments": {
582+
"code": "def test(): pass",
583+
"language": "python",
584+
"enable_syntax": true,
585+
"enable_security": true,
586+
"enable_complexity": false
587+
}
588+
}
589+
}
590+
```
591+
592+
### Testing MCP Integration
593+
594+
```bash
595+
# Test all MCP tools
596+
python3 test_mcp.py
597+
598+
# Test individual tools
599+
PYTHONPATH=src python3 -c "from mcp.server._tools_vallm import validate_syntax; print(validate_syntax('print(\"hello\")', 'python')['verdict'])"
600+
601+
# Run the Docker e2e flow
602+
bash mcp/tests/run_e2e.sh
603+
```
604+
605+
### Response Format
606+
607+
All MCP tools return a consistent JSON response:
608+
609+
```json
610+
{
611+
"success": true,
612+
"validator": "security",
613+
"score": 0.3,
614+
"weight": 1.5,
615+
"confidence": 0.9,
616+
"verdict": "fail",
617+
"issues": [
618+
{
619+
"message": "Use of eval() detected",
620+
"severity": "warning",
621+
"line": 1,
622+
"column": 0,
623+
"rule": "security.eval"
624+
}
625+
],
626+
"details": {}
627+
}
628+
```
629+
519630
## Plugin System
520631

521632
Write custom validators using pluggy:

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.52
1+
0.1.53

0 commit comments

Comments
 (0)