Skip to main content
Glama

Nexar MCP Server

by phuhduong
nexar.ts2.62 kB
/** * Nexar tool definitions and handlers */ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import { z } from 'zod'; import { NexarClient } from '../client.js'; import { SearchComponentsArgs } from '../types.js'; /** * Create and register Nexar tools */ export function registerNexarTools(server: McpServer, nexarClient: NexarClient): void { console.log('Registering Nexar MCP tools...'); // Register tools/list handler server.server.setRequestHandler( z.object({ method: z.literal('tools/list'), }), async () => { return { tools: [ { name: 'search_components', description: 'Search for electronic components using the Nexar Supply API. Returns a list of compatible components with specifications, pricing, and availability.', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query describing the component needed (e.g., "ESP32 microcontroller with WiFi", "3.3V LDO regulator 600mA")', }, limit: { type: 'number', description: 'Maximum number of results to return', default: 10, }, }, required: ['query'], }, }, ], }; } ); console.log('Tools registered: search_components'); // Register tools/call handler server.server.setRequestHandler( z.object({ method: z.literal('tools/call'), params: z.object({ name: z.string(), arguments: z.any(), }), }), async (request) => { const { name, arguments: args } = request.params; if (name === 'search_components') { const { query, limit = 10 } = args as SearchComponentsArgs; if (!query || typeof query !== 'string') { throw new Error('query parameter is required and must be a string'); } try { const components = await nexarClient.searchComponents(query, limit); return { content: [ { type: 'text', text: JSON.stringify(components, null, 2), }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Failed to search components: ${errorMessage}`); } } throw new Error(`Unknown tool: ${name}`); } ); }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/phuhduong/nexar-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server