Scaling MCP Tools with Anthropic's Programmatic Tool Calling

Updated:


December 27, 2025

Learn how to use Anthropic's code_execution programatic tool calling features with Unified's MCP server to efficiently manage hundreds of tools while maintaining high accuracy and context efficiency.

When building AI applications with MCP servers, including the Unified MCP server, you quickly encounter a critical challenge: most LLM models will hit their model context threshold and stop processing.

And Anthropic's new code_execution feature creates internal Python code that invokes the tool as a function, potentially including multiple tool calls and pre/post-processing logic.

The Problem: Too Many Round Trips For Each Tool Invocation

With the Unified MCP server, you can expose many MCP servers at once for an LLM to perform complex multi-step processes. With 2218 integrations and support for 212,000+ tools, the LLM can be requested to perform very lengthy complicate processes.

But, these multi-step processes cause significant problems:

  • Latency: Multi-tool workflows can significantly extend the processing time of a query
  • Large token consumption: Running multi-tool workflows will cause a token usage spike as each tool's inout and output must be tokenized for each step
  • LLM Model's Context Window: Processing tools, inputs, and outputs for each step in a multi-step process can normally exhaust the LLM model's context window (ie. maximum tokens).

The Solution: Anthropic's Code Execution

Anthropic's code_execution feature works by designating which tools can be called internally by it's code execution feature.

How It Works

  1. You include a tool search tool in your tools list
  2. You provide all tool definitions with allowed_callers: [ "code_execution_20250825" ]
  3. Include a special tool entry:
    {
      "type": "code_execution_20250825",
      "name": "code_execution"
    },
    
  4. Claude can now write Python code that invokes the tool as a function, potentially including multiple tool calls and pre/post-processing logic
  5. Claude runs this code in a sandboxed container via code execution
  6. When a tool function is called, code execution pauses and the API returns a tool_use block

Implementation

To use the new code_execution tool option, follow these instructions (found here) when calling Anthropic's /v1/messages API:

  • Add "advanced-tool-use-2025-11-20"  to the anthropic-beta header: anthropic-beta: advanced-tool-use-2025-11-20,mcp-client-2025-11-20
  • Add the Unified MCP server's URL for your region with the connection ID, and put a connection-scoped token in authorization_token, which Anthropic sends as the Authorization: Bearer header (the ?token= URL parameter is deprecated)
"mcp_servers": [
  {
    "type": "url",
    "name": "unified-salesforce-server",
    "url": "https://mcp-api.unified.to/mcp?connection=y",
    "authorization_token": "YOUR_CONNECTION_SCOPED_TOKEN"
  }
],
  • Then add an additional tools array with configuration on which tools to defer:
"tools": [
  {
    "type": "code_execution_20250825",
    "name": "code_execution"
  },
  {
    "type": "mcp_toolset",
    "mcp_server_name": "unified-salesforce-server",
    "default_config": {
      "defer_loading": true
    },
    "configs": {
      "list_crm_contacts": {
        "defer_loading": false
      }
    }
  }
],
  • Use the default_config.defer_loading: true option to make all tools deferrable
  • Use the configs.{tool_id}.defer_loading: true/false to set an individual tool to defer (or not)

Or, alternatively, you can call the Unified MCP /tools endpoint with parameters ?type=anthropic&defer_tools=all and then feed that tools result into Anthropic's API.

Best Practices

1. Keep Core Tools Non-Deferred

If you have 3-5 tools that are frequently used, keep them as non-deferred.

2. Use Permissions to Scope Tools

Reduce the tool catalog size by requesting only the permissions you need:

// Instead of all tools across all categories
permissions: 'crm_contact_read,crm_contact_write,crm_deal_read'

// This is better than loading 200+ tools from all categories

3. Restrict Tools

Use the Unified MCP tools parameter to restrict which tools will be returned back to the LLM API.

This has a different effect than the defer_tools parameter as it doesn't return restricted tools to the LLM API at all, while deferring tools means that the LLM API knows about the tool, but doesnt process it until it is needed.

4. Monitor Token Usage

Track your token consumption to understand the benefits:

console.log(`Input tokens: ${response.usage.input_tokens}`);
console.log(`Output tokens: ${response.usage.output_tokens}`);
console.log(`Tool search requests: ${response.usage.server_tool_use?.tool_search_requests}`);

