How to Add Tools to an AI Agent
Overview
This guide explains how to add thousands of Membrane-powered tools to your AI Agent.
See a live demo agent built using this guide’s approach
How to Create Tools with Membrane
To create tools with Membrane, you must first add integrations to your workspace. See here for instructions on how to add integrations with external apps:
Tools can be created using different building blocks. However, the most common way is by simply creating Membrane Actions. To learn about other ways to create tools, or for more detail on creating tools with actions, see here:
Architecture
Key Components:
-
Membrane and MCP Server: Tool creation and execution.
-
Tools created with Membrane are exposed via the Membrane MCP Server. Once running/deployed, the MCP Server authenticates users with an access token or
Authorization
header, and exposes the tools that are available for only that user's connected apps.- Visit the MCP Server repo on GitHub for detailed instructions on how to run and deploy it.
-
-
External Apps: External platforms where actions are finally performed, e.g., HubSpot or Salesforce
-
Agent: Facilitates user input and communication between LLM and Membrane
-
Vector Database: Contains two indexes; one for all of the actions in your Membrane workspace, and another for tools from the Membrane MCP Server.
- The first index,
all-actions
, contains all of the actions in the connected Membrane workspace, regardless of the user's connection status to those apps. - The second index,
MCP-tools
, contains all of the tools that are available for the user's active connections only.
- The first index,
-
LLM: Intelligently chooses to invoke tools based on user input.

Preparing to Use Tools
Membrane can power thousands of tools, so only relevant tools should be exposed to the LLM to avoid context bloat.
This is solved by having two indexes. One index contains tools from the end customer’s connected apps via the Membrane MCP Server. These tools are indexed later, during the customer-agent interaction, after the user connects to apps.
The other index contains all of the actions in your workspace, which can be retrieved using the Membrane API or SDK. This indexing should occur before the customer-agent interaction begins.
Therefore, when the user input later suggests that a tool should be invoked, e.g., “create a contact in HubSpot,” the agent will first search the MCP-tools
index for relevant tools from the end user’s connected apps.
If the end user has connected to the app, the relevant tool is exposed to the LLM.
If the tool is not found in this index, it means that the user is not connected to the relevant app, and the agent will default to searching the all-actions
index for a relevant action.
If the action is found here, the agent will suggest that the user connect to the app, or (optionally) present a connection UI for the app.
Then the action will be available as a tool on the MCP Server, and the LLM can invoke it as required.
Customer-Agent Interaction
-
Customer connects apps
- Connections occur via a Connection UI, or the API for backend-to-backend apps.
-
Tools are indexed from MCP Server (in static mode)
- The Membrane MCP Server has both static and dynamic modes. Static mode exposes all tools for a user’s active connections. Dynamic mode exposes only select tools, so it’s used to present only the relevant tools to the LLM.
- When a new user connection to an external app is created, Membrane sends a webhook to your backend. This informs you to re-index tools in the
MCP-tools
index to ensure it's up to date.
-
User sends requests to agent (in chat or backend)
-
Semantic search
MCP-tools
index for tools related to the query-
If none are relevant, fall back to the
all-actions
index to check for relevant actions in non-connected apps.- If a relevant action is found in
all-actions
, prompt the user to connect the corresponding app so that the tool will be dynamically added to the MCP Server.
- If a relevant action is found in
-
-
-
Enable relevant tools
- Using the MCP Server’s dynamic mode, run
enable-tools
with the list of relevant tools found during the previous step (semantic search ofMCP-tools
), and present them to the LLM.
- Using the MCP Server’s dynamic mode, run
-
Call tools (executed on MCP Server)
- Each tool requires a specific input schema. If the user request is missing any required fields, the LLM requests the missing fields, and the tool is finally executed via the MCP Server.
If you have any questions or run into any trouble, reach out to [email protected]
Updated about 18 hours ago