Reading Time: 14 minutes

Grounding AI agents with real-time, accurate enterprise data is crucial. This is achieved through Model Context Protocol (MCP), the open standard for secure, reliable agent-to-tool communication. But does this mean that you need to completely change your enterprise architecture to build new MCP servers?

As a MuleSoft customer, you already possess a robust library of existing APIs that connect to your core systems. The most efficient and secure path to becoming an agent-ready enterprise is by adapting the existing APIs to the MCP standard, rather than undertaking the time-consuming and risk-prone effort of creating net new MCP servers from scratch. In addition, by leveraging existing APIs, you can capitalize on your current security measures, governance framework, and established connectivity. 

We’ll walk through how you can transform your API into an MCP server that AI agents can use.

Why make APIs agent-ready as MCP servers? 

Making your existing APIs agent-ready for Model Context Protocol (MCP) servers is the fastest way to bring AI capabilities into your enterprise. You instantly accelerate your AI adoption by reusing established APIs and integrations, saving significant time on planning and development. Crucially, this setup provides AI agents with direct, real-time data access, ensuring they are context-aware and grounded in accurate, live information. 

When transforming APIs into MCP servers, best practice is to break down complex API endpoints into simpler tools that are perfect for agentic clients. This is because AI agents thrive with a reliable sequence of simple, predictable steps. This strategic simplification focuses the agent’s actions on what is straightforward, repeatable, and optimal for business processes, allowing them to execute reliable tasks at enterprise scale. 

Why use MuleSoft?

MuleSoft is the ideal platform for transforming APIs into MCP servers. It provides a unified, enterprise platform that maximizes your existing API investments. Because MuleSoft customers already utilize API-led architecture, they can use existing Process and Experience APIs as powerful MCP servers. This lets agents immediately leverage business process led integrations without needing to call individual systems directly. 

The MuleSoft Connector for MCP quickly makes your Mule apps and APIs agent-ready, instantly connecting them to AI agents like Agentforce, Claude, and more. You can host both MCP servers, surfacing legacy systems to agents, and MCP clients, orchestrating agents within workflows. This eliminates the need for custom hosting environments and instead, take advantage of the platform you’ve been using for integrations and APIs. 

Furthermore, MuleSoft ensures governance and scale with Flex Gateway support for MCP. Flex Gateway applies enterprise-grade security and logging to every agent interaction. And with MuleSoft Agent Fabric, you can discover, orchestrate, and observe your entire agent network. With all these innovations, MuleSoft is the secure foundation for embedding AI into your business ecosystem.

Now that we’ve talked about the importance of using existing APIs to create MCP servers, let’s get started. 

Step-by-step guide

To follow along with this guide, you’ll need:

We’ a’re going to create a simple MCP server that gets information about a pet based on its ID through a sample API called Swagger Petstore.

Study the API

Before we start building out the MCP server, we first need to get familiar with what the API offers. Swagger Petstore has many endpoints. For this guide, we will focus on /pet/{petId}. petId is the input parameter that we need from the user to get the information for the pet.

Alt: Image of /pet/{petId}

Implement the Flow

