Skip to content

Commit 96d3a73

Browse files
authored
Add main docs MCP search (#269)
* Add main docs MCP search - Added new tool - Updated documentation * added changeset * Fixed tests and error handling * Fixed typos * Removed unnecessary comments
1 parent dc47417 commit 96d3a73

11 files changed

Lines changed: 346 additions & 14 deletions

File tree

.changeset/sixty-regions-tickle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sei-js/mcp-server": patch
3+
---
4+
5+
Added main docs search tool

docs/mcp-server/context.mdx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
---
22
title: "Documentation Context"
3-
description: "How the MCP server reads @sei-js documentation to provide intelligent assistance"
3+
description: "How the MCP server provides intelligent assistance through comprehensive documentation search"
44
icon: "book-open"
55
---
66

7-
The Sei MCP Server includes intelligent documentation search that reads the entire @sei-js ecosystem documentation to provide context-aware responses and code generation.
7+
The Sei MCP Server includes intelligent documentation search that provides access to both the main Sei documentation and the entire @sei-js ecosystem documentation for context-aware responses and code generation.
88

99
## Documentation Access
1010

11-
The MCP server can search and reference documentation for all @sei-js packages:
11+
The MCP server provides two search tools:
12+
13+
### Main Sei Documentation (`search_docs`)
14+
Search the official Sei documentation for:
15+
- General chain information and network details
16+
- Ecosystem providers and integrations
17+
- User onboarding guides and tutorials
18+
- Bridging and cross-chain operations
19+
- DeFi protocols and marketplace information
20+
21+
### Sei-JS Package Documentation (`search_sei_js_docs`)
22+
Search and reference documentation for all @sei-js packages:
1223

1324
- **@sei-js/precompiles** - Precompile contract reference and integration examples
1425
- **@sei-js/sei-global-wallet** - EIP-6963 wallet standard implementation

docs/mcp-server/introduction.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The Model Context Protocol is an open standard that connects AI systems with cus
7070
- **Real-time blockchain data access** - Get current balances, transaction history, and network status directly from Sei
7171
- **Secure by default** - Runs in read-only mode until you explicitly enable wallet tools
7272
- **Full execution and write operations** - Deploy contracts, execute transactions, and interact with smart contracts (with wallet configured)
73-
- **Up-to-date documentation access** - Search and understand the latest Sei documentation and guides
73+
- **Up-to-date documentation access** - Search both main Sei docs and Sei-JS package documentation for comprehensive guidance
7474
- **Specialized blockchain capabilities** - Access Sei-specific features like precompiles and native token operations
7575

7676
The Sei MCP Server leverages this protocol to bring comprehensive blockchain functionality directly to your AI assistant, enabling natural language interactions with the Sei network.
@@ -91,13 +91,14 @@ The Sei MCP Server leverages this protocol to bring comprehensive blockchain fun
9191
</Accordion>
9292

9393
<Accordion title="Comprehensive Toolkit" icon="toolbox">
94-
Access 16+ blockchain tools covering token management, NFT operations, smart contract interactions, and network monitoring.
94+
Access 29 blockchain tools covering token management, NFT operations, smart contract interactions, network monitoring, and documentation search.
9595
</Accordion>
9696
</AccordionGroup>
9797

9898
## Example Queries
9999

100100
```text
101+
"How do I bridge tokens to Sei from Ethereum?"
101102
"How do I query staking my delegations using Viem?"
102103
"Generate a wallet connection component using Sei Global Wallet"
103104
"Help me set up a new Sei project with the latest patterns"

docs/mcp-server/tools.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: "Available Tools"
3-
description: "Complete reference of 28 MCP tools for blockchain operations"
3+
description: "Complete reference of 29 MCP tools for blockchain operations"
44
icon: "wrench"
55
---
66

7-
The Sei MCP Server provides 28 tools for blockchain operations. **By default, wallet tools are disabled** and only read-only tools are available. [Enable wallet tools](/mcp-server/setup#wallet-connection) to unlock transaction capabilities.
7+
The Sei MCP Server provides 29 tools for blockchain operations. **By default, wallet tools are disabled** and only read-only tools are available. [Enable wallet tools](/mcp-server/setup#wallet-connection) to unlock transaction capabilities.
88

99
<Note>
1010
**Wallet Tools Disabled by Default**
@@ -113,6 +113,7 @@ These tools require [wallet configuration](/mcp-server/setup#wallet-connection)
113113

114114
| Tool | Purpose | Example Usage |
115115
|------|---------|---------------|
116+
| `search_docs` | Search the main Sei docs for general chain information, ecosystem providers, and user onboarding guides | "How do I bridge tokens to Sei?" |
116117
| `search_sei_js_docs` | Search Sei-JS documentation | "How do I use precompiles with Viem?" |
117118

118119
## Enabling Wallet Tools
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { createDocsSearchTool } from './server.js';
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2+
import { z } from 'zod';
3+
import type { SeiSearchResponse } from '../mintlify/types';
4+
5+
const DOCS_SEARCH_URL = 'https://docs.sei-apis.io/search';
6+
7+
export const createDocsSearchTool = async (server: McpServer) => {
8+
server.tool(
9+
'search_docs',
10+
'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.',
11+
{
12+
query: z.string()
13+
},
14+
async ({ query }) => {
15+
try {
16+
const results = await searchDocs(query);
17+
const content = results.map((result) => {
18+
const { title, content, link } = result;
19+
const text = `Title: ${title}\nContent: ${content}\nLink: ${link}`;
20+
return {
21+
type: 'text' as const,
22+
text
23+
};
24+
});
25+
return {
26+
content
27+
};
28+
} catch (error) {
29+
return {
30+
content: [
31+
{
32+
type: 'text',
33+
text: `Error searching docs: ${error instanceof Error ? error.message : String(error)}`
34+
}
35+
],
36+
isError: true
37+
};
38+
}
39+
}
40+
);
41+
};
42+
43+
const searchDocs = async (query: string): Promise<SeiSearchResponse[]> => {
44+
const url = `${DOCS_SEARCH_URL}?q=${encodeURIComponent(query)}`;
45+
46+
try {
47+
const response = await fetch(url);
48+
49+
if (!response.ok) {
50+
throw new Error(`HTTP error! status: ${response.status}`);
51+
}
52+
53+
const data = await response.json() as SeiSearchResponse[];
54+
55+
if (!data || data.length === 0) {
56+
throw new Error('No results found');
57+
}
58+
59+
return data;
60+
} catch (error) {
61+
if (error instanceof Error) {
62+
throw new Error(`Search failed: ${error.message}`);
63+
}
64+
65+
throw error;
66+
}
67+
};

packages/mcp-server/src/mintlify/search.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { TrieveSDK } from 'trieve-ts-sdk';
44
import { z } from 'zod';
55

66
import { DEFAULT_BASE_URL, SERVER_URL, SUBDOMAIN } from './config.js';
7-
import type { MintlifySearchConfig, SeiJSSearchResult, TrieveResponse, TrieveSearchResult } from './types.js';
7+
import type { MintlifySearchConfig, SeiSearchResponse, TrieveResponse, TrieveSearchResult } from './types.js';
88
import { formatErr, throwOnAxiosError } from './utils.js';
99

1010
/**
@@ -28,7 +28,7 @@ const fetchMintlifyConfig = async (subdomain: string): Promise<MintlifySearchCon
2828
/**
2929
* Search Sei-JS documentation using Mintlify/Trieve API
3030
*/
31-
const searchSeiJSDocs = async (query: string, config: MintlifySearchConfig): Promise<SeiJSSearchResult[]> => {
31+
const searchSeiJSDocs = async (query: string, config: MintlifySearchConfig): Promise<SeiSearchResponse[]> => {
3232
const trieve = new TrieveSDK({
3333
apiKey: config.trieveApiKey,
3434
datasetId: config.trieveDatasetId,
@@ -65,7 +65,7 @@ export const createSeiJSDocsSearchTool = async (server: McpServer): Promise<void
6565

6666
server.tool(
6767
'search_sei_js_docs',
68-
'Search all @sei-js libraries documentation for blockchain development, EVM/Ethereum integration, global wallet connections, React next.js and vite boilerplates, ledger integration, and the Sei chain registry',
68+
'Search all @sei-js libraries documentation for blockchain development, EVM/Ethereum integration, global wallet connections, React Next.js and Vite boilerplates, ledger integration, and the Sei chain registry. Useful for NodeJS based integrations with Sei.',
6969
{
7070
query: z.string()
7171
},

packages/mcp-server/src/mintlify/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface MintlifySearchConfig {
55
base_url?: string;
66
}
77

8-
export interface SeiJSSearchResult {
8+
export interface SeiSearchResponse {
99
title: string;
1010
content: string;
1111
link: string;

packages/mcp-server/src/server/server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
32
import { getSupportedNetworks } from '../core/chains.js';
43
import { registerEVMPrompts } from '../core/prompts.js';
54
import { registerEVMResources } from '../core/resources.js';
65
import { registerEVMTools } from '../core/tools.js';
76
import { createSeiJSDocsSearchTool } from '../mintlify/index.js';
7+
import { createDocsSearchTool } from '../docs/index.js';
88

99
// Create and start the MCP server
1010
async function startServer() {
@@ -20,7 +20,8 @@ async function startServer() {
2020
registerEVMTools(server);
2121
registerEVMPrompts(server);
2222

23-
// Register documentation search tool
23+
// Register documentation search tools
24+
await createDocsSearchTool(server);
2425
await createSeiJSDocsSearchTool(server);
2526

2627
// Log server information

packages/mcp-server/src/tests/core/services/balance.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,31 @@ describe('Balance Service', () => {
150150
// Restore console.error
151151
console.error = originalConsoleError;
152152
});
153+
154+
test('should return false if there is a non-Error object thrown', async () => {
155+
// Import mocked modules
156+
const { readContract } = await import('../../../core/services/contracts.js');
157+
const { utils } = await import('../../../core/services/utils.js');
158+
159+
// Configure mocks for this test
160+
(readContract as jest.Mock).mockImplementation(() => {
161+
throw 'String error message'; // Non-Error object
162+
});
163+
(utils.validateAddress as jest.Mock).mockImplementation((address) => address as `0x${string}`);
164+
165+
// Mock console.error to avoid cluttering test output
166+
const originalConsoleError = console.error;
167+
console.error = () => {};
168+
169+
// Call the function
170+
const result = await isNFTOwner(VALID_TOKEN_ADDRESS, VALID_OWNER_ADDRESS, 1n);
171+
172+
// Verify results
173+
expect(result).toBe(false);
174+
175+
// Restore console.error
176+
console.error = originalConsoleError;
177+
});
153178
});
154179

155180
describe('getERC721Balance', () => {

0 commit comments

Comments
 (0)