import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import { z } from 'zod'; const inventory: Readonly> = Object.freeze({ A001: 7, B002: 0 }); const server = new McpServer({ name: 'inventory-mcp-server', version: '0.1.0' }); server.registerTool('inventory_lookup', { title: 'Look up fixture inventory', description: 'Read stock for one local fixture SKU. A missing SKU returns status not_found and units null; zero units means the item exists but is out of stock.', inputSchema: z.object({ sku: z.string().regex(/^[A-Z][0-9]{3}$/).describe('One uppercase letter and three digits, for example A001.') }).strict(), outputSchema: z.object({ sku: z.string(), status: z.enum(['found', 'not_found']), units: z.number().int().nonnegative().nullable() }).strict(), annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false }, }, async ({ sku }) => { const found = Object.hasOwn(inventory, sku); const output = { sku, status: found ? 'found' as const : 'not_found' as const, units: found ? inventory[sku] : null }; return { content: [{ type: 'text', text: JSON.stringify(output) }], structuredContent: output }; }); // stdout belongs exclusively to JSON-RPC; this server has no application logging. await server.connect(new StdioServerTransport());