Skip to main content

anthropic.callable_tools()

Give Anthropic’s tool runner access to an existing Console session.

Usage

Source

anthropic.callable_tools(console, **kwargs)

The runner calls Console’s tools and returns their output to Claude before requesting the next response. Keep the connection open for the whole conversation so later tool calls can use variables from earlier cells. A synchronous client produces synchronous tools; an async client produces async tools for AsyncAnthropic.

Text results return text, and text-only tool errors raise RuntimeError. Results containing images use Anthropic content blocks with the server’s image data and MIME types, preserving the order of text and images. An image result marked as an error raises anthropic.lib.tools.ToolError carrying those blocks, so the tool runner retains the images and error status.

Discovery includes every tool, even when the server has no send tool.

Parameters

console: MCPConsole | AsyncMCPConsole

A connected MCPConsole or AsyncMCPConsole.

**kwargs: Any
Options passed to Anthropic’s beta_tool or beta_async_tool, such as defer_loading.

Returns

list[Any]
All discovered tools for client.beta.messages.tool_runner(tools=...).

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 prints the model’s final answer:

import os
import mcp_console
from anthropic import Anthropic
from mcp_console import MCPConsole

with Anthropic() as client, MCPConsole() as console:
    runner = client.beta.messages.tool_runner(
        model=os.environ["ANTHROPIC_MODEL"],
        max_tokens=4096,
        tools=mcp_console.anthropic.callable_tools(console),
        messages=[
            {
                "role": "user",
                "content": "Use Python in Console to calculate the mean "
                "and sample standard deviation of [12, 15, 18, 20, 25].",
            }
        ],
    )
    message = runner.until_done()
    for block in message.content:
        if block.type == "text":
            print(block.text)