SuiteScript 2.1 Custom Tool Script Type Code Samples

This sample consists of the three requirements for building a custom tool: a custom tool script, a JSON file for the schema, and the SDF object file. The custom tool script defines two tool methods: add() and reverseText(). The add() tool method takes two parameters and returns their sum. The reverseText() method takes a string and returns the reversed string. Together, these files show how to structure your custom tool before deployment to your NetSuite account.

You can find sample tool implementations in the MCP-Sample-Tools directory of the SuiteCloud Project Repository on Oracle Samples GitHub. This project includes SuiteScript-based sample tools for performing common business tasks through conversational AI. These examples demonstrate the types of AI-powered solutions that you can build and deploy in your own NetSuite account.

NetSuite also provides the MCP Standard Tools SuiteApp, which is available in the SuiteApp Marketplace. For more information, see MCP Standard Tools SuiteApp.

Implementation of Custom Tools That Adds Numbers and Reverses a String

The following sample is a custom tool script that implements two tools: one for adding two numbers, and another for reversing a string.

Note:

This script sample uses the define function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript 2.x Global Objects.

Important:

This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.

            /**
 * exampletools.jsc
 * @NApiVersion 2.1
 * @NModuleScope Public
 */

define([], function() {
    return {
        add: function (args) {
            try {
                const a = args["a"];
                const b = args["b"];
                return {
                    result: a+b
                };
            } catch(e) {
                return {
                    result: "",
                    error: "There was an error executin the tool: " + e
                }
            }
        },
        reverseText: function (args) {
            try {
                const text = args["text"];
                return {
                    result: text.split('').reverse().join('')
                };
            } catch(e) {
                return {
                    result: "",
                    error: "There was an error executin the tool: " + e
                }
            }
        }
    }
}); 

          

Custom Tool Definition Schema

The following sample is the JSON schema definition for the custom tools defined in the script. For more information about the properties of the JSON schema, see Custom Tool JSON Schema.

            {
    {
    "tools": [
        {
            "name": "add",
            "description": "Add two numbers together",
            "inputSchema": {
                "type": "object",
                "properties": {
                    "a": { "type": "number", "description": "First addend" },
                    "b": { "type": "number", "description": "Second addend" }
                },
                "required": ["a", "b"]
            },
            "outputSchema": {
                "type": "object",
                "properties": {
                    "result": {
                        "type": "number",
                        "description": "Value of adding the two input numbers"
                    },
                    "error": {
                        "type": "string",
                        "description": "Error message if execution fails"
                    }
                },
                "required": ["result"]
            },
            "annotations": {
                "title": "Add Numbers",
                "readOnlyHint": true,
                "idempotentHint": true,
                "openWorldHint": false
            }
        },
        {
            "name": "reverseText",
            "description": "Reverses a given text string. Example: if the user says 'Reverse the text: I like apples', call this tool with { \"text\": \"I like apples\" }. ",
            "inputSchema": {
                "type": "object",
                "properties": {
                    "text": { "type": "string", "description": "Text to reverse" }
                },
                "required": ["text"]
            },
            "outputSchema": {
                "type": "object",
                "properties": {
                    "result": {
                        "type": "string",
                        "description": "Value of reversing the input text value"
                    },
                    "error": {
                        "type": "string",
                        "description": "Error message if execution fails"
                    }
                },
                "required": ["result"]
            },
            "annotations": {
                "title": "Reverse Text",
                "readOnlyHint": true,
                "idempotentHint": true,
                "openWorldHint": false
            }
        }
    ]
} 

          

The following sample is the JSON schema definition for the custom tools defined in the script without using outputSchema.

            {
    "tools": [
        {
            "name": "add",
            "description": "Add two numbers together",
            "inputSchema": {
                "type": "object",
                "properties": {
                    "a": { "type": "number", "description": "First addend" },
                    "b": { "type": "number", "description": "Second addend" }
                },
                "required": ["a", "b"]
            },
            "annotations": {
                "title": "Add Numbers",
                "readOnlyHint": true,
                "idempotentHint": true,
                "openWorldHint": false
            }
        },
        {
            "name": "reverseText",
            "description": "Reverses a given text string. Example: if the user says 'Reverse the text: I like apples', call this tool with { \"text\": \"I like apples\" }. ",
            "inputSchema": {
                "type": "object",
                "properties": {
                    "text": { "type": "string", "description": "Text to reverse" }
                },
                "required": ["text"]
            },
            "annotations": {
                "title": "Reverse Text",
                "readOnlyHint": true,
                "idempotentHint": true,
                "openWorldHint": false
            }
        }
    ]
} 

          

If you are using ChatGPT, defining which schema properties are nullable is required. The following sample is the JSON schema definition for the custom tools when using ChatGPT.

            {
    "tools": [
        {
            "name": "add",
            "description": "Add two numbers together",
            "inputSchema": {
                "type": "object",
                "properties": {
                    "a": { "type": "number", "description": "First addend" },
                    "b": { "type": "number", "description": "Second addend" }
                },
                "required": ["a", "b"],
                "nullable": []
            },
            "outputSchema": {
                "type": "object",
                "properties": {
                    "result": {
                        "type": "number",
                        "description": "Value of adding the two input numbers"
                    },
                    "error": {
                        "type": "string",
                        "description": "Error message if execution fails"
                    }
                },
                "required": ["result"],
                "nullable": ["error"]
            },
            "annotations": {
                "title": "Add Numbers",
                "readOnlyHint": true,
                "idempotentHint": true,
                "openWorldHint": false
            }
        },
        {
            "name": "reverseText",
            "description": "Reverses a given text string. Example: if the user says 'Reverse the text: I like apples', call this tool with { \"text\": \"I like apples\" }. ",
            "inputSchema": {
                "type": "object",
                "properties": {
                    "text": { "type": "string", "description": "Text to reverse" }
                },
                "required": ["text"]
            },
            "outputSchema": {
                "type": "object",
                "properties": {
                    "result": {
                        "type": "string",
                        "description": "Value of reversing the input text value"
                    },
                    "error": {
                        "type": "string",
                        "description": "Error message if execution fails"
                    }
                },
                "required": ["result"],
                "nullable": ["error"]
            },
            "annotations": {
                "title": "Reverse Text",
                "readOnlyHint": true,
                "idempotentHint": true,
                "openWorldHint": false
            }
        }
    ]
} 

          

Custom Tool SDF XML Object

The following sample is the SDF XML definition for the custom tool. Custom tools are defined as a tool SDF custom object in SDF. For more information, see Custom Tool Scripts as XML Definitions.

            <tool scriptid="customtool_test1">
  <name>Test Agent Tool 1</name>
  <scriptfile>[/SuiteApps/com.netsuite.tools/tools/scriptfile.js]</scriptfile>
  <rpcschema>[/SuiteApps/com.netsuite.tools/tools/scriptfile_schema.json]</rpcschema>
  <exposeto3rdpartyagents>T</exposeto3rdpartyagents>
  <permissions>
    <permission>
            <permkey>LIST_EMAILTEMPLATE</permkey>
            <permlevel>FULL</permlevel>
    </permission>
    <permission>
            <permkey>ADMI_CRMLIST</permkey>
            <permlevel>VIEW</permlevel>
    </permission>
  </permissions>
</tool> 

          

General Notices