anthropic.tools()

Open a Console session for Anthropic’s async tool runner, including images.

Usage

Source

anthropic.tools(
    *, command=None, args=None, server_parameters=None, tool_kwargs=None
)

Enter this async context once per conversation and pass the yielded list directly to tool_runner(tools=...). The runner executes model tool calls, sends their text and image results back to Claude, and continues until the model finishes. The same Console process stays alive throughout the context; leaving it closes the MCP connection and its subprocess.

You do not need to create an AsyncMCPConsole yourself. To share a connection with ordinary Python calls, use tool() instead.

Parameters

command: Command | None = None

Console executable. Defaults to the installed mcp-console.

args: Sequence[Command] | None = None

Server arguments. Defaults to ["serve"].

server_parameters: Mapping[str, Any] | None = None

MCP stdio settings such as cwd and env. Use cwd to select the workspace whose files the Console session can access.

tool_kwargs: Mapping[str, Any] | None = None
Options passed to Anthropic’s async_mcp_tool, such as defer_loading.

Yields

AsyncIterator[list[Any]]
Native Anthropic tools discovered from the connected Console server.

Examples

Install with pip install 'mcp-console[anthropic]'. Set ANTHROPIC_API_KEY and set ANTHROPIC_MODEL to the Claude model ID you want to use. This script gives the model access to the current directory and asks it to create and inspect a plot:

import asyncio
import os
import mcp_console
from anthropic import AsyncAnthropic


async def main():
    async with AsyncAnthropic() as client:
        async with mcp_console.anthropic.tools(
            server_parameters={"cwd": os.getcwd()},
        ) as tools:
            runner = client.beta.messages.tool_runner(
                model=os.environ["ANTHROPIC_MODEL"],
                max_tokens=4096,
                tools=tools,
                messages=[
                    {
                        "role": "user",
                        "content": "Use Python in Console to plot monthly sales "
                        "[12, 15, 18, 20, 25] and describe the trend.",
                    }
                ],
            )
            message = await runner.until_done()
            for block in message.content:
                if block.type == "text":
                    print(block.text)


asyncio.run(main())

The plot is returned to Claude as an image tool result. The loop above prints Claude’s text response; it does not save the plot to disk.