In ACB, we need to first create a new integration project. 

  • Open Visual Studio Code and click on the MuleSoft Logo in the left sidebar
  • Click on Develop an Integration
  • Place a project name such as swagger-petstore-mcp-server
  • Click on Create Project
    Alt: an image of creating a new integration project
    1. Open swagger-petstore-mcp-server.xml (path: [project folder]/src/main/mule)
    2. Click on Create an MCP Server
    Alt: Create an MCP server page

    Once done, you will see a Mule flow with MCP connector already added as a listener for a tool. Each project can have multiple Mule flows which can translate to having multiple MCP tools within your MCP server. We will create an MCP server with 1 MCP tool. 

    Alt: A Mule flow with MCP connector

    With the project created, let’s configure the MCP listener connection. 

    1. Click on the + (Add New Connection) button under Connection Config section
    Alt: Add a new connection configuration
    1. Under connection, choose streamable http server
    2. Click + under Listener config to create a new HTTP connection configuration
    Alt: MCP Connector Listener Configuration
    1. For Host, put in 0.0.0.0 and for Port, put in 8081
    2. Click Add 
    Alt: http listener configuration
    1. Back in MCP – Tool Listener Configuration, fill out:
      1. Listener-Config set to the new HTTP Configuration
      2. Server Name: petstore-mcp-server
      3. Server Version: 1.0.0
    2. Click Add
    Alt: Finishing out MCP - Tool Listener

    With the connection created, now we need to configure the MCP – Tool Listener connector itself with the following information: 

    • Name: get-pet-by-id
    • Description: Returns a single pet at Swagger Pet Store based on the ID provided by the user
    • Parameter Schema: 
    {
                    "$schema": "http://json-schema.org/draft-07/schema#",
                    "type": "object",
                    "properties": {
                        "petID": { "type": "string", "description": "Pet ID" }
                    },
                    "required": ["petId"]
                }

    Parameter Schema defines the 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. In this case, we are requiring the user to input in a petID. 

    Alt: MCP Tool Listener Connector Configuration - inputting name, description, and parameter schema
    • Responses: click + Add and in Text, place #[payload.^raw]
    Alt: MCP Tool Listener Connector Configuration - inputting responses

    Now that the set up for the listener is done, we need to connect to the Petstore API. 

    1. Click on + button below the listener in the flow
    Alt: adding a new step under the MCP listener
    1. Search HTTP and choose Request under the HTTP Connector 
    Alt: choosing HTTP request component
    1. Create a new connection configuration for HTTP request (click on + next to configuration)
      1. Choose Request under Connection
      2. Protocol: HTTPS
      3. Host: petstore.swagger.io
      4. Port: 443
      5. Base Path: /v2/pet/
    2. Leave everything else as default and click Add
    Alt: HTTP request configuration
    1. Click on fx button next to path 
    2. Put in payload.petID. Using Dataweave, we are able to get the petID value from the listener. 
    Alt: Configuring HTTP request component with input parameters

    With the MCP server built out, let’s deploy the app to CloudHub 2.0.

    Deploy

    To deploy the application, follow these steps: 

    1. Click on the rocket button on the top right. 
    2. Choose CloudHub 2.0
    3. Deployment target of your choice. I chose Cloudhub-US-West-2 since that’s closest to me
    4. Choose sandbox for the environment
    5. When deploy_ch2.json file opens, leave as default and click deploy under notifications. 
    Alt: Click on deploy under notifications after deploy_ch2.json file opens up
    1. Choose the latest runtime version 
    2. For application version, put in 1.0.0
    3. Once the build is successful, you can check the status of the deployment by clicking on Open in Runtime Manager under notifications. 
    Alt: Click on Open in Runtime Manager
    1. In Runtime Manager, find your application and check that it’s running. Make sure to grab the public endpoint url to test the MCP server. 

    Test out the MCP server in Postman

    To test out the MCP server, we will use the Postman Desktop since it’s widely available. You need to make sure you are using MCP as the protocol in Postman. 

    1. Choose HTTP and add the url. The url is: [public endpoint from Runtime Manager]/mcp
    2. Click Connect
    Alt: Testing the MCP server in Postman
    1. Click on get-pet-by-id and put in 101 as the ID
    2. Click on Run
    Alt: Testing the MCP server in Postman - Running the tool

    You should get a simple response back such as: 

    {
        "content": [
            {
                "type": "text",
    
                "text": "{\"id\":101,\"category\":{\"id\":1,\"name\":\"dogs\"},\"name\":\"Rex\",\"photoUrls\":[\"https://example.com/dog.png\"],\"tags\":[{\"id\":2,\"name\":\"pet\"}],\"status\":\"available\"}",
    
                "annotations": {
    
                    "audience": []
                }
            }
        ],
    
        "isError": false
    }

    On your way to success

    By following these steps, you can simply set up an MCP server with an existing API. With this as a starting point, you can go on with more advanced configurations and use all that Anypoint Code Builder has to offer to build your MCP servers with existing APIs. 

    What’s amazing is that you can bypass a lot of the configuration seen in this guide with the help of MuleSoft Vibes. With MuleSoft Vibes, you can use natural language to help you start building MCP servers. 

    Try out our interactive demo for some hands-on action. Lastly, do you have APIs you want to transform to MCP servers? Try it out with this guide as your starting point!