Contact Us 1-800-596-4880

MCP Connector 1.1 - Examples

These are some examples of how to use existing APIs to build agents using MCP Connector.

Create an MCP Server and Tools

These examples show you the process of creating an MCP server within your Mule app and defining two distinct tools that the MCP server will expose: one for retrieving a dynamic list of approved vendors with their product categories, and another for initiating the creation of purchase orders with specified details.

These examples illustrate the concept of MCP tools as invocable Remote Procedure Calls (RPCs).

Create the MCP Server Configuration

This example demonstrates how to configure an MCP server within your Mule application using the Streamable HTTP transport. When acting as an MCP client, MuleSoft facilitates the creation of integrations and orchestrations where AI Agents are integrated as just another system in the workflow.

<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="b15f1eb5-468e-4170-8f59-62c9965e2a57" > <<1>>
	<http:listener-connection host="localhost" port="${https.port}" />
</http:listener-config>

<mcp:config name="MCP_Server" serverName="Mule MCP Server" serverVersion="1.0.0"> <<2>>
	<mcp:streamable-http-server-connection
        listenerConfig="HTTP_Listener_config"
        mcpEndpointPath="/mcp">
        <mcp:default-response-headers> <<3>>
            <mcp:default-response-header key="X-API-Version" value="1.0.0"/>
            <mcp:default-response-header key="X-Server-ID" value="${server.id}"/>
        </mcp:default-response-headers>
    </mcp:streamable-http-server-connection>
</mcp:config>

<configuration-properties file="mule-artifact.properties"/>

<flow name="mcp-connectorFlow" doc:id="a8cbbf9b-dfe7-4519-97e3-c832f8815267" >
    <http:listener doc:name="Listener" doc:id="53fb94b1-cbd6-4e5a-9bf7-d33e02284bb7" config-ref="HTTP_Listener_config" path="/path"/>
</flow> <<4>>
xml
1 The HTTP listener configuration defines the endpoint where the MCP server is exposed.
2 The MCP server configuration uses the Streamable HTTP transport.
3 Headers are added to all responses for version tracking and server identification.
4 Property placeholders are used for configuration values to support different environments.

Create a Tool That Provides a List of Vendors

This example illustrates how to create an MCP tool that retrieves a dynamic list of approved vendors from an external system (in this case, SAP Concur). The example demonstrates how to use the <mcp:tool-listener> to define a callable tool and how to process the data to provide the agent with relevant vendor information, including their assigned product category from the Custom19 field.

First, set up the SAP Concur configuration with retry and timeout settings:

<sap-concur:config name="SAP_Concur_Config"> <<1>>
	<sap-concur:oauth-connection clientId="${concur.client.id}" clientSecret="${concur.client.secret}">
		<oauth:token-manager-config tokenUrl="${concur.token.url}"/>
	</sap-concur:oauth-connection>
	<reconnection> <<2>>
		<reconnect-forever frequency="5000"/>
	</reconnection>
	<request-timeout>30</request-timeout> <<3>>
	<request-timeout-unit>SECONDS</request-timeout-unit>
</sap-concur:config>

<!-- Cache configuration for vendor data -->
<ee:cache-config name="Vendor_Cache_Config"> <<4>>
	<ee:cache-ttl>3600000</ee:cache-ttl>
	<ee:cache-ttl-unit>MILLISECONDS</ee:cache-ttl-unit>
</ee:cache-config>
xml
1 The SAP Concur configuration includes OAuth authentication settings.
2 A reconnection strategy is configured to handle temporary connection issues.
3 Request timeout is set to 30 seconds to prevent hanging requests.
4 A cache configuration is added to improve performance with a one hour TTL.

Now, create the main flow that handles vendor retrieval with pagination and caching:

1 The <mcp:tool-listener> defines the interface for the vendor retrieval tool with pagination support.
2 The <mcp:parameters-schema> schema includes validation for page size and page number.
3 The cache component improves performance by storing results for 1 hour.
4 The DataWeave transformation filters approved vendors and adds pagination metadata.
5 Error handling covers connectivity, authentication, and unexpected errors.

Create a Tool That Creates Purchase Orders

This example demonstrates the creation of an MCP tool that allows an agent to initiate the creation of a purchase order in SAP Concur. The example highlights how to define input parameters for a tool using a JSON schema, including natural language descriptions for each parameter to help the LLM in understanding and populating the required information.

1 The tool listener defines the purchase order creation interface with comprehensive input validation.
2 The parameters schema includes validation rules for all fields, including length limits and patterns.
3 A vendor existence check is performed before creating the purchase order.
4 The DataWeave transformation validates the vendor check response.
5 Error handling covers connectivity, authentication, validation, and unexpected errors.

Configure the MCP Client to Use Third-Party MCP Servers

The previous examples showed you how to write tools that draw from existing Anypoint Connectors. Now, take a look at how to use third-party MCP servers.

Create a Weather Service Using Multiple MCP Servers

This example shows how to integrate your Mule applications with existing third-party MCP servers using Streamable HTTP transport by configuring the MCP Client and using the Call Tool operation.

When connecting to third-party MCP servers, ensure they support Streamable HTTP transport. If a third-party server only supports SSE transport, you may need to use the SSE client connection or contact the service provider for Streamable HTTP support.

First, set up the client configurations with timeout and retry settings:

1 The HTTP request configuration includes timeout and retry settings for the weather API.
2 The Google Maps MCP client configuration uses Streamable HTTP transport with custom headers and reconnection settings.
3 The Weather MCP server configuration uses Streamable HTTP transport and exposes the weather service endpoints with custom headers.

Now, create the weather service flows with error handling and caching:

1 The cache configuration stores weather data for 15 minutes to reduce API calls.
2 The coordinates-based weather flow includes input validation and caching.
3 The address-based weather flow demonstrates tool composition by:
  • First converting the address to coordinates using Google Maps

  • Then using those coordinates to get the weather

4 Both flows include comprehensive error handling for different scenarios.
5 The DataWeave transformation validates the Google Maps response before proceeding.

While LLMs can orchestrate these tools directly, there are cases where manual composition in Mule is preferable:

  • When you need guaranteed access to all MCP servers

  • When authentication needs to be handled securely

  • When you need strong governance and tracing capabilities

View on GitHub