Guidelines for Complex MCP Tools Creation (Create / Update / Delete)
This guide outlines the standard procedure for creating a custom ABAP class and exposing it as a complex Model Context Protocol (MCP) Tool.
Step 1: Create the ABAP Class
Create a new ABAP class in the SAP backend. To function as an MCP Tool, this class must implement the following standard interfaces:
- /SKYBFR/IF_YAI_AUTHORIZATION (Optional): Provides the ability to implement custom authorization logic via the
CHECK_AUTHORIZATION_INTmethod. Note: Standard SAP authorization checks are never skipped; this is for additional, tool-specific checks. - /SKYBFR/IF_YAI_OPERATION (Mandatory): Provides the main method for executing your custom business logic via
RUN_OPERATION_INT. - /SKYBFR/IF_YAI_SCHEMA (Mandatory): Provides the method to define the tool’s input and output metadata via
/SKYBFR/IF_YAI_SCHEMA~GET_SCHEMA.
Step 2: Define MCP Tool Metadata
You must define the parameters your tool accepts and returns.
1. Implement the Schema Method: Implement the /SKYBFR/IF_YAI_SCHEMA~GET_SCHEMA method to map your input (et_input) and output (et_output) variables. Ensure you provide clear descriptions, as the LLM relies on these to understand how to use the tool.
ABAP:
METHOD /skybfr/if_yai_schema~get_schema.
et_input = VALUE #(
( name = ‘your_input_parameter’
type = ‘string’
description = ‘Description of what this input does and how it should be formatted.’ )
).
et_output = VALUE #(
( name = ‘your_output_parameter’
type = ‘string’
description = ‘Description of the result or value returned by this tool.’ )
).
ENDMETHOD.
2. Define the Corresponding Type: In the PROTECTED SECTION of your class, create a data structure that exactly matches the schema defined above. This structure will be used to hold the values during execution.
ABAP:
PROTECTED SECTION.
TYPES:
BEGIN OF gty_s_result,
“Input
your_input_parameter TYPE string,
“Output
your_output_parameter TYPE string,
END OF gty_s_result.
Step 3: Implement the Tool’s Logic
Implement your custom business logic inside the RUN_OPERATION_INT method. You must include the standard macro structure to seamlessly handle data mapping between SAP and the MCP Server.
1. Include Macros: At the top of your method implementation, include the following:
ABAP:
INCLUDE /skybfr/yai_skill_macros.
2. Handle Data Operations:
- Reading Input: To retrieve the input data passed by the MCP Tool call, use the macro:
get_memory - Returning Output: To pass your processed results back to the MCP Server, use the macro:
set_memory
Step 4: Register your ABAP-based MCP Tool
Once the class is active, it must be registered in the system so the MCP server can discover it.
- Execute transaction SM30.
- Maintain the table/view:
/SKYBFR/YAICMCPN - Add a new entry with the following details:
- Tool Name:
your_tool_name_in_snake_case(This is the name the LLM will see and call) - ABAP Class:
ZCL_YOUR_CUSTOM_CLASS(The class created in Step 1) - Tool Description:
A clear, concise description of what the tool accomplishes in the SAP system.
- Tool Name:
Step 5: Verify the Tool via API
Once registered, verify that your newly added tool is properly exposed by fetching it from the MCP Server. You can do this by executing the tools/list method via a cURL command:
Bash:
curl -X POST http://[YOUR_SERVER_PATH]/mcp \
-H “Content-Type: application/json” \
-H “Accept: application/json, text/event-stream” \
-H “Mcp-Session-Id: [YOUR_SESSION_ID]” \
-d ‘{
“jsonrpc”: “2.0”,
“id”: 2,
“method”: “tools/list”
}’
NOTE: Verify that your new tool name and schema appear in the JSON response.