Cascading Code Calls
Cascading code calls is one of the key use cases of Code Mode. Instead of invoking tools one by one or through the traditional MCP call pattern, it treats MCP tools as callable methods that you can compose into custom business logic. This significantly reduces the number of round trips between the model and the tools, saving a large amount of tokens.
Example Scenario
In the example below, github.list_commits is the official GitHub MCP tool, which can be used to query the commit history of a repository.
The agent’s task is to count the number of commits in the agents repository. If using the github.list_commits tool alone, the model would need to fetch each page of results and aggregate them manually. With 1,503 commits in total and 50 commits per page, there would be 30 pages, requiring 30 separate requests before the information could be summarized. This process consumes a significant amount of tokens. In many scenarios, the upper limit of requests is unpredictable, making repeated requests impractical.
In Code Mode, the github.list_commits MCP tool is exposed as an API, and the model generates the following code that aggregates all the data in a single request.
In complex business scenarios, Code Mode is more convenient and can save a substantial amount of tokens.
async () => { … |
Welcome to Hawa Code: https://www.hawacode.com/