Skip to main content
Version: 1.0-beta

Consuming MCP from an Agent

An AI agent in WSO2 Agent Builder can use any MCP server as a tool source. Add the server once, and the agent picks up every tool the server advertises (or only the ones you select) and treats them exactly like local function tools.

Adding an MCP server to an agent​

On the agent canvas, select Add Tool at the bottom-right corner of the AI Agent node, then select Use MCP Server. In the Add Tool - Use MCP Server panel, select Connect Manually to enter a server URL. To use an MCP server that your organization added to WSO2 Agent Manager, select WSO2 Agent Manager instead. The manual connection form opens:

The agent canvas with the Add Tool - Use MCP Server panel open, showing Server Url (http://localhost:8080/mcp), a Requires Authentication checkbox, Tools to Include set to Selected, the Available Tools list (3 of 3 selected: getTextStatistics, getReadabilityScore, and analyzeStructure, each with a Read more link) with a Deselect All button, a collapsed Advanced Configurations section, and Result (default aiMcpbasetoolkit).The agent canvas with the Add Tool - Use MCP Server panel open, showing Server Url (http://localhost:8080/mcp), a Requires Authentication checkbox, Tools to Include set to Selected, the Available Tools list (3 of 3 selected: getTextStatistics, getReadabilityScore, and analyzeStructure, each with a Read more link) with a Deselect All button, a collapsed Advanced Configurations section, and Result (default aiMcpbasetoolkit).
FieldWhat it does
Server UrlThe MCP endpoint, for example http://localhost:8080/mcp.
Requires AuthenticationSelect this if the server requires authentication. The panel then shows the authentication fields.
Tools to IncludeAll to expose every tool the server advertises, or Selected to expose only some.
Available Tools (shown when Selected)Lists every tool the server advertises, with its description and a Read more link. Select the tools the agent can use. Select All and Deselect All change every tool at once.
Advanced Configurations > InfoThe client name and version sent to the server.
Advanced Configurations > HTTP VersionThe HTTP version the client uses to connect (HTTP/2_0 or HTTP/1_1).
Advanced Configurations > HTTP1 / HTTP2 SettingsProtocol tuning such as keep-alive, header sizes, and frame sizes.
Advanced Configurations > TimeoutPer-call timeout. Defaults to 30 seconds. Increase it for slow tools.
Advanced Configurations > ForwardedWhether to add Forwarded or X-Forwarded-For headers when the agent runs behind a proxy.
ResultThe variable name for the generated toolkit instance (for example, aiMcpbasetoolkit).

After you select Save, the toolkit appears on the canvas, connected to the AI Agent node by a dashed line. The agent's LLM sees the selected MCP tools the same way it sees any other tool.

Filtering tools​

When an MCP server exposes many tools, include only the ones the agent needs.

In the Edit MCP Server panel, set Tools to Include to Selected and select the tools the agent can use. The panel queries the server and lists every tool it advertises under Available Tools, with a Select All / Deselect All shortcut and a running count (for example, "1 of 3 selected").

The Edit MCP Server panel with Tools to Include set to Selected, showing the Available Tools list (1 of 3 selected) with getTextStatistics checked and getReadabilityScore and analyzeStructure unchecked, each with a Read more link. On the canvas, aiMcpbasetoolkit connects to the AI Agent node with a dashed line.The Edit MCP Server panel with Tools to Include set to Selected, showing the Available Tools list (1 of 3 selected) with getTextStatistics checked and getReadabilityScore and analyzeStructure unchecked, each with a Read more link. On the canvas, aiMcpbasetoolkit connects to the AI Agent node with a dashed line.

Why it matters:

  • Tool selection accuracy. LLMs choose better with fewer options.
  • Prompt size. Every tool's name, description, and parameter schema is sent on every call. Filtering trims the prompt.
  • Cost. Smaller prompts cost less.
  • Security. Don't give the agent tools that change data unless you designed for it.

Combining MCP servers, local tools, and toolkits​

The agent's tools array accepts any combination of:

  • Function tools marked @ai:AgentTool.
  • Custom toolkit classes (your own *ai:BaseToolKit implementations).
  • ai:McpToolKit instances for one or more remote MCP servers.
final ai:McpToolKit slackMcp = check new ("http://localhost:9092/mcp");
final ai:McpToolKit calendarMcp = check new ("http://localhost:9093/mcp");

final ai:Agent supportAgent = check new (
systemPrompt = {
role: "Support Assistant",
instructions: "Use CRM tools for customer info, Slack for notifications, " +
"and Calendar for scheduling follow-ups."
},
tools = [
getCustomerDetails, // local function tool
createSupportTicket, // local function tool
slackMcp, // MCP toolkit
calendarMcp // another MCP toolkit
],
model = check ai:getDefaultModelProvider()
);

Local tools and MCP tools are completely interchangeable from the agent's perspective. The LLM sees one unified tool list.

Production tips​

  • Make endpoints configurable. Hard-coding MCP URLs makes environments harder to manage. Expose the URL as a configurable variable (listed under Configurations in the project sidebar) so it can be set per environment without changing source code.

  • Run MCP servers close to the agent. The agent waits for every MCP call before it responds, so network latency between the agent and the server adds directly to the response time users see.

  • Authenticate the connection. If the MCP server is yours, put authentication in front of it. If it's external, follow the vendor's authentication scheme. Most use OAuth or bearer tokens passed in headers.

  • Watch token costs. Every tool the toolkit advertises is included in every reasoning step's prompt. A 50-tool MCP server, unfiltered, is a real prompt-token cost.

What's next​