Skip to content

Commit a7f6bd3

Browse files
Extract Get Component Info Tool (#23)
* extract # Conflicts: # src/index.ts * Remove unneeded import
1 parent 0433453 commit a7f6bd3

File tree

2 files changed

+38
-43
lines changed

2 files changed

+38
-43
lines changed

src/index.ts

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type { ListPromptsRequestSchema, GetPromptRequestSchema } from "@modelcon
1313
import { z } from 'zod';
1414
import {
1515
designTokens,
16-
components,
1716
documentation,
1817
getComponentTokenDependencies,
1918
} from './optics-data.js';
@@ -45,6 +44,7 @@ import GetTokenTool from './tools/get-token-tool.js';
4544
import GetTokenUsageStatsTool from './tools/get-token-usage-stats-tool.js';
4645
import SearchTokensTool from './tools/search-tokens-tool.js';
4746
import ListComponentsTool from './tools/list-components-tool.js'
47+
import GetComponentInfoTool from './tools/get-component-info-tool.js';
4848

4949
/**
5050
* Create and configure the MCP server
@@ -186,7 +186,7 @@ prompts.forEach((prompt) => {
186186
// get_token_usage_stats ✅
187187
// search_tokens ✅
188188
// list_components ✅
189-
// get_component_info
189+
// get_component_info
190190
// get_component_tokens
191191
// search_documentation
192192

@@ -195,6 +195,7 @@ const tools = [
195195
new GetTokenUsageStatsTool(),
196196
new SearchTokensTool(),
197197
new ListComponentsTool(),
198+
new GetComponentInfoTool(),
198199
]
199200

200201
tools.forEach((tool) => {
@@ -220,47 +221,6 @@ tools.forEach((tool) => {
220221
)
221222
})
222223

223-
/**
224-
* Tool: Get Component Info
225-
*/
226-
server.registerTool(
227-
'get_component_info',
228-
{
229-
title: 'Get Component Info',
230-
description: 'Get detailed information about a component including its design token dependencies',
231-
inputSchema: {
232-
componentName: z.string().describe('The name of the component (e.g., "Button", "Card", "Input")'),
233-
},
234-
},
235-
async ({ componentName }) => {
236-
const component = components.find(
237-
(c) => c.name.toLowerCase() === componentName.toLowerCase()
238-
);
239-
240-
if (!component) {
241-
return {
242-
content: [
243-
{
244-
type: 'text',
245-
text: `Component not found: ${componentName}\n\nAvailable components: ${components
246-
.map((c) => c.name)
247-
.join(', ')}`,
248-
},
249-
],
250-
};
251-
}
252-
253-
return {
254-
content: [
255-
{
256-
type: 'text',
257-
text: JSON.stringify(component, null, 2),
258-
},
259-
],
260-
};
261-
}
262-
);
263-
264224
/**
265225
* Tool: Get Component Tokens
266226
*/
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { z } from 'zod'
2+
3+
import Tool, { type ToolInputSchema } from './tool.js'
4+
import { components } from '../optics-data.js'
5+
6+
class GetComponentInfoTool extends Tool {
7+
name = 'get_component_info'
8+
title = 'Get Component Info'
9+
description = 'Get detailed information about a component including its design token dependencies'
10+
11+
inputSchema = {
12+
componentName: z
13+
.string()
14+
.describe('The name of the component (e.g., "Button", "Card", "Input")')
15+
}
16+
17+
async handler(args: ToolInputSchema): Promise<string> {
18+
const component = components.find(
19+
(c) => c.name.toLowerCase() === args.componentName.toLowerCase()
20+
)
21+
22+
let value = ''
23+
24+
if (!component) {
25+
const availableComponents = components.map((c) => c.name).join(', ')
26+
value = `Component not found: ${args.componentName}\n\nAvailable components: ${availableComponents}`
27+
} else {
28+
value = JSON.stringify(component, null, 2)
29+
}
30+
31+
return value
32+
}
33+
}
34+
35+
export default GetComponentInfoTool

0 commit comments

Comments
 (0)