Skip to main content

Build a Customer Care Agent with MCP

What you'll build

A customer care agent that connects to a ShopEasy MCP server and answers product availability, order status, and return questions over a chat API.

This tutorial shows how to build an agent that consumes an external MCP server using ai:McpToolKit. You do not build the MCP server here. It is provided as a running service. Your job is to wire the agent to it, write the system prompt, and expose a chat endpoint.

The agent receives customer messages over HTTP, reasons about which tool to call, invokes the MCP server, and returns a natural language answer.

Prerequisites

Step 1: Create the agent

  1. Open WSO2 Integrator and create or select your project.
  2. Select Add Artifact.
  3. Under AI Integration, select AI Chat Agent.
  4. Set the Name to Customer Care Agent and select Create.
The Add Artifact panel with AI Chat Agent selected under the AI Integration sectionThe Add Artifact panel with AI Chat Agent selected under the AI Integration section

The visual designer opens with the agent flow: a Start node, an AI Agent node, and a Return node.

Step 2: Configure the agent

2.1 Open the agent configuration

Select the AI Agent node to open the configuration panel on the right.

The AI Chat Agent visual designer showing the agent flow with Start, AI Agent, and Return nodesThe AI Chat Agent visual designer showing the agent flow with Start, AI Agent, and Return nodes

2.2 Write the system prompt

  1. Set the Role to Customer Support Agent.
  2. Paste the following into Instructions:
You are a helpful customer support agent for ShopEasy, an online retailer.
Help customers with product availability, order tracking, and return requests.
Always use the available tools to look up accurate information — never guess.
Keep responses friendly and concise. Include relevant IDs (order ID, return ID) in your responses.
The agent configuration panel showing the Role and Instructions fields filled inThe agent configuration panel showing the Role and Instructions fields filled in

2.3 Set advanced configurations

  1. Expand Advanced Configurations.
  2. Set Maximum Iterations to 10.
  3. Select Save.
The advanced configuration panel showing Maximum Iterations set to 10The advanced configuration panel showing Maximum Iterations set to 10
Why set Maximum Iterations to 10?

The default is based on the number of toolkit objects, not individual tools. With one MCP toolkit wrapping three tools, the default is 2, which is too low for multi-step queries. Setting it to 10 gives the agent enough room to reason, call a tool, and respond.

Step 3: Add the MCP server as a tool

3.1 Select the tool type

  1. Select + on the AI Agent node.
  2. Select Use MCP Server.
The Add Tool panel with Use MCP Server highlightedThe Add Tool panel with Use MCP Server highlighted

3.2 Configure the server URL

  1. Set Server URL to http://localhost:8080/mcp.
  2. Leave Requires Authentication off.
  3. Select Save.
The Add MCP Server panel with the server URL set to http://localhost:8080/mcpThe Add MCP Server panel with the server URL set to http://localhost:8080/mcp

The MCP toolkit appears as aiMcpbasetoolkit attached to the agent node in the visual designer. The agent will discover the available tools from the server at startup.

The completed agent flow showing the AI Agent node connected to the aiMcpbasetoolkitThe completed agent flow showing the AI Agent node connected to the aiMcpbasetoolkit

Step 4: Run and test

Make sure the ShopEasy MCP server is running, then click the Play button in the top-right corner of the WSO2 Integrator IDE to start the agent.

Once the agent is running, click Chat in the toolbar (next to Tracing: Off) to open the built-in chat panel. Type your message in the input field and press Enter to send it.

Try the following messages to exercise all three tools:

  • "Do you have any wireless headphones in stock?"
  • "What is the status of my order ORD-042?"
  • "I want to return ORD-001. The item arrived damaged."
The agent running in the WSO2 Integrator IDE with the MCP toolkit connected and the Ballerina Debug indicator activeThe agent running in the WSO2 Integrator IDE with the MCP toolkit connected and the Ballerina Debug indicator active

For more detail on using the chat panel, see Try-It experiences.

What you built

  • Connected an agent to a live MCP server using ai:McpToolKit
  • The agent dynamically discovered three tools (searchProducts, getOrderStatus, submitReturnRequest) at startup with no hardcoded tool definitions
  • Exposed the agent as an HTTP chat service with session-scoped memory

What's next