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.
-
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
globaland the method that returns results must be annotated with@InvocableMethod. See these links for full details:- Connect Your Widget to a Custom Lightning Type for details about the two required custom Lightning types.
- Apex Actions
-
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.
- Salesforce Dev Blog: Expose Custom Apex as a Hosted MCP Tool for Agents
- Trailhead: Agent Customization with Apex
- Apex Developer Guide
- Apex @InvocableMethod Annotation
- Apex Actions
- Custom Lightning Types
- Salesforce CLI Command Reference: project Commands