1. AI and MCP
  2. Your own agent with the Claude API

With the Claude API MCP connector, your backend sends a message and Claude calls the Treeunfe tools on its own. You don’t write the tool loop or run an MCP client: Anthropic makes the connection to the server.

​
Before you start

  • A Claude API key (ANTHROPIC_API_KEY), created in the Anthropic Console.
  • The access token from the Enterprise MCP OAuth sign-in (TREEUNFE_MCP_ACCESS_TOKEN). The environment is the one you chose in that authorization: HOMOLOGACAO or PRODUCAO. See Sign-in.

​
How it works

The request carries two parts that go together:

ParameterWhat it does
mcp_serversSays where the server is (url), names it (name) and sends the access token in authorization_token. The token is sent as Authorization: Bearer.
toolsAn mcp_toolset entry with the same server name, which makes its tools available to Claude.

The connector is in beta and needs the anthropic-beta: mcp-client-2025-11-20 header.

​
Example

  • Python

  • TypeScript

pip install anthropic
import os
import anthropic

client = anthropic.Anthropic()  # reads ANTHROPIC_API_KEY

response = client.beta.messages.create(
    model="claude-opus-5-5",
    max_tokens=16000,
    betas=["mcp-client-2025-11-20", "server-side-fallback-2026-07-01"],
    fallbacks="default",
    mcp_servers=[
        {
            "type": "url",
            "url": "https://mcp.enterprise.treeunfe.com.br/mcp",
            "name": "treeunfe-enterprise",
            "authorization_token": os.environ["TREEUNFE_MCP_ACCESS_TOKEN"],
        }
    ],
    tools=[{"type": "mcp_toolset", "mcp_server_name": "treeunfe-enterprise"}],
    messages=[
        {
            "role": "user",
            "content": "List the companies in the account and summarize the last 5 NF-e of each.",
        }
    ],
)

if response.stop_reason == "refusal":
    print("The request was declined.")
else:
    for block in response.content:
        if block.type == "text":
            print(block.text)

fallbacks: "default" makes the API try another Claude model if the main model declines the request. You can remove this field and the server-side-fallback-2026-07-01 beta if you don’t want that behavior.

​
Limit the tools

For a read-only agent, turn every tool off by default and turn on only the read tools with default_config and configs:

tools=[
    {
        "type": "mcp_toolset",
        "mcp_server_name": "treeunfe-enterprise",
        "default_config": {"enabled": False},
        "configs": {
            "READ_TOOL_NAME": {"enabled": True},
        },
    }
]

Replace READ_TOOL_NAME with the name shown in the server’s tool list. This adds to the permissions selected at sign-in: even if a tool is enabled, an authorization without issue permission can’t issue invoices.

With the MCP connector, Claude calls tools without asking for approval. The environment is the one from the authorization. To issue in production, have a person confirm the invoice before it is sent, or authorize the agent with read permission only and issue through the REST API after confirmation.