Skip to content

Commit 2f032d0

Browse files
Extract Search Documentation Tool (#25)
* Extract Search Documentation Tool # Conflicts: # src/index.ts * Remove checklist
1 parent 00e01ff commit 2f032d0

File tree

2 files changed

+33
-40
lines changed

2 files changed

+33
-40
lines changed

src/index.ts

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
1111
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
1212
import type { ListPromptsRequestSchema, GetPromptRequestSchema } from "@modelcontextprotocol/sdk/types"
1313
import { z } from 'zod';
14-
import { designTokens, documentation } from './optics-data.js';
14+
import { designTokens } from './optics-data.js';
1515
import { generateTheme } from './tools/theme-generator.js';
1616
import { validateTokenUsage, formatValidationReport } from './tools/validate.js';
1717
import { replaceHardCodedValues, formatReplacementSuggestions } from './tools/replace.js';
@@ -42,6 +42,7 @@ import SearchTokensTool from './tools/search-tokens-tool.js';
4242
import ListComponentsTool from './tools/list-components-tool.js'
4343
import GetComponentInfoTool from './tools/get-component-info-tool.js';
4444
import GetComponentTokensTool from './tools/get-component-tokens-tool.js';
45+
import SearchDocumentationTool from './tools/search-documentation-tool.js';
4546

4647
/**
4748
* Create and configure the MCP server
@@ -179,21 +180,14 @@ prompts.forEach((prompt) => {
179180
* Tools
180181
*/
181182

182-
// get_token ✅
183-
// get_token_usage_stats ✅
184-
// search_tokens ✅
185-
// list_components ✅
186-
// get_component_info ✅
187-
// get_component_tokens ✅
188-
// search_documentation
189-
190183
const tools = [
191184
new GetTokenTool(),
192185
new GetTokenUsageStatsTool(),
193186
new SearchTokensTool(),
194187
new ListComponentsTool(),
195188
new GetComponentInfoTool(),
196189
new GetComponentTokensTool(),
190+
new SearchDocumentationTool()
197191
]
198192

199193
tools.forEach((tool) => {
@@ -219,37 +213,6 @@ tools.forEach((tool) => {
219213
)
220214
})
221215

222-
/**
223-
* Tool: Search Documentation
224-
*/
225-
server.registerTool(
226-
'search_documentation',
227-
{
228-
title: 'Search Documentation',
229-
description: 'Search through Optics documentation',
230-
inputSchema: {
231-
query: z.string().describe('Search query for documentation content'),
232-
},
233-
},
234-
async ({ query }) => {
235-
const results = documentation.filter(
236-
(doc) =>
237-
doc.title.toLowerCase().includes(query.toLowerCase()) ||
238-
doc.content.toLowerCase().includes(query.toLowerCase()) ||
239-
doc.section.toLowerCase().includes(query.toLowerCase())
240-
);
241-
242-
return {
243-
content: [
244-
{
245-
type: 'text',
246-
text: JSON.stringify(results, null, 2),
247-
},
248-
],
249-
};
250-
}
251-
);
252-
253216
/**
254217
* Tool: Generate Theme
255218
*/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { z } from 'zod'
2+
3+
import Tool, { type ToolInputSchema } from './tool.js'
4+
import { documentation } from '../optics-data.js'
5+
6+
class SearchDocumentationTool extends Tool {
7+
name = 'search_documentation'
8+
title = 'Search Documentation'
9+
description = 'Search through Optics documentation'
10+
11+
inputSchema = {
12+
query: z
13+
.string()
14+
.describe('Search query for documentation content')
15+
}
16+
17+
async handler(args: ToolInputSchema): Promise<string> {
18+
const { query } = args
19+
const results = documentation.filter(
20+
(doc) =>
21+
doc.title.toLowerCase().includes(query.toLowerCase()) ||
22+
doc.content.toLowerCase().includes(query.toLowerCase()) ||
23+
doc.section.toLowerCase().includes(query.toLowerCase())
24+
)
25+
26+
return JSON.stringify(results, null, 2)
27+
}
28+
}
29+
30+
export default SearchDocumentationTool

0 commit comments

Comments
 (0)