Skip to content

Instantly share code, notes, and snippets.

@cdbkr
Created December 11, 2025 15:05
Show Gist options
  • Select an option

  • Save cdbkr/cf304268a30e6bb8c4cce8f7b2b8cdcb to your computer and use it in GitHub Desktop.

Select an option

Save cdbkr/cf304268a30e6bb8c4cce8f7b2b8cdcb to your computer and use it in GitHub Desktop.
createResourceTool function
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