import type { Tool } from '@modelcontextprotocol/sdk/types.js'
// This is a mock handler function. In a real scenario, this would fetch from a real API.
async function fetchUser(userId: string) {
if (userId === '1') {
return { id: '1', name: 'John Doe' }
}
throw new Error('User not found')
}
export const getUserInfoTool: Tool = {
name: 'getUserInfo',
description: 'Fetches user information from an API',
inputSchema: {
type: 'object',
properties: {
userId: { type: 'string' },
},
required: ['userId'],
},
}
// We export the handler separately to be used in the main server setup.
export async function getUserInfoHandler(input: unknown) {
const args = input as { userId: string }
try {
const user = await fetchUser(args.userId)
return {
content: [{ type: 'text', text: JSON.stringify(user) }],
}
}
catch (error) {
return {
content: [{ type: 'text', text: (error as Error).message }],
isError: true,
}
}
}