UNPKG

@sei-js/mcp-server

Version:

Model Context Protocol (MCP) server for interacting with EVM-compatible networks

54 lines (53 loc) 1.8 kB
import { z } from 'zod'; const DOCS_SEARCH_URL = 'https://docs.sei-apis.io/search'; export const createDocsSearchTool = async (server) => { server.tool('search_docs', 'Search the main Sei docs for general chain information, ecosystem providers, and user onboarding guides. Useful for all queries for up-to-date information about Sei.', { query: z.string() }, async ({ query }) => { try { const results = await searchDocs(query); const content = results.map((result) => { const { title, content, link } = result; const text = `Title: ${title}\nContent: ${content}\nLink: ${link}`; return { type: 'text', text }; }); return { content }; } catch (error) { return { content: [ { type: 'text', text: `Error searching docs: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }); }; const searchDocs = async (query) => { const url = `${DOCS_SEARCH_URL}?q=${encodeURIComponent(query)}`; try { const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); if (!data || data.length === 0) { throw new Error('No results found'); } return data; } catch (error) { if (error instanceof Error) { throw new Error(`Search failed: ${error.message}`); } throw error; } };