Skip to main content

Consuming MCP from an Agent

An AI Agent in WSO2 Integrator can use any MCP server as a tool source. Add the server once; 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, click + Add Tool → Use MCP Server. The Add Tool - Use MCP Server panel opens:

The Add Tool - Use MCP Server panel showing Server URL (http://localhost:8080/mcp), a Requires Authentication checkbox, Tools to Include set to Selected, and the Available Tools list (3 of 3 selected: getTextStatistics, getReadabilityScore, analyzeStructure, each with a Read more link), a collapsed Advanced Configurations section, and Result (default aiMcpbasetoolkit).The Add Tool - Use MCP Server panel showing Server URL (http://localhost:8080/mcp), a Requires Authentication checkbox, Tools to Include set to Selected, and the Available Tools list (3 of 3 selected: getTextStatistics, getReadabilityScore, analyzeStructure, each with a Read more link), a collapsed Advanced Configurations section, and Result (default aiMcpbasetoolkit).
FieldWhat it does
Server URLThe MCP endpoint, for example http://localhost:8080/mcp.
Requires AuthenticationEnable if the server requires authentication, to reveal the auth configuration 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. Check the ones the agent should have access to; Select All / Deselect All toggles everything at once.
Advanced Configurations → Info → name/versionThe MCP client identifier and version sent to the server.
Advanced Configurations → HTTP VersionHTTP/2_0 for modern Streamable HTTP servers; HTTP/1_1 for older ones.
Advanced Configurations → HTTP1 / HTTP2 SettingsProtocol tuning such as keep-alive, header sizes, and frame sizes.
Advanced Configurations → TimeoutPer-call timeout. Default 30 s; increase for slow tools.
Advanced Configurations → ForwardedWhether to send Forwarded / X-Forwarded-For when sitting behind a proxy.
ResultThe variable name for the generated toolkit instance (for example, aiMcpbasetoolkit).

After Save, every selected tool from the MCP server appears in the agent's tool list. They are indistinguishable to the agent's LLM from any other tool.

Filtering tools​

When an MCP server exposes many tools, do not pull them all in. Pick the few you actually want.

In the Edit MCP Server panel, set Tools to Include to Selected and check the tools the agent should have access to. 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.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.

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 expose the agent to mutation tools you didn't design for.

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​

  • configurable for endpoints. Hard-coding MCP URLs makes environments harder to manage. Expose the URL as a configurable variable so it can be set per environment without changing source code.

  • Run MCP servers close to the agent. MCP calls are on the agent's hot path. Network latency between agent and server directly increases user-perceived response time.

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

  • Watch token bills. 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​