From 606cd218bf23cb3ba8eec062100104d6223d4c55 Mon Sep 17 00:00:00 2001 From: Arthur DANJOU Date: Fri, 19 Dec 2025 12:13:47 +0100 Subject: [PATCH] feat: ajouter un outil pour lire des ressources depuis l'API serveur --- server/mcp/tools/read-resource.ts | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 server/mcp/tools/read-resource.ts diff --git a/server/mcp/tools/read-resource.ts b/server/mcp/tools/read-resource.ts new file mode 100644 index 0000000..bd4896d --- /dev/null +++ b/server/mcp/tools/read-resource.ts @@ -0,0 +1,39 @@ +import { z } from 'zod' + +export default defineMcpTool({ + description: 'Read a resource from the server API', + inputSchema: { + resource: z.enum([ + 'contact', + 'education', + 'experiences', + 'hobbies', + 'languages', + 'profile', + 'projects', + 'skills', + 'uses' + ]).describe('resource name') + }, + handler: async ({ resource }) => { + try { + const data = await $fetch(`/api/${resource}`) + + return { + content: [{ + type: 'text', + text: JSON.stringify(data, null, 2) + }] + } + } + catch (error) { + return { + content: [{ + type: 'text', + text: `Error: ${error instanceof Error ? error.message : String(error)}` + }], + isError: true + } + } + } +})