Files
artapi/server/mcp/tools/read-resource.ts

40 lines
792 B
TypeScript

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
}
}
}
})