Optimize JSON-RPC tool schemas for LLM context windows: minimize token footprint, validate parameters strictly, and return compact, structured responses.
Large Language Models interact with external systems through structured JSON tool schemas. Inefficient tool definitions waste precious context tokens and trigger hallucinated parameters. This guide details how to build high-performance JSON-RPC 2.0 tools for telephony.
1 Context Window Optimization Best Practices
1. Terse Descriptions: Keep schema descriptions clear and concise to conserve system prompt tokens.
2. Strict Parameter Types: Use explicit JSON Schema validation with regex patterns for phone numbers (e.g. ^\+[1-9]\d{1,14}$).
3. Truncated Message Bodies: When returning inbox lists, return only the most recent 5 messages with truncated bodies unless the agent explicitly requests full history.
Frequently Asked Questions • Model Context Protocol & AI Agents
Use standard JSON-RPC 2.0 codes (-32602 for invalid parameters) alongside custom application error codes (e.g. -32001 for number not found, -32002 for quota exceeded).