Corrosion Engineering MCP Server
Provides AI agents with physics-based corrosion engineering calculations, from rapid handbook lookups to mechanistic electrochemical models with dual-tier pitting assessment for material compatibility screening and corrosion rate prediction.
README
Corrosion Engineering MCP Server
Physics-Based Corrosion Rate Prediction via Model Context Protocol
Overview
Corrosion Engineering MCP Server is a FastMCP-based toolkit that provides AI agents with access to physics-based corrosion engineering calculations, ranging from rapid handbook lookups to mechanistic electrochemical models with dual-tier pitting assessment.
Current Status: Version 0.3.0 (2025-12-15)
- ✅ 348 tests passing (100% coverage)
- ✅ 14 MCP tools with
corrosion_prefix - ✅ Production Ready: All critical bugs fixed
See IMPLEMENTATION_ROADMAP.md for implementation history.
Quick Start
Installation
# Clone repository
git clone git@github.com:puran-water/corrosion-engineering-mcp.git
cd corrosion-engineering-mcp
# Activate virtual environment
source ../venv312/bin/activate # Linux/Mac
# OR
..\venv312\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Run tests
pytest tests/test_phase3_pitting_integration.py -v
MCP Configuration
Add to Claude Desktop config (.mcp.json):
{
"mcpServers": {
"corrosion-engineering": {
"command": "python",
"args": ["/path/to/corrosion-engineering-mcp/server.py"]
}
}
}
Full configuration guide: MCP_CONFIGURATION.md
Phase 3 Highlights: Dual-Tier Pitting Assessment
What's New
Tier 1 + Tier 2 Pitting Assessment: Combines fast empirical screening (PREN/CPT) with mechanistic electrochemical assessment (E_pit vs E_mix).
Example (SS316 in seawater):
result = calculate_localized_corrosion(
material="SS316", # or 316L, 316, UNS S31600 (aliases supported)
temperature_C=25.0,
Cl_mg_L=19000.0,
pH=8.0,
dissolved_oxygen_mg_L=8.0, # ← Enables Tier 2
)
# Tier 1 (PREN/CPT - always available)
print(result["pitting"]["susceptibility"]) # "critical" (T > CPT)
print(result["pitting"]["CPT_C"]) # 10.0°C
print(result["pitting"]["PREN"]) # 24.7
# Tier 2 (E_pit vs E_mix - requires DO)
print(result["pitting"]["electrochemical_risk"]) # "low" (E_mix << E_pit)
print(result["pitting"]["E_pit_VSCE"]) # 1.084 V_SCE
print(result["pitting"]["E_mix_VSCE"]) # 0.501 V_SCE
# Tier disagreement detection
print(result["tier_disagreement"]["detected"]) # True
print(result["tier_disagreement"]["explanation"]) # "Trust Tier 2 for accurate assessment..."
Key Insight: CPT test (ferric chloride, saturated) is conservative. Tier 2 provides mechanistic driving force (ΔE = E_mix - E_pit) accounting for actual dissolved oxygen.
Codex UX Improvements ✅
- Self-describing Tier 2 unavailability:
electrochemical_interpretationexplains WHY (not justnull) - RedoxState warnings surfaced: DO saturation, anaerobic conditions appended to interpretation
- Material alias mapping: 316L, 316, UNS S31600 → SS316 (6 aliases supported)
- Tier disagreement detection: Automatic warning when Tier 1 ≠ Tier 2 with guidance
Full user guide: docs/TIER1_VS_TIER2_PITTING_GUIDE.md
Architecture: 4-Tier Framework
Tier 0: Handbook Lookup (~0.5 sec)
Purpose: Rapid screening via semantic search on 2,980 vector chunks
Tools (3):
corrosion_screen_materials- Material-environment compatibilitycorrosion_query_typical_rates- Empirical corrosion ratescorrosion_identify_mechanism- Mechanism identification + mitigation
Tier 1: Chemistry (~1 sec)
Purpose: Aqueous speciation and scaling indices
Tools (2):
corrosion_langelier_index- Water scaling tendency (Langelier SI)corrosion_predict_scaling- Mineral scale prediction
Tier 2: Mechanistic Physics (1-5 sec)
Purpose: First-principles electrochemical models
Tools (7):
corrosion_predict_co2_h2s- NORSOK M-506 sweet/sour servicecorrosion_predict_aerated_chloride- O₂ mass transfer limitedcorrosion_assess_galvanic- NRL mixed-potential Butler-Volmer solvercorrosion_generate_pourbaix- E-pH stability diagramscorrosion_get_material_properties- Alloy database (18+ materials)corrosion_estimate_service_life- Remaining life prediction
Tier 3: Localized Corrosion
Purpose: Pitting/crevice assessment
Tools (2):
corrosion_assess_localized- Dual-tier pitting + crevice- Tier 1: PREN/CPT empirical (ASTM G48, ISO 18070)
- Tier 2: E_pit vs E_mix mechanistic (NRL Butler-Volmer)
corrosion_calculate_pren- PREN calculation
Tool Count: 14 Tools
| Tier | Tools | Count |
|---|---|---|
| Tier 0: Handbook | screen_materials, query_typical_rates, identify_mechanism | 3 |
| Tier 1: Chemistry | langelier_index, predict_scaling | 2 |
| Tier 2: Mechanistic | predict_co2_h2s, predict_aerated_chloride, assess_galvanic, generate_pourbaix, get_material_properties, estimate_service_life | 6 |
| Tier 3: Localized | assess_localized, calculate_pren | 2 |
| Info | get_server_info | 1 |
| Total | 14 |
All tools have the corrosion_ prefix (e.g., corrosion_screen_materials).
Recent Updates
Version 0.3.0 (2025-12-15)
- 14 MCP tools registered with
corrosion_prefix - CSV-backed material properties for 18+ alloys
- All critical bug fixes from code review complete
- 348 tests passing
Key Fixes (0.3.0)
- Galvanic K constant corrected (A/cm² → mm/year)
- ipy unit conversion fixed (in/y → mm/y)
- DO scaling for user-supplied values
- Zero-CO₂ short-circuit in NORSOK model
- NORSOK pH clamping (prevents errors for pH > 6.5)
JSON Response Schema
All tools return standardized JSON with:
- Central estimates (median or nominal values)
- Uncertainty bounds (p05, p95 percentiles)
- Provenance metadata (model, validation, sources, confidence)
Example (calculate_localized_corrosion):
{
"pitting": {
"CPT_C": 10.0,
"PREN": 24.7,
"Cl_threshold_mg_L": 233,
"susceptibility": "critical",
"margin_C": -15.0,
"interpretation": "CRITICAL: T = 25.0°C exceeds CPT...",
"E_pit_VSCE": 1.084,
"E_mix_VSCE": 0.501,
"electrochemical_margin_V": -0.583,
"electrochemical_risk": "low",
"electrochemical_interpretation": "LOW RISK: E_mix (0.501 V) is 583 mV below E_pit..."
},
"tier_disagreement": {
"detected": true,
"tier1_assessment": "critical",
"tier2_assessment": "low",
"explanation": "⚠️ TIER DISAGREEMENT: Tier 1 (PREN/CPT empirical) says 'critical' but Tier 2 (E_pit vs E_mix mechanistic) says 'low'. Recommendation: Trust Tier 2..."
},
"overall_risk": "critical",
"recommendations": [
"⚠️ TIER DISAGREEMENT: Trust Tier 2 for accurate assessment...",
"CRITICAL: Immediate risk of localized corrosion..."
]
}
Validated Materials (Phase 3)
| Material | Tier 1 (PREN/CPT) | Tier 2 (E_pit/E_mix) | Status |
|---|---|---|---|
| SS316 | ✅ | ✅ | ✅ Production-ready (seawater validated) |
| 316L | ✅ | ✅ | ✅ Alias → SS316 |
| 316 | ✅ | ✅ | ✅ Alias → SS316 |
| UNS S31600/S31603 | ✅ | ✅ | ✅ Alias → SS316 |
| HY80 | ✅ | ⚠️ | ⚠️ Tier 1 only (negative ORR activation energy at seawater) |
| HY100 | ✅ | ⏳ | ⏳ Tier 2 untested (coefficients available) |
| 2205 | ✅ | ❌ | ✅ Tier 1 only (not in NRL DB, PREN=35) |
| 254SMO | ✅ | ❌ | ✅ Tier 1 only (not in NRL DB, PREN=43) |
Directory Structure
corrosion-engineering-mcp/
├── server.py # FastMCP server
├── requirements.txt # Dependencies
├── .mcp.json # FastMCP configuration
├── README.md # This file
│
├── core/ # Core architecture
│ ├── interfaces.py # Abstract base classes
│ ├── schemas.py # Pydantic models (CorrosionResult, etc.)
│ ├── state_container.py # CorrosionContext caching
│ ├── phreeqc_adapter.py # PHREEQC backend
│ └── localized_backend.py # Tier 1+2 pitting backend (Phase 3)
│
├── tools/ # MCP tool implementations
│ ├── handbook/ # Tier 0: Semantic search
│ │ ├── material_screening.py # ✅ screen_materials
│ │ ├── typical_rates.py # ✅ query_typical_rates
│ │ └── mechanism_guidance.py # ✅ identify_mechanism
│ ├── chemistry/ # Tier 1: PHREEQC
│ │ ├── speciation.py # ✅ run_phreeqc_speciation
│ │ └── calculate_pourbaix.py # 🔄 calculate_pourbaix (stub)
│ └── mechanistic/ # Tier 2: Physics models
│ ├── co2_h2s.py # ✅ predict_co2_h2s_corrosion
│ ├── aerated_chloride.py # ✅ predict_aerated_chloride_corrosion
│ ├── predict_galvanic_corrosion.py # ✅ predict_galvanic_corrosion
│ └── localized_corrosion.py # ✅ calculate_localized_corrosion (Phase 3)
│
├── utils/ # Utility modules
│ ├── material_database.py # Authoritative materials data
│ ├── nrl_materials.py # NRL electrochemical database (Phase 3)
│ ├── nrl_constants.py # Physical constants (Phase 3)
│ ├── nrl_electrochemical_reactions.py # ORR, HER, Fe oxidation (Phase 3)
│ ├── pitting_assessment.py # E_pit calculator (Phase 3)
│ ├── redox_state.py # DO ↔ Eh conversion (Phase 3)
│ └── nacl_solution_chemistry.py # NaCl solution properties (Phase 3)
│
├── external/ # External data files
│ ├── nrl_coefficients/ # 23 CSV files (NRL Butler-Volmer)
│ └── nrl_matlab_reference/ # 12 MATLAB files (NRL validation)
│
├── tests/ # Test suite
│ ├── test_phase3_pitting_integration.py # ✅ 9/9 passing
│ ├── test_phase2_galvanic.py # Phase 2 tests
│ └── test_redox_state.py # RedoxState module tests
│
└── docs/ # Documentation
├── TIER1_VS_TIER2_PITTING_GUIDE.md # User guide (600+ lines)
├── POURBAIX_PHREEQC_ROADMAP.md # Pourbaix integration plan
└── ... # Additional documentation
Implementation Summary
Completed Features
- Tier 0: Handbook lookup (semantic search on 2,980 chunks)
- Tier 1: Chemistry (Langelier SI, scaling prediction)
- Tier 2: Mechanistic physics (CO₂/H₂S, aerated chloride, galvanic, Pourbaix)
- Tier 3: Localized corrosion (dual-tier pitting, PREN)
- Materials: NRL database (6 alloys) + CSV database (18+ alloys)
Future Roadmap
- Corrosion under insulation (CUI) prediction
- Monte Carlo uncertainty quantification
- Enhanced PHREEQC integration
Usage Examples
Example 1: Dual-Tier Pitting Assessment (Phase 3)
# SS316 in aerated seawater
result = calculate_localized_corrosion(
material="316L", # Alias → SS316
temperature_C=25.0,
Cl_mg_L=19000.0,
pH=8.0,
dissolved_oxygen_mg_L=8.0, # Enables Tier 2
)
# Tier 1: Conservative CPT screening
print(f"CPT: {result['pitting']['CPT_C']}°C") # 10.0
print(f"Tier 1 Risk: {result['pitting']['susceptibility']}") # "critical"
# Tier 2: Mechanistic electrochemical
print(f"E_pit: {result['pitting']['E_pit_VSCE']:.3f} V_SCE") # 1.084
print(f"E_mix: {result['pitting']['E_mix_VSCE']:.3f} V_SCE") # 0.501
print(f"ΔE: {result['pitting']['electrochemical_margin_V']*1000:.0f} mV") # -583
print(f"Tier 2 Risk: {result['pitting']['electrochemical_risk']}") # "low"
# Disagreement detection
if result['tier_disagreement']['detected']:
print(result['tier_disagreement']['explanation'])
# "Trust Tier 2 for accurate assessment - it accounts for actual
# electrochemical driving force and redox conditions..."
Example 2: Galvanic Corrosion (Phase 2)
# Steel bolts in stainless flange
result = predict_galvanic_corrosion(
anode_material="HY80",
cathode_material="SS316",
temperature_C=25.0,
pH=7.5,
chloride_mg_L=800.0,
area_ratio_cathode_to_anode=50.0, # Large flange, small bolts
)
print(f"Galvanic current density: {result['galvanic_current_density_A_cm2']:.2e} A/cm²")
print(f"Anode corrosion rate: {result['anode_corrosion_rate_mm_year']:.3f} mm/year")
if 'warnings' in result and result['warnings']:
print(f"Warnings: {result['warnings']}")
Example 3: Handbook Screening (Tier 0)
result = screen_materials(
environment="CO2-rich brine, 60°C, pCO2=0.5 bar, pH 6.8",
candidates=["CS", "316L", "duplex_2205"],
application="piping"
)
print(f"Material: {result.material}")
print(f"Compatibility: {result.compatibility}")
print(f"Typical rate range: {result.typical_rate_range} mm/y")
Design Decisions
Why Dual-Tier Pitting?
Decision: Combine empirical (PREN/CPT) with mechanistic (E_pit vs E_mix)
Rationale:
- Tier 1 (PREN/CPT): Fast, conservative screening (worst-case ferric chloride test)
- Tier 2 (E_pit vs E_mix): Mechanistic driving force accounting for redox state
- Graceful degradation: Tier 2 optional (requires DO + NRL material), falls back to Tier 1
- Codex validation: "Tier 1 is guaranteed, Tier 2 is opt-in... solid UX"
Why Material Aliases?
Decision: Map 316L, 316, UNS S31600 → SS316
Rationale (Codex recommendation):
- Prevents "Tier 2 unavailable" frustration
- Users don't need to memorize "SS316" vs "316L"
- 6-line alias dict prevents 90% of support issues
Why Tier Disagreement Detection?
Decision: Automatic warning when Tier 1 ≠ Tier 2
Rationale (Codex recommendation):
- "Expose the conflict explicitly" when tiers disagree
- Clear guidance: "Trust Tier 2 for accurate assessment"
- Example: SS316 seawater → Tier 1 "critical" vs Tier 2 "low" (Tier 2 correct)
Production Deployment
Pre-Deployment Checklist
- [x] All tests passing (9/9 Phase 3 integration tests)
- [x] Codex recommendations implemented (4/4)
- [x] Documentation complete (user guide, deployment checklist)
- [x] Known limitations documented (HY80 at seawater)
- [x] API backward compatible (100%)
Smoke Tests
See: PRODUCTION_DEPLOYMENT_CHECKLIST.md
Monitoring Metrics
- Tier 2 availability rate (target: >50%)
- Tier disagreement rate (expected: 20-40%)
- Error rate (target: <5%)
- Latency p95 (target: <2 seconds)
Dependencies
Current (requirements.txt):
# MCP Framework
fastmcp>=0.1.0
# Core
numpy>=1.24.0
pandas>=2.0.0
scipy>=1.10.0
pydantic>=2.0.0
# Chemistry
phreeqpython>=1.5.5
# Testing
pytest>=7.0.0
pytest-cov>=4.0.0
pytest-asyncio>=0.21.0
References
Authoritative Sources
- U.S. Naval Research Laboratory - Butler-Volmer electrochemical kinetics
- Repository: USNavalResearchLaboratory/corrosion-modeling-applications (MIT)
- ASTM G48 - Critical Pitting Temperature tabulated data
- ISO 18070 / NORSOK M-506 - Chloride thresholds
- Garcia & Gordon (1992) - DO saturation model
Documentation
- User Guide: docs/TIER1_VS_TIER2_PITTING_GUIDE.md
- Deployment: PRODUCTION_DEPLOYMENT_CHECKLIST.md
- MCP Config: MCP_CONFIGURATION.md
License
MIT License - See LICENSE file for details
Citation
@software{corrosion_mcp_2025,
title={Corrosion Engineering MCP Server},
author={Puran Water LLC},
year={2025},
url={https://github.com/puran-water/corrosion-engineering-mcp},
version={0.3.0}
}
Version: 0.3.0 | Tests: 348 passing | Tools: 14
Last Updated: 2025-12-15
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。