chatlas.register()

Start Console and register its native MCP tools on a chatlas chat.

Usage

Source

chatlas.register(chat, *, command=None, args=None, **kwargs)

Chatlas owns this MCP connection and preserves text and image results. Register once, use chat.chat_async() for model requests, and call await chat.cleanup_mcp_tools() in finally to close the server even if a request fails. For a connection you also call directly from Python, use tool().

Parameters

chat: Any

An existing chatlas Chat.

command: Command | None = None

Console executable. Defaults to the installed mcp-console.

args: Sequence[Command] | None = None

Server arguments. Defaults to ["serve"].

**kwargs: Any
Options passed to chat.register_mcp_tools_stdio_async(). Supply cwd and env inside transport_kwargs. Use the default tool names: a namespace can also change the name used to call the server’s send tool.

Returns

Any
The result of chatlas’s MCP registration.

Examples

Install with pip install 'mcp-console[chatlas]'. Set OPENAI_API_KEY and set OPENAI_MODEL to your model ID for this OpenAI-backed chat:

import asyncio
import os
import mcp_console
from chatlas import ChatOpenAI


async def main():
    chat = ChatOpenAI(model=os.environ["OPENAI_MODEL"])
    try:
        await mcp_console.chatlas.register(
            chat,
            transport_kwargs={"cwd": os.getcwd()},
        )
        await chat.chat_async(
            "Use Python in Console to plot monthly sales "
            "[12, 15, 18, 20, 25] and describe the trend."
        )
    finally:
        await chat.cleanup_mcp_tools()


asyncio.run(main())