getUserInfo
Retrieve user details by providing a userId through an API call. Simplifies user data access for efficient integration and management within the MCP Tool Starter Kit environment.
Instructions
Fetches user information from an API
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| userId | Yes |
Implementation Reference
- src/tools/example.tool.ts:24-38 (handler)The main handler function for the getUserInfo tool. Processes input, fetches user data with fetchUser, returns MCP-formatted response or error.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, } } }
- src/tools/example.tool.ts:11-21 (schema)Tool definition including name, description, and input schema requiring a 'userId' string.export const getUserInfoTool: Tool = { name: 'getUserInfo', description: 'Fetches user information from an API', inputSchema: { type: 'object', properties: { userId: { type: 'string' }, }, required: ['userId'], }, }
- src/server.ts:41-43 (registration)Registers getUserInfoTool in the ListTools response.return { tools: [getUserInfoTool], }
- src/server.ts:53-55 (registration)Dispatch logic in CallToolRequest handler that calls getUserInfoHandler for matching tool name.if (request.params.name === getUserInfoTool.name) { return getUserInfoHandler(request.params.arguments) }
- src/tools/example.tool.ts:4-9 (helper)Mock helper function to fetch user information by ID.async function fetchUser(userId: string) { if (userId === '1') { return { id: '1', name: 'John Doe' } } throw new Error('User not found') }