-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathserver.ts
More file actions
69 lines (61 loc) · 1.81 KB
/
Copy pathserver.ts
File metadata and controls
69 lines (61 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
import type { SeiSearchResponse } from '../mintlify/types';
const DOCS_SEARCH_URL = 'https://docs.sei-apis.io/search';
export const createDocsSearchTool = async (server: McpServer) => {
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' as const,
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: string): Promise<SeiSearchResponse[]> => {
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() as SeiSearchResponse[];
if (!data || data.length === 0) {
throw new Error('No results found');
}
// Return as array to match expected interface
return data;
} catch (error) {
if (error instanceof Error) {
throw new Error(`Search failed: ${error.message}`);
}
// For testing purposes, allow non-Error objects to pass through
// so we can test the String(error) branch in the main handler
throw error;
}
};