Created
December 11, 2025 15:05
-
-
Save cdbkr/cf304268a30e6bb8c4cce8f7b2b8cdcb to your computer and use it in GitHub Desktop.
createResourceTool function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const createResourceTool = (resource, endpoints, baseUrl) => { | |
| const operations = endpoints.map(endpoint => endpoint.id); | |
| return { | |
| name: `${resource}_operations`, | |
| description: buildToolDescription(resource, endpoints, operations), | |
| parameters: z.object({ | |
| operation: z.enum(operations), | |
| parameters: z.record(z.any()).optional(), | |
| body: z.record(z.any()).optional(), | |
| }), | |
| execute: async ({ operation, parameters, body }) => { | |
| const endpoint = endpoints.find(endpoint => endpoint.id === operation); | |
| const result = await callApi(baseUrl, endpoint, parameters, body); | |
| return JSON.stringify(result, null, 2); | |
| }, | |
| }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment