- AI and MCP
- Your own agent with the Claude API
AI and MCP
Your own agent with the Claude API
Use the Treeunfe MCP from your backend with the Claude API MCP connector.
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 Treeunfe organization API Key (
TREEUNFE_API_KEY), preferably a homologation key.
How it works
The request carries two parts that go together:
| Parameter | What it does |
|---|---|
mcp_servers | Says where the server is (url), names it (name) and sends the key in authorization_token. The key is sent as Authorization: Bearer. |
tools | An 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.treeunfe.com.br/mcp",
"name": "treeunfe",
"authorization_token": os.environ["TREEUNFE_API_KEY"],
}
],
tools=[{"type": "mcp_toolset", "mcp_server_name": "treeunfe"}],
messages=[
{
"role": "user",
"content": "Look up the last 5 NF-e issued this month and summarize the amount and status 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",
"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 key’s scope: even if a tool is enabled, a key without nfe:emit can’t issue invoices.
With the MCP connector, Claude calls tools without asking for approval. To issue in production, add a step where a person confirms the invoice data before it’s sent, or give the agent a key with only nfe:read and issue through the REST API after confirmation.