Create the Apex Invocable Action

Your widget displays data from an object in your org, such as a HotelInfo custom object. While there are multiple ways to get the data, a standard approach is to create an Apex class that contains a SOQL query for the HotelInfo object. The Apex class returns the results in the shape of one of your custom Lightning types schema. You later use this Apex class to create an MCP tool in your custom MCP server.

  1. In your local DX project, create the Apex class that queries your org and returns output shaped to the schema of one of your custom Lightning types. Remember, for channels that support MCP, you must create two custom Lightning types: one for the MCP result wrapper role and one for the MCP payload role.

    Make sure your Apex code meets the requirements for an Apex invocable action. For example, the Apex class must be global and the method that returns results must be annotated with @InvocableMethod. See these links for full details:

  2. Deploy your Apex class to your org. For example, to use a Salesforce CLI command to deploy to the org with alias my-org, run this command:

Your Apex invocable action is ready to become an MCP tool. See Create a Custom MCP Server.