get_resource_action_snippet
Generate code snippets to execute resource actions in multiple programming languages. Simplify API integrations by providing ready-to-use code for JavaScript, Python, Java, and more.
Instructions
Generate a code snippet to perform a resource action in the specified language. For example, a JavaScript snippet to call the action with the required parameters.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | ||
| language | Yes | ||
| resource | Yes |
Implementation Reference
- The primary handler function for the 'get_resource_action_snippet' tool. It resolves the topic from the resource name, validates the resource and action existence, and delegates to the topic's getResourceActionSnippet method to generate the code snippet.export const getResourceActionSnippetHandler = async ( toolArgs: GetSnippetToolArgs ): Promise<CallToolResult> => { const { resource, action } = toolArgs; const topicKey = resource.split('_')[0]; const foundResource = TOPIC_KEY_MAP[topicKey] || TOPIC_KEY_MAP[resource]; /** * Check if the resource exists */ if ( !foundResource || !(await foundResource.getResources()).has(resource) || !(await foundResource.hasResourceAction(resource, action!)) ) { return McpResponse( JSON.stringify({ error: `Unknown or missing resource '${resource}' or action '${action}'.` }) ); } /** * List actions for the resource */ return foundResource.getResourceActionSnippet(toolArgs); };
- src/handlers/tools_list.ts:78-101 (schema)JSON input schema definition for the tool, provided in the tools list response. Specifies required parameters: resource, action, language.const listResourceActionSnippet: Tool = { name: GET_RESOURCE_ACTION_SNIPPET_TOOL, description: 'Generate a code snippet to perform a resource action in the specified language (optional tool for developers). Shows how to call the action with the required parameters. Useful for integrating Seitrace API calls into your own applications.', inputSchema: { type: 'object', properties: { resource: { type: 'string' }, action: { type: 'string' }, language: { type: 'string' }, payload: { type: 'object', additionalProperties: true, description: 'Optional example payload for snippet generation (e.g., rpc_method, params, endpoint).', }, }, required: ['resource', 'action', 'language'], additionalProperties: false, description: `Provide resource, action, and target language. Supported languages: ${SUPPORTED_SNIPPET_LANGUAGES.join( ', ' )}`, }, };
- src/handlers/index.ts:16-22 (registration)Registers the getResourceActionSnippetHandler under the tool name GET_RESOURCE_ACTION_SNIPPET_TOOL in the central handler map.export const handlerMap = { [LIST_RESOURCES_TOOL]: listResourcesHandler, [LIST_RESOURCE_ACTIONS_TOOL]: listResourceActionsHandler, [GET_RESOURCE_ACTION_SCHEMA_TOOL]: getResourceActionSchemaHandler, [GET_RESOURCE_ACTION_SNIPPET_TOOL]: getResourceActionSnippetHandler, [INVOKE_RESOURCE_ACTION_TOOL]: invokeResourceActionHandler, };
- src/topics/base.ts:7-12 (schema)TypeScript interface defining the input arguments for snippet tools, extending ToolArgs with optional language.export interface GetSnippetToolArgs extends ToolArgs { /** * The programming language to use for code snippets */ language?: string; }
- src/constants.ts:23-23 (registration)Defines the constant string name for the tool.export const GET_RESOURCE_ACTION_SNIPPET_TOOL = 'get_resource_action_snippet';