mirror of
https://github.com/ArthurDanjou/artapi.git
synced 2026-01-14 16:44:23 +01:00
feat: ajouter un outil pour lire des ressources depuis l'API serveur
This commit is contained in:
39
server/mcp/tools/read-resource.ts
Normal file
39
server/mcp/tools/read-resource.ts
Normal file
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user