# Code Mode Extension

> Execute JavaScript code to interact with multiple MCP tools

- 网址：https://funcoding.ai/agents/goose/mcp/code-mode-mcp/
- 来源：goose 官方文档原文（英文），Apache-2.0 许可，同步于 2026-10-11
- 官方原文：https://goose-docs.ai/docs/mcp/code-mode-mcp

---
The Code Mode extension enables [Code Mode](https://funcoding.ai/agents/goose/guides/managing-tools/code-mode/), a programmatic approach for interacting with MCP tools.

The Code Mode extension is an MCP server that exposes three meta-tools. When Code Mode is enabled, the LLM writes JavaScript code that goose executes using a Deno-based runtime called [Port of Context](https://github.com/AdrianCole/pctx) to discover tools, learn their interfaces, and call them programmatically.

This helps manage context window usage more efficiently when multiple extensions are enabled and when performing workflows with multiple tool calls.

## Configuration

**goose Desktop**

**goose CLI**

1. Run the `configure` command:
```sh
goose configure
```

2. Choose to `Toggle Extensions`
```sh
┌   goose-configure 
│
◇  What would you like to configure?
│  Toggle Extensions 
│
◆  Enable extensions: (use "space" to toggle and "enter" to submit)
// highlight-start    
│  ● code_execution
// highlight-end  
└  Extension settings updated successfully
```

## Example Usage

In this example, we'll ask goose to compile a report that requires multiple tool calls.

### goose Prompt

```
Create a LOG.md file with the current git branch, last 3 commits, and the version from package.json
```

### goose Output

<div class="callout callout-note">

**Desktop**

I'll help you create a LOG.md file with the git branch, last 3 commits, and version from package.json. Let me gather all this information in one operation.

`Execute Code code: import { shell, text_editor } from "developer" ...`

Let me check the package.json path first:

`Execute Code code: import { shell, text_editor } from "developer" ...`

Perfect! I've created the **LOG.md** file with:

- ✅ **Current git branch**
- ✅ **Last 3 commits** (with hash, message, author, and relative time)
- ✅ **Version** from ui/desktop/package.json

The file has been saved to the root directory as `LOG.md`.

</div>