5. Combine with Prompt Caching

Use prompt caching with defer_loading for multi-turn conversations:

messages.push({
    role: "user",
    content: "Now find their recent deals",
    cache_control: { type: "ephemeral" }
});

Tool Search Limits

Be aware of these limits:

  • Maximum tools: 10,000 tools in your catalog
  • Search results: Returns 3-5 most relevant tools per search
  • Pattern length: Maximum 200 characters for regex patterns
  • Model support: Claude Sonnet 4.5+ and Opus 4.5+ only

When to Use Defer Loading

Good use cases:

  • 20+ tools available from Unified connections
  • Multiple integrations (CRM + ATS + HRIS + Storage)
  • Building multi-tenant applications where each tenant has different integrations
  • Context window is getting tight with tool definitions
  • Tool selection accuracy is degrading

When traditional tool calling might be better:

  • Less than 10 tools total
  • All tools are frequently used in every request
  • Very focused single-integration use case

Real-World Example: Multi-Integration Assistant

Here's a practical example of a customer support assistant that accesses multiple integrations:

async function createSupportAssistant(crm_connection_id, hris_connection_id, zendesk_connection_id) {
    // Fetch tools from multiple Unified connections
    const crmTools = await fetchUnifiedTools(crm_connection_id, 'crm_contact_read,crm_deal_read', { type: 'anthropic', defer_tools: 'list_crm_'});
    const ticketingTools = await fetchUnifiedTools(zendesk_connection_id, 'ticketing_ticket_read,ticketing_ticket_write', { type: 'anthropic', defer_tools: 'list_crm_'});
    const hrisTools = await fetchUnifiedTools(hris_connection_id, 'hris_employee_read', { type: 'anthropic', defer_tools: 'list_crm_'});

    // Combine all tools with defer_loading
    const tools = [
        ...crmTools,
        ...ticketingTools,
        ...hrisTools
    ];

    // Total: 150+ tools, with all listX tools being deffered
    return await anthropic.beta.messages.create({
        model: "claude-sonnet-4-5-20250929",
        betas: ["advanced-tool-use-2025-11-20"],
        max_tokens: 4096,
        messages: [{
            role: "user",
            content: "Customer John Doe from Acme Corp called about ticket #12345. Show me his account info, open tickets, and any recent deals."
        }],
        tools: tools
    });
}

Resources

TLDR

Anthropic's defer_loading feature is a game-changer for building AI applications with Unified's MCP server. By the LLM API dynamically loading tools on-demand, you can:

  • Scale to hundreds of tools across multiple integrations
  • Reduce context usage by 80-90%
  • Improve tool selection accuracy significantly
  • Build more capable AI assistants that access diverse data sources

Start by adding the tool search tool and marking your Unified MCP tools as deferred. Monitor your token usage and tool selection accuracy to see the immediate benefits.

The combination of Unified's extensive integration network and Anthropic's intelligent tool search opens up possibilities for building truly comprehensive AI agents that can work across your entire SaaS ecosystem.

