tevinric/mcp-server-db2rpg
If you are the rightful owner of mcp-server-db2rpg and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A specialized Model Control Protocol (MCP) server for IBM DB2 and RPG code generation, review, and documentation.
upload_document
Process uploaded PDF or Markdown documents containing coding standards.
search_references
Search through uploaded documents for specific topics or patterns.
extract_code_examples
Extract code examples and patterns from reference documents.
generate_code
Generate new code based on requirements and reference standards.
review_code
Review existing code against uploaded standards and best practices.
explain_code
Explain code functionality using reference documentation.
create_artifact
Create large code artifacts with proper structure.
list_documents
List all uploaded reference documents with metadata.
Enhanced DB2/RPG Code Generation MCP Server
A specialized Model Control Protocol (MCP) server for IBM DB2 and RPG code generation, review, documentation, and traditional-to-freeform RPG conversion. This server allows LLMs to generate, review, explain, and convert code based on uploaded coding standards and reference documents.
π New Features in v1.1
RPG Traditional-to-Freeform Conversion
- Automatic Analysis: Analyze traditional RPG code structure and complexity
- Intelligent Conversion: Convert fixed-format RPG to modern free-form syntax
- Standards Compliance: Apply uploaded coding standards during conversion
- Validation Tools: Validate converted code against original functionality
- Modernization Suggestions: Get recommendations for improving legacy code
Enhanced Document Processing
- Section Extraction: Retrieve specific sections from coding standards documents
- Pattern Recognition: Extract RPG-specific coding patterns and conventions
- Conversion Guides: Support for specialized RPG conversion documentation
- Enhanced Code Detection: Improved recognition of both traditional and free-form RPG
Features
- Document Upload: Support for PDF and Markdown files containing coding standards
- Code Generation: Generate DB2/SQL and RPG code based on requirements
- Code Review: Review existing code against uploaded standards
- Code Explanation: Explain code functionality with reference to documentation
- π RPG Conversion: Convert traditional RPG to free-form format
- π Code Analysis: Analyze RPG code structure and complexity
- β Conversion Validation: Validate conversions against standards
- π‘ Modernization: Suggest improvements for legacy RPG code
- Image Processing: Extract and analyze images from PDF documents using PyMuPDF
- Artifact Creation: Generate large code artifacts with proper structure
- Context Management: Stay within 128K token limits with intelligent truncation
- Azure OpenAI Integration: Full integration with GPT-4o for code assistance
Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Client Application β
β βββββββββββββββββββ βββββββββββββββββββ β
β β Azure OpenAI β β Enhanced Python β β
β β GPT-4o βββββΊβ RPG Client β β
β βββββββββββββββββββ βββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β HTTP/MCP Protocol
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Enhanced MCP Server (FastAPI) β
β βββββββββββββββββββ βββββββββββββββββββ β
β β RPG Conversion β β Document β β
β β Engine β β Processing β β
β β β’ Analyze RPG β β β’ PDF extractionβ β
β β β’ Convert Code β β β’ Section extractβ β
β β β’ Validate β β β’ Pattern recog β β
β β β’ Modernize β β β’ Standards β β
β βββββββββββββββββββ βββββββββββββββββββ β
β βββββββββββββββββββ βββββββββββββββββββ β
β β Code Generation β β Enhanced β β
β β Tools β β Analysis β β
β β β’ generate_code β β β’ Style compare β β
β β β’ review_code β β β’ Pattern extractβ β
β β β’ explain_code β β β’ Code quality β β
β β β’ create_artifactβ β β’ Standards ref β β
β βββββββββββββββββββ βββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Enhanced Storage β
β βββββββββββββββββββ βββββββββββββββββββ β
β β Documents β β Conversion β β
β β β’ Standards β β Artifacts β β
β β β’ Conversion β β β’ Original RPG β β
β β Guides β β β’ Free-form β β
β β β’ Best Practicesβ β β’ Validation β β
β β β’ References β β β’ Reports β β
β βββββββββββββββββββ βββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Quick Start
1. Environment Setup
# Set up environment variables
source env_var_init_server.sh # For server
source env_var_init_client.sh # For client
# Install dependencies
pip install -r requirements.txt
2. Start the Enhanced MCP Server
# Run locally
python mcp-server.py
# Or using Docker
docker-compose up -d
3. Upload Reference Documents
# Upload coding standards and conversion guides
curl -X POST -F "file=@rpg_coding_standards.pdf" http://localhost:8000/upload
curl -X POST -F "file=@rpg_conversion_guide.md" http://localhost:8000/upload
curl -X POST -F "file=@freeform_best_practices.pdf" http://localhost:8000/upload
4. Run the Enhanced Client
# Interactive RPG conversion mode
python client.py interactive
# Example mode
python client.py
Available Tools
π Enhanced RPG Conversion Tools
1. analyze_rpg_syntax
Analyze traditional RPG code structure and identify conversion requirements.
Parameters:
code
: Traditional RPG code to analyzeinclude_conversion_plan
: Include conversion strategy (default: true)
Example:
await mcp_client.call_tool("analyze_rpg_syntax", {
"code": traditional_rpg_code,
"include_conversion_plan": True
})
2. convert_rpg_to_freeform
Convert traditional RPG code to free-form format using uploaded coding standards.
Parameters:
code
: Traditional RPG code to convertapply_standards
: Apply uploaded coding standards (default: true)include_comments
: Include conversion comments (default: true)validation_level
: Level of validation (basic/detailed/comprehensive)
3. validate_conversion
Validate converted RPG code against uploaded standards and best practices.
Parameters:
original_code
: Original traditional RPG codeconverted_code
: Converted free-form RPG codestandards_reference
: Specific standards document to reference
4. suggest_modernization
Suggest modernization techniques for RPG code based on current best practices.
Parameters:
code
: RPG code to analyze for modernizationfocus_areas
: Specific areas to focus on (error_handling, data_structures, procedures, sql_integration, performance, maintainability)
5. compare_code_styles
Compare traditional and free-form RPG coding styles with examples from standards.
Parameters:
operation_type
: Type of operation to compare (file_operations, calculations, conditions, loops, procedures, error_handling)show_examples
: Include code examples (default: true)
6. extract_rpg_patterns
Extract specific RPG coding patterns and standards from reference documents.
Parameters:
pattern_type
: Type of RPG pattern to extract (naming_conventions, error_handling, file_operations, data_structures, procedures, conversion_rules)format
: RPG format to focus on (traditional/freeform/both)
7. get_document_sections
Retrieve specific sections from uploaded documents by title or content type.
Parameters:
section_title
: Title or header of the section to retrievedocument_name
: Specific document name (optional)content_type
: Type of content to look for (coding_standards, conversion_rules, examples, best_practices, procedures)
Enhanced Existing Tools
8. upload_document
(Enhanced)
Process uploaded PDF or Markdown documents with improved RPG detection.
New document types:
conversion_guide
: RPG conversion guides and migration documents- Enhanced section extraction for coding standards
- Improved RPG code pattern recognition
9. extract_code_examples
(Enhanced)
Extract code examples with enhanced RPG format detection.
New code types:
rpg_traditional
: Traditional fixed-format RPGrpg_freeform
: Modern free-form RPG
10. generate_code
(Enhanced)
Generate new code with improved RPG free-form generation.
Enhanced code types:
rpg_freeform
: Generate modern free-form RPG code
Standard Tools (Unchanged)
search_references
- Search through uploaded documentsreview_code
- Review code against standardsexplain_code
- Explain code functionalitycreate_artifact
- Create large code artifactslist_documents
- List uploaded documents
Enhanced Usage Examples
RPG Conversion Workflow
# 1. Upload conversion standards
await mcp_client.upload_document("rpg_conversion_standards.pdf")
await mcp_client.call_tool("upload_document", {
"filename": "rpg_conversion_standards.pdf",
"document_type": "conversion_guide",
"description": "Official RPG conversion standards"
})
# 2. Analyze traditional RPG code
traditional_code = """
H DFTACTGRP(*NO) ACTGRP(*CALLER)
F CUSTFILE IF E K DISK
D customerID S 7P 0
C CHAIN 12345 CUSTFILE
"""
analysis = await mcp_client.call_tool("analyze_rpg_syntax", {
"code": traditional_code,
"include_conversion_plan": True
})
# 3. Convert to free-form
conversion = await mcp_client.call_tool("convert_rpg_to_freeform", {
"code": traditional_code,
"apply_standards": True,
"validation_level": "detailed"
})
# 4. Validate conversion
validation = await mcp_client.call_tool("validate_conversion", {
"original_code": traditional_code,
"converted_code": converted_code
})
# 5. Get modernization suggestions
suggestions = await mcp_client.call_tool("suggest_modernization", {
"code": converted_code,
"focus_areas": ["error_handling", "procedures", "sql_integration"]
})
Document Analysis
# Extract conversion patterns from standards
patterns = await mcp_client.call_tool("extract_rpg_patterns", {
"pattern_type": "conversion_rules",
"format": "both"
})
# Get specific document sections
standards = await mcp_client.call_tool("get_document_sections", {
"section_title": "Free-form Conversion Rules",
"content_type": "conversion_rules"
})
# Compare coding styles
comparison = await mcp_client.call_tool("compare_code_styles", {
"operation_type": "file_operations",
"show_examples": True
})
Enhanced Interactive Commands
When running python client.py interactive
:
New RPG Conversion Commands
analyze <code>
- Analyze traditional RPG code structureconvert <code>
- Convert traditional RPG to free-formvalidate
- Validate a conversion (prompts for both codes)modernize <code>
- Get modernization suggestionscompare <operation>
- Compare traditional vs free-form stylespatterns <type>
- Extract RPG patterns from documentssections <title>
- Get specific document sectionsstandards
- View conversion standards from documents
Enhanced Existing Commands
upload <file_path>
- Upload with conversion guide supportgenerate <type> <requirements>
- Enhanced RPG generationreview <type> <code>
- Enhanced RPG code reviewexplain <code>
- Enhanced RPG code explanationdocs
- List documents with processing statusartifacts
- List artifacts including conversions
Document Types
Supported Formats
- PDF: Enhanced extraction with section recognition
- Markdown: Improved header and section processing
Enhanced Document Categories
- standards: Coding standards and conventions
- procedures: Development procedures and workflows
- best_practices: Best practice guidelines
- reference: Technical reference materials
- examples: Code examples and templates
- π conversion_guide: RPG conversion guides and migration documentation
RPG Conversion Features
Automatic Analysis
- Format Detection: Identifies traditional vs free-form RPG
- Complexity Assessment: Evaluates conversion difficulty
- Component Inventory: Catalogs H-specs, F-specs, D-specs, etc.
- Dependency Analysis: Identifies files, subroutines, and indicators
Intelligent Conversion
- Standards Application: Uses uploaded coding standards
- Structure Modernization: Converts subroutines to procedures
- Syntax Translation: Fixed-format to free-form conversion
- Error Handling Enhancement: Adds modern error handling patterns
Validation & Quality
- Functional Validation: Ensures converted code maintains functionality
- Standards Compliance: Validates against uploaded coding standards
- Best Practice Checks: Applies modern RPG best practices
- Quality Assessment: Provides code quality metrics
Modernization Suggestions
- Error Handling: MONITOR/ON-ERROR patterns
- Data Structures: Qualified data structures
- Procedures: Modern procedure implementations
- SQL Integration: Embedded SQL recommendations
- Performance: Optimization suggestions
Context Window Management
Enhanced system automatically manages the 128K token context window:
- Smart Content Truncation: Intelligently truncates long documents while preserving key sections
- Conversion History: Maintains conversion context for validation
- Standards Prioritization: Keeps coding standards in context during conversions
- Artifact Generation: Large conversions are automatically saved as artifacts
Environment Variables
Server Variables (Enhanced)
export MCP_SERVER_HOST="0.0.0.0"
export MCP_SERVER_PORT="8000"
export STORAGE_PATH="./storage"
export RPG_CONVERSION_ENABLED="true" # New
export ENHANCED_ANALYSIS="true" # New
Client Variables (Enhanced)
export AZURE_OPENAI_API_KEY="your-api-key"
export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/"
export AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o"
export AZURE_OPENAI_API_VERSION="2024-02-01"
export MCP_SERVER_URL="http://localhost:8000"
export RPG_CONVERSION_MODE="enhanced" # New
API Endpoints
Enhanced MCP Protocol
POST /mcp
- Main MCP protocol endpoint with RPG tools
File Management (Enhanced)
POST /upload
- Upload documents including conversion guidesGET /documents
- List documents with processing statusGET /artifacts
- List artifacts including conversion results
Health Check (Enhanced)
GET /health
- Server health with RPG conversion statusGET /
- Server information with new features
Docker Deployment
# Build and run enhanced server
docker-compose up -d
# View logs
docker-compose logs -f mcp-server
# Stop
docker-compose down
Development
Adding New RPG Tools
- Add tool definition in
list_tools()
function - Add implementation in
call_tool()
function - Update RPGConverter class for new conversion logic
- Test with various RPG code samples
Extending Conversion Engine
- Enhance pattern recognition in
CodeAnalyzer
- Add new conversion rules in
RPGConverter
- Update validation logic
- Add new modernization patterns
RPG Conversion Examples
Traditional RPG Input
H DFTACTGRP(*NO) ACTGRP(*CALLER)
F CUSTFILE IF E K DISK
F ORDERFILE UF E K DISK
D customerID S 7P 0
D customerName S 50A
D orderTotal S 15P 2
C CHAIN 12345 CUSTFILE
C IF %FOUND(CUSTFILE)
C EVAL customerName = CFNAME
C calcTotal BEGSR
C EVAL orderTotal = OAMT1 + OAMT2
C ENDSR
Free-form Output
**CTL-OPT DFTACTGRP(*NO) ACTGRP(*CALLER);
DCL-F CUSTFILE DISK(*EXT) USAGE(*INPUT) KEYED;
DCL-F ORDERFILE DISK(*EXT) USAGE(*UPDATE) KEYED;
DCL-S customerID PACKED(7:0);
DCL-S customerName CHAR(50);
DCL-S orderTotal PACKED(15:2);
// Main processing logic
CHAIN 12345 CUSTFILE;
IF %FOUND(CUSTFILE);
customerName = CFNAME;
calcTotal();
ENDIF;
DCL-PROC calcTotal;
orderTotal = OAMT1 + OAMT2;
END-PROC;
Troubleshooting
Enhanced Issues
- RPG Conversion failures: Check uploaded conversion standards
- Pattern recognition errors: Verify document format and content
- Validation failures: Ensure original and converted code are provided
- Standards not applied: Verify document type is set correctly
Performance Optimization
- Conversion results are cached for repeat operations
- Large conversions are automatically saved as artifacts
- Pattern extraction is optimized for speed
- Document sections are indexed for quick retrieval
Security Considerations
- Uploaded RPG code is processed securely
- Conversion artifacts are properly isolated
- Standards documents are validated before processing
- Access controls for sensitive conversion guides
Contributing
- Fork the repository
- Create feature branch for RPG enhancements
- Add comprehensive tests for conversion logic
- Update documentation for new tools
- Submit pull request
License
This enhanced project is provided as-is for educational and development purposes, with special focus on RPG modernization initiatives.
Changelog
v1.1.0 - Enhanced RPG Conversion
- β¨ Added traditional-to-freeform RPG conversion
- π Enhanced code analysis and pattern recognition
- π Added conversion validation tools
- π‘ Implemented modernization suggestions
- π Enhanced document processing with section extraction
- π― Added specialized RPG pattern extraction
- β‘ Improved performance for large code conversions
- π οΈ Enhanced interactive client for RPG workflows