Checking...
MortyCP - Morty Context Protocol
Tools Home

Tool Execution Order Guide

Learn the correct order to call MortyCP tools for successful operations.

Execution Guide

Important: Tools must be called in the correct order. This guide shows the proper sequence.

Basic Rules

1. Always LIST before GET

  • Use list_loans to get loan IDs before calling get_loan
  • Use list_borrowers to get borrower IDs before calling get_borrower
  • Never use hardcoded IDs like "1" or "999" - they probably don't exist

2. Create parents before children

  • Create broker before creating broker staff
  • Create investor before creating investor account
  • Create loan before attaching anything to it

3. Create things before attaching them

  • Create borrower AND loan before attaching borrower to loan
  • Create investor, account, AND loan before attaching investor to loan

Common Workflows

Creating a Loan with Borrower and Investor

Step 1: Create borrower

  • Tool: create_borrower
  • Parameters: first_name, last_name, email (optional)
  • Save: borrower_id from response

Step 2: Create investor

  • Tool: create_investor
  • Parameters: first_name, last_name, type (0=Individual)
  • Save: investor_id from response

Step 3: Create investor account

  • Tool: create_investor_account
  • Parameters: investor_id (from step 2), legal_name
  • Save: account_id from response

Step 4: Create loan

  • Tool: create_loan
  • Parameters: loan_title, purpose (0=Refinance, 1=Purchase), loan_amount
  • Save: loan_id from response

Step 5: Attach borrower to loan

  • Tool: attach_borrower_to_loan
  • Parameters: loan_id (from step 4), borrower_id (from step 1), is_main_client=1

Step 6: Attach investor to loan

  • Tool: attach_investor_to_loan
  • Parameters: loan_id (from step 4), account_id (from step 3), amount (optional)
  • Note: Use account_id NOT investor_id

Getting Information About Existing Resources

Step 1: List loans

  • Tool: list_loans
  • Get: loan_id from results

Step 2: Get loan details

  • Tool: get_loan
  • Parameters: loan_id (from step 1)

Step 3: List borrowers

  • Tool: list_borrowers
  • Get: borrower_id from results

Step 4: Get borrower details

  • Tool: get_borrower
  • Parameters: borrower_id (from step 3)

Step 5: List investors for a loan

  • Tool: list_investors
  • Parameters: loan_id (from step 1)
  • Note: This only works if the loan has investors attached

Creating Broker Staff

Step 1: Create broker

  • Tool: create_broker
  • Parameters: name, phone, email (optional)
  • Save: broker_id from response

Step 2: Create broker staff

  • Tool: create_broker_staff
  • Parameters: broker_id (from step 1), first_name, last_name, type (0=Partner, 1=Broker, 2=Assistant)
  • Save: broker_staff_id from response

Step 3: Create broker staff cheque

  • Tool: create_broker_staff_cheque
  • Parameters: broker_staff_id (from step 2), cheque_name
  • Save: cheque_id (broker_staff_cheque_id) from response

Step 4: Attach broker staff to loan (if loan exists)

  • Tool: attach_broker_staff_to_loan
  • Parameters: loan_id, broker_staff_id (from step 2), cheque_id (from step 3)

Tool Dependencies

Tools that require parent resources to exist first:

  • create_investor_account → Requires investor_id (from create_investor)
  • create_broker_staff → Requires broker_id (from create_broker)
  • create_broker_staff_cheque → Requires broker_staff_id (from create_broker_staff)
  • attach_borrower_to_loan → Requires loan_id AND borrower_id (both must exist)
  • attach_investor_to_loan → Requires loan_id AND account_id (both must exist)
    Important: Use account_id from create_investor_account, NOT investor_id
  • attach_broker_staff_to_loan → Requires loan_id, broker_staff_id, AND cheque_id (all must exist)

Tools that require valid IDs (use list tools first):

  • get_loan → Use loan_id from list_loans
  • get_borrower → Use borrower_id from list_borrowers
  • list_investors → Use loan_id from list_loans (and loan must have investors attached)
  • get_broker (with loan_id) → Use loan_id from list_loans (and loan must have broker staff attached)
  • get_appraiser (with loan_id) → Use loan_id from list_loans (and loan must have appraiser attached)

Tools that can be called anytime (no prerequisites):

  • list_loans
  • list_borrowers
  • list_substatuses
  • create_loan
  • create_borrower
  • create_investor
  • create_broker
  • create_parent_broker

Common Mistakes to Avoid

❌ DON'T: Call get_loan with loan_id=1 without checking if it exists

✅ DO: Call list_loans first, then use a real loan_id

❌ DON'T: Call list_investors before attaching investors

✅ DO: Create investor, create account, attach to loan, then list

❌ DON'T: Call create_broker_staff without creating broker first

✅ DO: Create broker, get broker_id, then create broker staff

❌ DON'T: Use investor_id with attach_investor_to_loan

✅ DO: Use account_id from create_investor_account

❌ DON'T: Use hardcoded IDs like "1" or "999"

✅ DO: Always get real IDs from list operations or create operations


When You Get Errors

API Error 1: Resource doesn't exist

  • Check: Did you create it first?
  • Check: Did you use a real ID (not a guessed one)?
  • Solution: Use list tools to get valid IDs, or create the resource first

"Fully funded" error: Loan is fully funded

  • This is expected - fully funded loans can't accept more investors
  • Solution: Remove an existing investor or reduce funding amounts first

"Account is empty" error: Loan has no accounts

  • Solution: Attach investors to the loan first using attach_investor_to_loan

"Unwanted field" error: Field not supported

  • Solution: Check tool documentation - some fields only work with get/list, not create

Quick Reference

Creating resources (call in this order):

  1. create_loan / create_borrower / create_investor / create_broker (no prerequisites)
  2. create_investor_account (needs investor_id)
  3. create_broker_staff (needs broker_id)
  4. create_broker_staff_cheque (needs broker_staff_id)
  5. attach_borrower_to_loan (needs loan_id + borrower_id)
  6. attach_investor_to_loan (needs loan_id + account_id)
  7. attach_broker_staff_to_loan (needs loan_id + broker_staff_id + cheque_id)

Getting information (call in this order):

  1. list_loans / list_borrowers (to get IDs)
  2. get_loan / get_borrower (with IDs from step 1)
  3. list_investors (with loan_id, requires investors are attached)

That's it! Follow these rules and your tools will work correctly.


← Back to Tools Documentation