Share
All guidesAccounting Account Type Hierarchy in UnifiedAdvertising Report Metrics by IntegrationAmazon S3: Required IAM PermissionsATS to Vector DB: How to Power Talent Intelligence with Real-Time DataBuilding AI applications with Unified and LangbaseConcur & Concur (Company) — Connection GuideConfigure Greenhouse Native Candidate WebhooksConfigure Salesforce Meetings and Notes for UnifiedConnect Amazon Seller Central to Unified.toConnecting BambooHR via OAuth 2Connecting Google Workspace Integrations with a Service AccountCorrect WelcomeKit Scopes for Jungle IntegrationCreating Ads using the Unified Ads APICreating Walmart Items via UnifiedEnd-Users, Integrations, and ConnectionsEnriching Unified Objects with Custom MetadataEnterprise-managed authorization (EMA) with a static keyEnterprise-managed authorization (EMA) with a workspace secretEnterprise-managed authorization (EMA) with Microsoft Entra IDExtended observability — pushing API logs to ClickHouseExtended observability — pushing API logs to Grafana / LokiExtended Observability - Pushing API Logs to your Datadog InstanceFacebook Messenger Webhook SetupFireflies Integration GuideGetting started with WorkableHandling Delegated vs. Application Scopes in Microsoft IntegrationsHiBob & Unified: connection and time off guideHow long are logs retainedHow to access employees and usersHow to add API support for the Create Activity in CrelateHow to Associate a Connection ID with Your End-UserHow to build a Candidate Assessment product withHow to build a candidate sourcing or job board app with Unified.toHow to build a Discord support bot with Unified.to and LangbaseHow to Build a Fintech Application with Unified's Payments APIHow to Build an E-Commerce Product Integration with UnifiedHow to build an invoicing system with Unified.toHow to build Enterprise Search using RAGHow to configure Bullhorn Redirect URI for creating a connectionHow to configure webhooks in HubSpotHow to configure webhooks in Thrive LearningHow to configure webhooks in Toast for UnifiedHow to Connect Anthropic to Real-Time SaaS Data with Unified.to MCP ServerHow to Connect Cohere to Real-Time SaaS Data with Unified.to MCP ServerHow to Connect Google Gemini to Real-Time SaaS Data with Unified.to MCP ServerHow to connect HiBob (Bob) to Unified with OAuth 2.0How to Connect LLMs to Real-Time SaaS Data with Unified.to MCP ServerHow to Connect OpenAI to Real-Time SaaS Data with Unified.to MCP ServerHow to Connect Zoom and Zoom PhoneHow to create a Connection In Microsoft TeamsHow to create a token-based connection in HighlevelHow to Create a Unified.to Connection to HighLevelHow to Create a Xero Connection in Unified.toHow to create and configure webhooksHow to create Connection with HubspotHow to customize portal URLs for Stripe and GoCardlessHow to filter webhook eventsHow-to Get a Private Support Channel for Your Unified IntegrationHow to get help fromHow to get your 8x8 Connect API Key, Account ID and SMS Subaccount ID (optional): Step-by-step guideHow to get your ADP Workforce Now Oauth2 client ID, Oauth2 client secret, Oauth2 PEM certificate and Oauth2 private key: Step-by-step guideHow to get your Amazon S3 AWS Region, AWS S3 Key and AWS S3 Secret: Step-by-step guideHow to get your Ashby API Key: Step-by-step guideHow to get your Brex API token: Step-by-step guideHow to get your Bullhorn OAuth2 Client ID, OAuth2 Client Secret, API Username and API Password: Step-by-step guideHow to get your Ceridian Dayforce Username, Password and Client Namespace: Step-by-step guideHow to get your Crelate API key: Step-by-step guideHow to get your Dashlane API Key: Step-by-step guideHow to get your Deel Access Token: Step-by-step guideHow to get your Dialpad API Key: Step-by-step guideHow to get your Discord OAuth 2 credentials and bot tokenHow to get your ELMO client ID and client secret: Step-by-step guideHow to get your Gainsight Client ID, Client Secret and Gainsight API Domain: Step-by-step guideHow to get your Greenhouse API Key and Job board token: Step-by-step guideHow to get your Helpscout API Key: Step-by-step guideHow to get your HiBob Service User ID and Service User Token: Step-by-step guideHow to get your HighLevel API Key and Location ID: Step-by-step guideHow to get your HubSpot developer key and OAuth 2 credentials (Legacy Apps)How to get your Humaans API Key: Step-by-step guideHow to get your iCIMS API Username, API Password and Customer ID: Step-by-step guideHow to get your JobDiva Client ID, Username/email and Password: Step-by-step guideHow to get your Jobvite API Key, API Key Secret and Email: Step-by-step guideHow to get your Lever API Key: Step-by-step guideHow to get your Loxo Agency slug, API Key and Agency ID: Step-by-step guideHow to get your Microsoft Active Directory / Entra ID Client ID, Client Secret and Tenant ID: Step-by-step guideHow to get your Microsoft Azure AD OAuth 2 credentialsHow to get your OAuth 2 credentials for GmailHow to get your OAuth 2 credentials for Microsoft Dynamics 365How to get your OAuth 2 credentials in PipeDriveHow to get your OpenAI API Key: Step-by-step guideHow to get your Paycom SID/Username and Token/Password: Step-by-step guideHow to get your PCRecruiter Username, Password, Database ID, App Key and App ID: Step-by-step guideHow to get your SAP SuccessFactors (OpenID Connect) Username, Password, Client ID, Client Secret, Dependency Name, IAS Host and API URL: Step-by-step guideHow to get your SAP SuccessFactors Username, Company ID, Password and API URL: Step-by-step guideHow to get your Shopify Admin API access token and Store ID: Step-by-step guideHow to get your Wayfair Client ID, Client Secret and Vendor Encrypted Key: Step-by-step guideHow to get your Workable API Token and Subdomain: Step-by-step guideHow to get your yotpo APP Key / Store ID and Secret Key: Step-by-step guideHow to Handle Attachments in Invoice, Bill and Credit MemoHow to Manage Google Ad Manager Orders, Line Items and Creatives with theHow to migrate or import your integrations into Unified.toHow to obtain your GitHub OAuth2 credentialsHow to Power Claude with Live Customer Data Using Unified MCPHow to receive assessment orders from an ATS with Unified.toHow to register a Google developer app and get OAuth 2 credentialsHow to register a Salesforce developer app and get OAuth 2 credentialsHow to register a Slack developer account and get OAuth 2 credentialsHow to Register a Workday Developer App and Get OAUTH2 CredentialsHow to Register a Workday Developer App and Get OAUTH2/ SOAP CredentialsHow to Register a ZendeskSell Developer App and Get OAUTH2 CredentialsHow to Register a Zoho Developer App and Get OAUTH2 CredentialsHow to Register an ADP Developer App and Get OAUTH2 CredentialsHow to Register an Atlassian Developer App and Get OAUTH2 CredentialsHow to Register your Facebook OAuth2 ApplicationHow to Register your Google Ads OAuth2 ApplicationHow to Register your MetaAds OAuth2 applicationHow To Request & Write Raw Integration DataHow to Retrieve Microsoft Dynamics 365 Business Central CredentialsHow to set up a custom API URL with a CNAMEHow to Set Up a Google Meet Meeting Bot with UnifiedHow to set up a HiBob marketplace installHow to Set Up a Microsoft Teams Bot with UnifiedHow to Set Up a Microsoft Teams Meeting Bot with UnifiedHow to Set Up a Webex Meeting Bot with UnifiedHow to Set Up a Zoom Meeting Bot with UnifiedHow to set up and configure NotionHow to set up Google Business Profile API access and get OAuth 2 credentialsHow to Set Up LinkedIn Webhooks with UnifiedHow to set up native webhooks for QuickBooks Online with UnifiedHow to set up Slack webhooks using event subscriptionsHow to set up Telegram (bot) with Unified.toHow to set up your scopes in HubSpotHow to setup a Freshbooks developer appHow to setup a TikTok Shop applicationHow to Setup AWS Assume Role for AWS Secret ManagerHow to setup Oracle JD EdwardsHow to Setup Quickbooks DesktopHow to setup Sage 100 with Unified.toHow to test webhooks in the Synthetic Data (Sandbox) environmentHow to troubleshoot unhealthy connectionsHow to troubleshoot unhealthy webhooksHow to Use Decision Models with the Unified GenAI APIHow to use SCIM with the Unified APIHow to use the Passthrough APIHow to Use Unified.to's Generative AI API with OpenAI and ClaudeHow to use User Provisioning and Verification with UnifiedHow virtual webhook retry and recovery worksIntegration set-up guide for LeverManaging custom validation rules in SalesforceNetSuite Authentication Setup for UnifiedNotice of Deprecation of Fields and Objects (Nov 2025)Oracle HCM / Taleo OAuth Credentials GuideRetrieval-Augmented Generation (RAG)SalesForce (External Client Apps) on Multiple OrganizationsSAML Single-Sign-OnScaling MCP Tools with Anthropic's (& OpenAI's) Defer LoadingSet Environments for your Unified.to WorkspaceSetting up a Slack Bot Connection with Unified.toSetting up OAuth 2 Credentials for Greenhouse's APIsTrello Connection Guide in UnifiedUnderstanding OAuth2 Authorization flowsUnderstanding Response Time Headers in the Unified APIUnified Assessment API: Embed Assessments Inside ATS PlatformsUnified's MCP ServerUnified MCP Server with LangChain and LangGraphUnlock real-time data with virtual webhooksUse Unified to sign in your users into your applicationVincere OAuth Setup Guide for UnifiedWorkable: Creating candidates and attaching them to jobsWorkday vs Workday Legacy — Why Unified.to Supports BothWorking with hierarchical tree data in Storage, Messaging, and KMS APIs
Are we missing anything? Let us know
Was this page helpful?