ynab_mcp/
docs.rs

1use serde_json::{json, Value};
2
3/// Comprehensive API documentation for the YNAB MCP server
4///
5/// This module provides detailed documentation for all tools, resources,
6/// and MCP protocol capabilities to help AI assistants and developers
7/// understand and effectively use the server.
8pub struct ApiDocumentation;
9
10impl ApiDocumentation {
11    /// Get comprehensive documentation for all tools
12    pub fn get_tools_documentation() -> Value {
13        json!({
14            "version": "1.0.0",
15            "last_updated": "2024-01-15",
16            "description": "YNAB MCP Server Tool Documentation - Complete reference for all available tools",
17            "categories": {
18                "transaction_management": {
19                    "description": "Create, update, and manage YNAB transactions",
20                    "tools": [
21                        {
22                            "name": "create_transaction",
23                            "description": "Create a new transaction in your YNAB budget",
24                            "required_parameters": ["budget_id", "account_id", "amount", "date"],
25                            "optional_parameters": ["payee_id", "category_id", "memo", "cleared", "flag_color", "flag_name"],
26                            "examples": [
27                                {
28                                    "description": "Create a simple expense transaction",
29                                    "parameters": {
30                                        "budget_id": "default",
31                                        "account_id": "12345678-1234-1234-1234-123456789abc",
32                                        "amount": -2500,
33                                        "date": "2024-01-15",
34                                        "memo": "Coffee shop"
35                                    },
36                                    "expected_result": "Transaction created successfully with milliunits precision"
37                                },
38                                {
39                                    "description": "Create income transaction with category",
40                                    "parameters": {
41                                        "budget_id": "default",
42                                        "account_id": "12345678-1234-1234-1234-123456789abc",
43                                        "amount": 500000,
44                                        "date": "2024-01-15",
45                                        "category_id": "87654321-4321-4321-4321-210987654321",
46                                        "memo": "Freelance work"
47                                    }
48                                }
49                            ],
50                            "common_errors": {
51                                "invalid_amount": "Amount must be an integer in milliunits (1000 milliunits = $1.00)",
52                                "invalid_account_id": "Account ID must be a valid UUID from your YNAB budget",
53                                "invalid_date": "Date must be in YYYY-MM-DD format",
54                                "permission_denied": "Check read-only mode setting and API token permissions"
55                            },
56                            "tips": [
57                                "Use negative amounts for expenses, positive for income",
58                                "1 dollar = 1000 milliunits for precision",
59                                "Get account IDs from resources/list endpoint",
60                                "Use 'default' for budget_id to access primary budget"
61                            ]
62                        },
63                        {
64                            "name": "update_transaction",
65                            "description": "Update an existing transaction",
66                            "required_parameters": ["budget_id", "transaction_id"],
67                            "optional_parameters": ["account_id", "amount", "date", "payee_id", "category_id", "memo", "cleared"],
68                            "examples": [
69                                {
70                                    "description": "Update transaction amount and memo",
71                                    "parameters": {
72                                        "budget_id": "default",
73                                        "transaction_id": "11111111-1111-1111-1111-111111111111",
74                                        "amount": -3000,
75                                        "memo": "Coffee shop - updated amount"
76                                    }
77                                }
78                            ]
79                        },
80                        {
81                            "name": "approve_transaction",
82                            "description": "Approve a pending transaction (from bank imports)",
83                            "required_parameters": ["budget_id", "transaction_id"],
84                            "examples": [
85                                {
86                                    "description": "Approve an imported transaction",
87                                    "parameters": {
88                                        "budget_id": "default",
89                                        "transaction_id": "22222222-2222-2222-2222-222222222222"
90                                    }
91                                }
92                            ]
93                        },
94                        {
95                            "name": "clear_transaction",
96                            "description": "Change the cleared status of a transaction",
97                            "required_parameters": ["budget_id", "transaction_id", "clear_state"],
98                            "parameter_details": {
99                                "clear_state": {
100                                    "type": "string",
101                                    "allowed_values": ["cleared", "uncleared", "reconciled"],
102                                    "description": "New cleared state for the transaction"
103                                }
104                            }
105                        }
106                    ]
107                },
108                "transfer_management": {
109                    "description": "Transfer money between accounts",
110                    "tools": [
111                        {
112                            "name": "create_transfer",
113                            "description": "Create a transfer between two accounts in YNAB",
114                            "required_parameters": ["budget_id", "from_account_id", "to_account_id", "amount", "date"],
115                            "optional_parameters": ["memo"],
116                            "examples": [
117                                {
118                                    "description": "Transfer from checking to savings",
119                                    "parameters": {
120                                        "budget_id": "default",
121                                        "from_account_id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
122                                        "to_account_id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
123                                        "amount": 100000,
124                                        "date": "2024-01-15",
125                                        "memo": "Monthly savings"
126                                    }
127                                }
128                            ],
129                            "tips": [
130                                "Transfer amounts are always positive",
131                                "Both accounts must belong to the same budget",
132                                "Transfers automatically balance (debit from source, credit to destination)"
133                            ]
134                        }
135                    ]
136                },
137                "data_analysis": {
138                    "description": "Analyze spending patterns and financial data",
139                    "tools": [
140                        {
141                            "name": "analyze_transactions",
142                            "description": "Comprehensive transaction analysis with unlimited data access",
143                            "required_parameters": ["budget_id"],
144                            "optional_parameters": ["account_id", "category_id", "from_date", "to_date"],
145                            "examples": [
146                                {
147                                    "description": "Analyze all transactions for current month",
148                                    "parameters": {
149                                        "budget_id": "default",
150                                        "from_date": "2024-01-01",
151                                        "to_date": "2024-01-31"
152                                    }
153                                },
154                                {
155                                    "description": "Analyze grocery spending",
156                                    "parameters": {
157                                        "budget_id": "default",
158                                        "category_id": "grocery-category-id"
159                                    }
160                                }
161                            ]
162                        },
163                        {
164                            "name": "analyze_spending_by_category",
165                            "description": "Analyze spending patterns by category over time",
166                            "required_parameters": ["budget_id"],
167                            "optional_parameters": ["months_back"],
168                            "parameter_details": {
169                                "months_back": {
170                                    "type": "number",
171                                    "default": 12,
172                                    "description": "Number of months to analyze (default: 12)"
173                                }
174                            }
175                        },
176                        {
177                            "name": "get_transactions_by_date_range",
178                            "description": "Get ALL transactions within a specific date range (no pagination limits)",
179                            "required_parameters": ["budget_id", "from_date", "to_date"],
180                            "examples": [
181                                {
182                                    "description": "Get all December transactions",
183                                    "parameters": {
184                                        "budget_id": "default",
185                                        "from_date": "2023-12-01",
186                                        "to_date": "2023-12-31"
187                                    }
188                                }
189                            ]
190                        },
191                        {
192                            "name": "get_all_account_transactions",
193                            "description": "Get ALL transactions for a specific account (no limits)",
194                            "required_parameters": ["budget_id", "account_id"]
195                        }
196                    ]
197                },
198                "budget_management": {
199                    "description": "Manage budget categories and assignments",
200                    "tools": [
201                        {
202                            "name": "set_category_budget",
203                            "description": "Assign money to a budget category for a specific month",
204                            "required_parameters": ["budget_id", "category_id", "budgeted_amount"],
205                            "optional_parameters": ["month"],
206                            "parameter_details": {
207                                "budgeted_amount": {
208                                    "type": "string or number",
209                                    "examples": ["50.00", "50000", 50000],
210                                    "description": "Amount in dollars (e.g., '50.00') or milliunits (e.g., 50000)"
211                                },
212                                "month": {
213                                    "type": "string",
214                                    "format": "YYYY-MM-DD",
215                                    "default": "current month",
216                                    "description": "Month to assign budget for"
217                                }
218                            },
219                            "examples": [
220                                {
221                                    "description": "Assign $200 to groceries for current month",
222                                    "parameters": {
223                                        "budget_id": "default",
224                                        "category_id": "grocery-category-id",
225                                        "budgeted_amount": "200.00"
226                                    }
227                                }
228                            ]
229                        }
230                    ]
231                },
232                "system_management": {
233                    "description": "Server health, cache management, and system operations",
234                    "tools": [
235                        {
236                            "name": "health_check",
237                            "description": "Check the health and connectivity of the YNAB API connection",
238                            "required_parameters": [],
239                            "response_format": {
240                                "status": "healthy or unhealthy",
241                                "uptime_seconds": "server uptime",
242                                "response_time_ms": "API response time",
243                                "api_connectivity": "YNAB API status"
244                            }
245                        },
246                        {
247                            "name": "cache_management",
248                            "description": "Manage the YNAB API response cache for improved performance",
249                            "required_parameters": ["action"],
250                            "parameter_details": {
251                                "action": {
252                                    "type": "string",
253                                    "allowed_values": ["stats", "cleanup", "clear"],
254                                    "descriptions": {
255                                        "stats": "Show cache statistics and hit rates",
256                                        "cleanup": "Remove expired cache entries",
257                                        "clear": "Remove all cache entries"
258                                    }
259                                }
260                            }
261                        }
262                    ]
263                }
264            },
265            "global_parameters": {
266                "budget_id": {
267                    "description": "YNAB budget identifier",
268                    "special_values": {
269                        "default": "Use the primary/first budget",
270                        "last-used": "Use the most recently accessed budget"
271                    },
272                    "format": "UUID string or special value"
273                },
274                "amounts": {
275                    "format": "milliunits (1000 milliunits = $1.00)",
276                    "examples": {
277                        "$1.00": 1000,
278                        "$10.50": 10500,
279                        "-$5.25": -5250
280                    },
281                    "notes": "Always use integers for milliunits precision"
282                },
283                "dates": {
284                    "format": "YYYY-MM-DD",
285                    "examples": ["2024-01-15", "2023-12-31"],
286                    "timezone": "Server timezone (typically UTC)"
287                },
288                "uuids": {
289                    "format": "Standard UUID format",
290                    "example": "12345678-1234-1234-1234-123456789abc",
291                    "how_to_get": "Use resources/list endpoint or other list operations"
292                }
293            },
294            "error_codes": {
295                "authentication_errors": {
296                    "description": "API token issues, keyring problems",
297                    "solutions": [
298                        "Check YNAB API token at https://app.youneedabudget.com/settings/developer",
299                        "Use 'ynab-mcp store-token' to store token securely",
300                        "Verify token has not expired"
301                    ]
302                },
303                "rate_limit_errors": {
304                    "description": "YNAB API rate limit exceeded (200 requests/hour)",
305                    "solutions": [
306                        "Use cache_management tools to optimize requests",
307                        "Wait 15+ minutes before retrying",
308                        "Check rate limit status with health_check"
309                    ]
310                },
311                "validation_errors": {
312                    "description": "Invalid parameters or malformed requests",
313                    "solutions": [
314                        "Check parameter types and formats",
315                        "Verify UUIDs are valid and exist",
316                        "Use resources/list to get valid IDs"
317                    ]
318                }
319            },
320            "best_practices": {
321                "performance": [
322                    "Use cache_management to monitor and optimize cache usage",
323                    "Batch related operations together",
324                    "Use date ranges to limit large queries",
325                    "Check health_check before bulk operations"
326                ],
327                "reliability": [
328                    "Handle rate limit errors gracefully with retries",
329                    "Validate parameters before making requests",
330                    "Use read-only mode for exploration",
331                    "Store sensitive tokens securely with keyring"
332                ],
333                "data_accuracy": [
334                    "Use milliunits for precise money calculations",
335                    "Verify account and category IDs exist before using",
336                    "Use proper date formats (YYYY-MM-DD)",
337                    "Double-check transaction amounts and signs"
338                ]
339            }
340        })
341    }
342
343    /// Get comprehensive documentation for all resources
344    pub fn get_resources_documentation() -> Value {
345        json!({
346            "version": "1.0.0",
347            "last_updated": "2024-01-15",
348            "description": "YNAB MCP Server Resource Documentation - Complete reference for all available resources",
349            "base_uri": "ynab://",
350            "resource_types": {
351                "budgets": {
352                    "description": "Access to YNAB budgets and their properties",
353                    "uri_patterns": [
354                        "ynab://budgets",
355                        "ynab://budgets/{budget_id}"
356                    ],
357                    "examples": [
358                        {
359                            "uri": "ynab://budgets",
360                            "description": "List all available budgets",
361                            "response_contains": ["budget_id", "budget_name", "last_modified", "first_month", "last_month"]
362                        },
363                        {
364                            "uri": "ynab://budgets/default",
365                            "description": "Get details of the primary budget",
366                            "response_contains": ["accounts", "categories", "payees", "currency_format"]
367                        }
368                    ]
369                },
370                "accounts": {
371                    "description": "Bank accounts, credit cards, and other account types",
372                    "uri_patterns": [
373                        "ynab://budgets/{budget_id}/accounts",
374                        "ynab://budgets/{budget_id}/accounts/{account_id}"
375                    ],
376                    "account_types": [
377                        "checking", "savings", "creditCard", "cash",
378                        "lineOfCredit", "otherAsset", "otherLiability"
379                    ],
380                    "examples": [
381                        {
382                            "uri": "ynab://budgets/default/accounts",
383                            "description": "List all accounts in the default budget"
384                        },
385                        {
386                            "uri": "ynab://budgets/default/accounts/12345678-1234-1234-1234-123456789abc",
387                            "description": "Get specific account details including balance"
388                        }
389                    ]
390                },
391                "categories": {
392                    "description": "Budget categories and category groups",
393                    "uri_patterns": [
394                        "ynab://budgets/{budget_id}/categories",
395                        "ynab://budgets/{budget_id}/categories/{category_id}",
396                        "ynab://budgets/{budget_id}/category_groups/{group_id}/categories"
397                    ],
398                    "examples": [
399                        {
400                            "uri": "ynab://budgets/default/categories",
401                            "description": "List all categories with budgeted amounts and activity"
402                        },
403                        {
404                            "uri": "ynab://budgets/default/categories/grocery-category-id",
405                            "description": "Get specific category with detailed spending information"
406                        }
407                    ]
408                },
409                "transactions": {
410                    "description": "All transaction data with filtering capabilities",
411                    "uri_patterns": [
412                        "ynab://budgets/{budget_id}/transactions",
413                        "ynab://budgets/{budget_id}/accounts/{account_id}/transactions",
414                        "ynab://budgets/{budget_id}/categories/{category_id}/transactions"
415                    ],
416                    "query_parameters": {
417                        "since_date": "Get transactions since a specific date (YYYY-MM-DD)",
418                        "type": "Filter by transaction type (uncategorized, unapproved)"
419                    },
420                    "examples": [
421                        {
422                            "uri": "ynab://budgets/default/transactions",
423                            "description": "All transactions in the budget"
424                        },
425                        {
426                            "uri": "ynab://budgets/default/accounts/checking-account-id/transactions",
427                            "description": "All transactions for a specific account"
428                        },
429                        {
430                            "uri": "ynab://budgets/default/categories/grocery-id/transactions",
431                            "description": "All transactions in a specific category"
432                        }
433                    ]
434                },
435                "payees": {
436                    "description": "Merchants, people, and organizations you pay",
437                    "uri_patterns": [
438                        "ynab://budgets/{budget_id}/payees",
439                        "ynab://budgets/{budget_id}/payees/{payee_id}"
440                    ],
441                    "special_payees": {
442                        "transfer_payees": "Generated automatically for transfers between accounts",
443                        "starting_balance": "Special payee for account opening balances"
444                    }
445                },
446                "months": {
447                    "description": "Monthly budget data and category assignments",
448                    "uri_patterns": [
449                        "ynab://budgets/{budget_id}/months",
450                        "ynab://budgets/{budget_id}/months/{month}",
451                        "ynab://budgets/{budget_id}/months/{month}/categories"
452                    ],
453                    "month_format": "YYYY-MM-DD (first day of month)",
454                    "examples": [
455                        {
456                            "uri": "ynab://budgets/default/months",
457                            "description": "List all available months with budget data"
458                        },
459                        {
460                            "uri": "ynab://budgets/default/months/2024-01-01",
461                            "description": "Get budget data for January 2024"
462                        }
463                    ]
464                },
465                "user": {
466                    "description": "User profile information",
467                    "uri_patterns": ["ynab://user"],
468                    "response_contains": ["user_id", "email", "subscription"]
469                },
470                "scheduled_transactions": {
471                    "description": "Recurring transactions and scheduled transfers",
472                    "uri_patterns": [
473                        "ynab://budgets/{budget_id}/scheduled_transactions",
474                        "ynab://budgets/{budget_id}/scheduled_transactions/{scheduled_transaction_id}"
475                    ]
476                }
477            },
478            "data_formats": {
479                "monetary_values": {
480                    "format": "milliunits (integers)",
481                    "precision": "1000 milliunits = $1.00",
482                    "examples": {
483                        "positive_income": 250000,
484                        "negative_expense": -150000,
485                        "zero_balance": 0
486                    }
487                },
488                "dates": {
489                    "format": "YYYY-MM-DD or ISO 8601",
490                    "timezone": "UTC or local timezone"
491                },
492                "cleared_states": {
493                    "cleared": "Transaction has been confirmed/reconciled",
494                    "uncleared": "Transaction is pending or unconfirmed",
495                    "reconciled": "Transaction has been reconciled against bank statement"
496                },
497                "account_types": {
498                    "on_budget": ["checking", "savings", "cash"],
499                    "off_budget": ["otherAsset", "otherLiability"],
500                    "debt": ["creditCard", "lineOfCredit"]
501                }
502            },
503            "filtering_and_querying": {
504                "date_filtering": {
505                    "parameter": "since_date",
506                    "format": "YYYY-MM-DD",
507                    "description": "Get data modified since this date",
508                    "example": "ynab://budgets/default/transactions?since_date=2024-01-01"
509                },
510                "transaction_types": {
511                    "uncategorized": "Transactions without a category assigned",
512                    "unapproved": "Transactions from bank imports awaiting approval"
513                },
514                "account_filtering": {
515                    "on_budget": "Include only on-budget accounts",
516                    "off_budget": "Include only off-budget (tracking) accounts"
517                }
518            },
519            "caching_behavior": {
520                "cache_ttl": {
521                    "budgets": "30 minutes (structure changes infrequently)",
522                    "accounts": "30 minutes",
523                    "categories": "30 minutes",
524                    "transactions": "2 minutes (changes frequently)",
525                    "payees": "30 minutes",
526                    "user": "60 minutes"
527                },
528                "cache_keys": "Based on URI and query parameters",
529                "cache_invalidation": "Automatic expiration based on TTL"
530            },
531            "common_use_cases": {
532                "budget_overview": {
533                    "description": "Get complete budget picture",
534                    "resources": [
535                        "ynab://budgets/default",
536                        "ynab://budgets/default/accounts",
537                        "ynab://budgets/default/categories"
538                    ]
539                },
540                "spending_analysis": {
541                    "description": "Analyze spending by category or account",
542                    "resources": [
543                        "ynab://budgets/default/transactions",
544                        "ynab://budgets/default/categories/{category_id}/transactions"
545                    ]
546                },
547                "account_reconciliation": {
548                    "description": "Match transactions with bank statements",
549                    "resources": [
550                        "ynab://budgets/default/accounts/{account_id}",
551                        "ynab://budgets/default/accounts/{account_id}/transactions"
552                    ]
553                },
554                "monthly_review": {
555                    "description": "Review monthly budget performance",
556                    "resources": [
557                        "ynab://budgets/default/months/{month}",
558                        "ynab://budgets/default/months/{month}/categories"
559                    ]
560                }
561            },
562            "troubleshooting": {
563                "invalid_uri": {
564                    "symptoms": "Resource not found errors",
565                    "solutions": [
566                        "Check URI format against patterns",
567                        "Verify budget_id, account_id, etc. are valid UUIDs",
568                        "Use 'default' for primary budget",
569                        "List available resources first"
570                    ]
571                },
572                "empty_responses": {
573                    "symptoms": "No data returned",
574                    "solutions": [
575                        "Check date ranges are reasonable",
576                        "Verify filters aren't too restrictive",
577                        "Ensure budget has data for requested time period",
578                        "Check account/category exists and has transactions"
579                    ]
580                },
581                "performance_issues": {
582                    "symptoms": "Slow responses or timeouts",
583                    "solutions": [
584                        "Use date ranges to limit large queries",
585                        "Check cache_management stats",
586                        "Monitor rate limiting with health_check",
587                        "Consider using specific account/category filters"
588                    ]
589                }
590            }
591        })
592    }
593
594    /// Get MCP protocol compliance documentation  
595    pub fn get_mcp_protocol_documentation() -> Value {
596        json!({
597            "protocol_version": "2024-11-05",
598            "server_info": {
599                "name": "ynab-mcp",
600                "version": "0.1.0",
601                "description": "YNAB Model Context Protocol Server",
602                "author": "YNAB MCP Contributors",
603                "homepage": "https://github.com/your-org/ynab-mcp"
604            },
605            "capabilities": {
606                "tools": {
607                    "supported": true,
608                    "list_changed": false,
609                    "count": 12
610                },
611                "resources": {
612                    "supported": true,
613                    "subscribe": false,
614                    "list_changed": false
615                },
616                "prompts": {
617                    "supported": true,
618                    "list_changed": false,
619                    "count": 5
620                },
621                "logging": {
622                    "supported": false
623                },
624                "completion": {
625                    "supported": false
626                }
627            },
628            "supported_methods": [
629                "initialize",
630                "tools/list",
631                "tools/call",
632                "resources/list",
633                "resources/read",
634                "prompts/list",
635                "prompts/get"
636            ],
637            "error_handling": {
638                "supported_codes": {
639                    "-32601": "Method not found",
640                    "-32602": "Invalid params",
641                    "-32603": "Internal error",
642                    "-32001": "Authentication Error",
643                    "-32002": "Rate Limit Exceeded",
644                    "-32003": "Network Error",
645                    "-32004": "Resource Not Found",
646                    "-32005": "Permission Denied"
647                },
648                "error_format": {
649                    "code": "Standard JSON-RPC error code",
650                    "message": "Human-readable error description",
651                    "data": {
652                        "description": "Detailed error information",
653                        "error_id": "Unique error identifier for troubleshooting",
654                        "correlation_id": "Request correlation ID",
655                        "timestamp": "ISO 8601 timestamp"
656                    }
657                }
658            },
659            "transport": {
660                "method": "stdio",
661                "format": "JSON-RPC 2.0",
662                "encoding": "UTF-8"
663            }
664        })
665    }
666
667    /// Get comprehensive usage examples and tutorials
668    pub fn get_usage_examples() -> Value {
669        json!({
670            "quick_start": {
671                "description": "Common workflows for getting started",
672                "examples": [
673                    {
674                        "title": "Basic Budget Overview",
675                        "steps": [
676                            {
677                                "step": 1,
678                                "action": "Get server capabilities",
679                                "method": "initialize",
680                                "expected_response": "Server info and capabilities"
681                            },
682                            {
683                                "step": 2,
684                                "action": "List available tools",
685                                "method": "tools/list",
686                                "expected_response": "12 available tools"
687                            },
688                            {
689                                "step": 3,
690                                "action": "Get budget list",
691                                "method": "resources/read",
692                                "params": {"uri": "ynab://budgets"},
693                                "expected_response": "List of available budgets"
694                            },
695                            {
696                                "step": 4,
697                                "action": "Get budget details",
698                                "method": "resources/read",
699                                "params": {"uri": "ynab://budgets/default"},
700                                "expected_response": "Complete budget information"
701                            }
702                        ]
703                    },
704                    {
705                        "title": "Create and Track an Expense",
706                        "steps": [
707                            {
708                                "step": 1,
709                                "action": "Get available accounts",
710                                "method": "resources/read",
711                                "params": {"uri": "ynab://budgets/default/accounts"}
712                            },
713                            {
714                                "step": 2,
715                                "action": "Create expense transaction",
716                                "method": "tools/call",
717                                "params": {
718                                    "name": "create_transaction",
719                                    "arguments": {
720                                        "budget_id": "default",
721                                        "account_id": "checking-account-id",
722                                        "amount": -2500,
723                                        "date": "2024-01-15",
724                                        "memo": "Lunch at cafe"
725                                    }
726                                }
727                            },
728                            {
729                                "step": 3,
730                                "action": "Verify transaction was created",
731                                "method": "resources/read",
732                                "params": {"uri": "ynab://budgets/default/transactions"}
733                            }
734                        ]
735                    },
736                    {
737                        "title": "Monthly Spending Analysis",
738                        "steps": [
739                            {
740                                "step": 1,
741                                "action": "Analyze spending by category",
742                                "method": "tools/call",
743                                "params": {
744                                    "name": "analyze_spending_by_category",
745                                    "arguments": {
746                                        "budget_id": "default",
747                                        "months_back": 3
748                                    }
749                                }
750                            },
751                            {
752                                "step": 2,
753                                "action": "Get specific date range transactions",
754                                "method": "tools/call",
755                                "params": {
756                                    "name": "get_transactions_by_date_range",
757                                    "arguments": {
758                                        "budget_id": "default",
759                                        "from_date": "2024-01-01",
760                                        "to_date": "2024-01-31"
761                                    }
762                                }
763                            }
764                        ]
765                    }
766                ]
767            },
768            "advanced_workflows": {
769                "budget_optimization": {
770                    "description": "Optimize budget allocations based on spending patterns",
771                    "tools_used": ["analyze_spending_by_category", "set_category_budget"],
772                    "workflow": [
773                        "Analyze historical spending by category",
774                        "Identify categories that are over/under budget",
775                        "Adjust budget allocations accordingly",
776                        "Monitor changes over time"
777                    ]
778                },
779                "account_reconciliation": {
780                    "description": "Reconcile accounts with bank statements",
781                    "tools_used": ["get_all_account_transactions", "clear_transaction", "approve_transaction"],
782                    "workflow": [
783                        "Get all transactions for the account",
784                        "Compare with bank statement",
785                        "Approve pending transactions",
786                        "Mark transactions as reconciled"
787                    ]
788                }
789            },
790            "ai_integration_tips": {
791                "natural_language_processing": [
792                    "Parse user intent for budget categories (e.g., 'food' -> grocery category)",
793                    "Extract amounts from natural language (e.g., 'twenty-five dollars' -> 25000 milliunits)",
794                    "Interpret relative dates (e.g., 'last month' -> calculate date range)"
795                ],
796                "error_recovery": [
797                    "Handle rate limit errors with exponential backoff",
798                    "Suggest alternative approaches when resources are not found",
799                    "Provide helpful error messages with remediation steps"
800                ],
801                "performance_optimization": [
802                    "Use caching to avoid repeated API calls",
803                    "Batch related operations together",
804                    "Use specific filters to limit data transfer"
805                ]
806            }
807        })
808    }
809}
810
811#[cfg(test)]
812mod tests {
813    use super::*;
814
815    #[test]
816    fn test_get_tools_documentation() {
817        let docs = ApiDocumentation::get_tools_documentation();
818
819        // Verify tools documentation structure
820        assert!(docs.is_object());
821        assert!(docs["version"].is_string());
822        assert!(docs["description"].is_string());
823        assert!(docs["categories"].is_object());
824
825        // Verify categories structure
826        let categories = &docs["categories"];
827        assert!(categories["transaction_management"].is_object());
828        assert!(categories["budget_management"].is_object());
829    }
830
831    #[test]
832    fn test_get_resources_documentation() {
833        let docs = ApiDocumentation::get_resources_documentation();
834
835        // Basic structure validation
836        assert!(docs.is_object());
837        // The exact structure may vary, just verify it returns valid JSON
838    }
839
840    #[test]
841    fn test_get_mcp_protocol_documentation() {
842        let docs = ApiDocumentation::get_mcp_protocol_documentation();
843
844        // Basic structure validation
845        assert!(docs.is_object());
846        assert!(docs["protocol_version"].is_string());
847        // The exact structure may vary, just verify it returns valid JSON
848    }
849
850    #[test]
851    fn test_get_usage_examples() {
852        let docs = ApiDocumentation::get_usage_examples();
853
854        // Basic structure validation
855        assert!(docs.is_object());
856        // The exact structure may vary, just verify it returns valid JSON
857    }
858
859    #[test]
860    fn test_api_documentation_struct() {
861        // Test that ApiDocumentation is a unit struct and can be referenced
862        let _api_docs = ApiDocumentation;
863
864        // Test that we can call static methods
865        let tools_docs = ApiDocumentation::get_tools_documentation();
866        assert!(tools_docs.is_object());
867
868        let resources_docs = ApiDocumentation::get_resources_documentation();
869        assert!(resources_docs.is_object());
870
871        let protocol_docs = ApiDocumentation::get_mcp_protocol_documentation();
872        assert!(protocol_docs.is_object());
873
874        let usage_docs = ApiDocumentation::get_usage_examples();
875        assert!(usage_docs.is_object());
876    }
877
878    #[test]
879    fn test_tools_documentation_completeness() {
880        let docs = ApiDocumentation::get_tools_documentation();
881
882        // Check that tool categories have meaningful content
883        let categories = &docs["categories"];
884        let transaction_mgmt = &categories["transaction_management"];
885        assert!(transaction_mgmt["tools"].is_array());
886
887        let tools = transaction_mgmt["tools"].as_array().unwrap();
888        assert!(
889            tools.len() > 2,
890            "Should have multiple transaction management tools"
891        );
892    }
893
894    #[test]
895    fn test_documentation_json_serialization() {
896        let tools_docs = ApiDocumentation::get_tools_documentation();
897        let resources_docs = ApiDocumentation::get_resources_documentation();
898        let protocol_docs = ApiDocumentation::get_mcp_protocol_documentation();
899        let usage_docs = ApiDocumentation::get_usage_examples();
900
901        // Test that all documentation can be serialized to JSON
902        assert!(serde_json::to_string(&tools_docs).is_ok());
903        assert!(serde_json::to_string(&resources_docs).is_ok());
904        assert!(serde_json::to_string(&protocol_docs).is_ok());
905        assert!(serde_json::to_string(&usage_docs).is_ok());
906    }
907}