We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Code Mode

When presented with too many tools, models can struggle with calling the right tool or calling it correctly.

One thing models are trained to do is write code. Code Mode bridges what models do really well, and what MCP does well. It exposes tools through a JavaScript API so the model can execute code to search for tools, call tools, and process the results.

Compose Tool Calls

With the GitHub MCP server, an agent could generate:

const issuePage = await tools.github.list_issues({
  owner: "anomalyco",
  repo: "opencode",
  state: "OPEN",
  orderBy: "CREATED_AT",
  direction: "DESC",
  perPage: 20,
  fields: ["number", "title", "assignees"],
});

return issuePage.issues
  .filter((issue) => !issue.assignees?.length)
  .map((issue) => ({
    number: issue.number,
    title: issue.title,
  }));

This example demonstrates an API tool call and programmatically processing the result. The result is way smaller yet so much more relevant.

Code Mode isn't limited to MCPs. It can run built-in and plugin tools.

Deferred Discovery

OpenCode routes MCP tools through Code Mode by default. It shows the model a limited catalog, then lets it discover additional tool signatures using the search function inside execute. Instead of dumping an MCP's entire list of tools into context, the model can use Code Mode to filter for relevant tools when needed.

Disabling Code Mode

You can disable Code Mode in an MCP server's configuration. Only set codemode: false for an MCP server when the provider needs to see its tools in its native tool list.

Assignment

Fix the bug reported in the bootdotdev/learn-ai-coding-starter repository's GitHub issue.

SlopLang allows variable names like score2, but this program currently fails with a syntax error:

slop score2 = 40✨
score2 = score2 + 2✨
hallucinate(score2)✨

It should create a score2 variable set to 40, add 2 to its value, and then print 42. Names can contain digits; they just can't start with them.

Tell OpenCode to run and submit the CLI tests from the project root.