Tool Execution Order Guide
Learn the correct order to call MortyCP tools for successful operations.
Important: Tools must be called in the correct order. This guide shows the proper sequence.
Basic Rules
1. Always LIST before GET
- Use
list_loansto get loan IDs before callingget_loan - Use
list_borrowersto get borrower IDs before callingget_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_idfrom response
Step 2: Create investor
- Tool:
create_investor - Parameters:
first_name,last_name,type(0=Individual) - Save:
investor_idfrom response
Step 3: Create investor account
- Tool:
create_investor_account - Parameters:
investor_id(from step 2),legal_name - Save:
account_idfrom response
Step 4: Create loan
- Tool:
create_loan - Parameters:
loan_title,purpose(0=Refinance, 1=Purchase),loan_amount - Save:
loan_idfrom 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_idNOTinvestor_id
Getting Information About Existing Resources
Step 1: List loans
- Tool:
list_loans - Get:
loan_idfrom results
Step 2: Get loan details
- Tool:
get_loan - Parameters:
loan_id(from step 1)
Step 3: List borrowers
- Tool:
list_borrowers - Get:
borrower_idfrom 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_idfrom 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_idfrom 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→ Requiresinvestor_id(fromcreate_investor)create_broker_staff→ Requiresbroker_id(fromcreate_broker)create_broker_staff_cheque→ Requiresbroker_staff_id(fromcreate_broker_staff)attach_borrower_to_loan→ Requiresloan_idANDborrower_id(both must exist)attach_investor_to_loan→ Requiresloan_idANDaccount_id(both must exist)
Important: Useaccount_idfromcreate_investor_account, NOTinvestor_idattach_broker_staff_to_loan→ Requiresloan_id,broker_staff_id, ANDcheque_id(all must exist)
Tools that require valid IDs (use list tools first):
get_loan→ Useloan_idfromlist_loansget_borrower→ Useborrower_idfromlist_borrowerslist_investors→ Useloan_idfromlist_loans(and loan must have investors attached)get_broker(withloan_id) → Useloan_idfromlist_loans(and loan must have broker staff attached)get_appraiser(withloan_id) → Useloan_idfromlist_loans(and loan must have appraiser attached)
Tools that can be called anytime (no prerequisites):
list_loanslist_borrowerslist_substatusescreate_loancreate_borrowercreate_investorcreate_brokercreate_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):
create_loan/create_borrower/create_investor/create_broker(no prerequisites)create_investor_account(needsinvestor_id)create_broker_staff(needsbroker_id)create_broker_staff_cheque(needsbroker_staff_id)attach_borrower_to_loan(needsloan_id+borrower_id)attach_investor_to_loan(needsloan_id+account_id)attach_broker_staff_to_loan(needsloan_id+broker_staff_id+cheque_id)
Getting information (call in this order):
list_loans/list_borrowers(to get IDs)get_loan/get_borrower(with IDs from step 1)list_investors(withloan_id, requires investors are attached)
That's it! Follow these rules and your tools will work correctly.