Skip to content

[AI-203] Standardize MCP tool input validation#301

Open
Kartikey-Malkani wants to merge 1 commit intoopenMF:mainfrom
Kartikey-Malkani:feature/mcp-tool-validation
Open

[AI-203] Standardize MCP tool input validation#301
Kartikey-Malkani wants to merge 1 commit intoopenMF:mainfrom
Kartikey-Malkani:feature/mcp-tool-validation

Conversation

@Kartikey-Malkani
Copy link
Copy Markdown

@Kartikey-Malkani Kartikey-Malkani commented Mar 29, 2026

Jira: https://mifosforge.jira.com/browse/AI-203

Summary

  • Add reusable python/tools/validation.py for shared MCP input validation
  • Wrap all @mcp.tool() registrations in mcp_server.py with centralized pre-validation
  • Short-circuit invalid requests before tool business logic / Fineract API calls
  • Add focused tests in python/tests/test_validation.py

Validation Framework

  • Validates common ID fields (*Id, *_id, id) as positive integers
  • Validates common numeric fields (amount, principal, rate, period counters) as positive numbers
  • Validates date-like fields as non-empty strings
  • Returns early with consistent error structure on any validation failure

Error Response Format

{
  "error": "Invalid loan_id. It must be a positive integer.",
  "httpStatusCode": 400,
  "validation": {
    "field": "loan_id",
    "value": "invalid_value",
    "expected": "positive integer"
  }
}

Backward Compatibility

  • Preserves all function signatures (no breaking changes)
  • Uses conservative common validation rules only
  • Existing callers continue to work unchanged

Verification

  • Error checks: clean for all edited files
  • Tests pass: 14 passed
  • Command: python -m pytest tests/test_validation.py tests/test_loans.py -q

Closes AI-203

Copy link
Copy Markdown
Contributor

@IOhacker IOhacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this ticket in the PR title: https://mifosforge.jira.com/browse/AI-203

@Kartikey-Malkani Kartikey-Malkani changed the title feat: standardize MCP tool input validation [AI-203] Standardize MCP tool input validation Mar 30, 2026
@Kartikey-Malkani
Copy link
Copy Markdown
Author

Thanks for the feedback! I’ve updated the PR to include the Jira ticket in the title and description.

Please let me know if anything else needs improvement or if it’s good to proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants