@czi-sds/mcp 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +420 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,34 +1,439 @@
|
|
|
1
1
|
# SDS MCP Server
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
examples, design tokens and migration patterns.
|
|
3
|
+
Welcome to the Science Design System (SDS) MCP Server! This guide will help you understand the architecture, create new tools, test your changes, and publish the server.
|
|
5
4
|
|
|
6
|
-
##
|
|
5
|
+
## Table of Contents
|
|
7
6
|
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
|
|
7
|
+
- [Architecture Overview](#architecture-overview)
|
|
8
|
+
- [Setting Up Development Environment](#setting-up-development-environment)
|
|
9
|
+
- [Creating a New Tool](#creating-a-new-tool)
|
|
10
|
+
- [Testing Your Changes](#testing-your-changes)
|
|
11
|
+
- [Publishing to NPM](#publishing-to-npm)
|
|
12
|
+
- [Real-World Testing](#real-world-testing)
|
|
13
|
+
- [Best Practices](#best-practices)
|
|
13
14
|
|
|
14
|
-
##
|
|
15
|
+
## Architecture Overview
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
- `get_component_props` - Get component properties and configuration
|
|
18
|
-
- `get_component_example` - Retrieve usage examples and code patterns
|
|
19
|
-
- `get_theme` - Get theme tokens, semantic tokens, text styles and layer styles
|
|
17
|
+
### Project Structure
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
```
|
|
20
|
+
packages/mcp/
|
|
21
|
+
├── src/
|
|
22
|
+
│ ├── tools/ # Tool implementations
|
|
23
|
+
│ │ ├── index.ts # Tool registry and initialization
|
|
24
|
+
│ │ └── *.ts # Individual tool files
|
|
25
|
+
│ ├── lib/
|
|
26
|
+
│ │ ├── types.ts # TypeScript type definitions
|
|
27
|
+
│ │ └── fetch.ts # Data fetching utilities
|
|
28
|
+
│ ├── server.ts # Core MCP server setup
|
|
29
|
+
│ ├── stdio.ts # STDIO transport implementation
|
|
30
|
+
│ └── http.ts # HTTP transport implementation
|
|
31
|
+
├── data/ # Static data files
|
|
32
|
+
│ ├── component-list.json
|
|
33
|
+
│ ├── component-props/
|
|
34
|
+
│ ├── component-props-storybook/
|
|
35
|
+
│ └── tailwind.json
|
|
36
|
+
├── scripts/ # Build and generation scripts
|
|
37
|
+
│ ├── generate-*.ts # Data generation scripts
|
|
38
|
+
│ └── inspect.js # Inspector helper
|
|
39
|
+
└── dist/ # Built output
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Core Concepts
|
|
43
|
+
|
|
44
|
+
#### 1. **MCP Server**
|
|
45
|
+
|
|
46
|
+
The Model Context Protocol (MCP) server provides tools to AI assistants for interacting with the SDS component library. It supports two transport methods:
|
|
47
|
+
|
|
48
|
+
- **STDIO**: For local CLI usage (primary method)
|
|
49
|
+
- **HTTP**: For web-based integrations
|
|
50
|
+
|
|
51
|
+
#### 2. **Tools**
|
|
52
|
+
|
|
53
|
+
Tools are functions that AI assistants can call to retrieve information or perform actions. Each tool:
|
|
54
|
+
|
|
55
|
+
- Has a unique name and description
|
|
56
|
+
- Defines input parameters using Zod schemas
|
|
57
|
+
- Returns structured data to the assistant
|
|
58
|
+
- Can have initialization context (`ctx`)
|
|
59
|
+
|
|
60
|
+
#### 3. **Data Layer**
|
|
61
|
+
|
|
62
|
+
The `data/` directory contains pre-generated JSON files with component information:
|
|
63
|
+
|
|
64
|
+
- Component lists and properties
|
|
65
|
+
- Storybook metadata
|
|
66
|
+
- Design tokens (Tailwind config)
|
|
67
|
+
|
|
68
|
+
## Setting Up Development Environment
|
|
69
|
+
|
|
70
|
+
### Prerequisites
|
|
71
|
+
|
|
72
|
+
1. Clone the repository:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
git clone https://github.com/chanzuckerberg/sci-components.git
|
|
76
|
+
cd sci-components
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
2. Install/Use the correct NodeJs version
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
nvm use
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
3. Install dependencies:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
yarn install
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
4. Build packages (required for data generation):
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
yarn build
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
5. Navigate to the MCP package:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
cd packages/mcp
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Creating a New Tool
|
|
104
|
+
|
|
105
|
+
### Step 1: Create the Tool File
|
|
106
|
+
|
|
107
|
+
Create a new file in `src/tools/` (e.g., `src/tools/my-new-tool.ts`):
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { z } from "zod";
|
|
111
|
+
import { type Tool } from "../lib/types.js";
|
|
112
|
+
|
|
113
|
+
// Define the tool's context type (optional)
|
|
114
|
+
type MyToolContext = {
|
|
115
|
+
// Any data needed during initialization
|
|
116
|
+
availableOptions?: string[];
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const myNewTool: Tool<MyToolContext> = {
|
|
120
|
+
name: "my_new_tool",
|
|
121
|
+
description: "Brief description of what this tool does for AI assistants",
|
|
122
|
+
|
|
123
|
+
// Optional: Initialize context data
|
|
124
|
+
async ctx() {
|
|
125
|
+
// Load any necessary data at startup
|
|
126
|
+
const availableOptions = await loadOptions();
|
|
127
|
+
return { availableOptions };
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
// Optional: Conditionally disable the tool
|
|
131
|
+
disabled(config) {
|
|
132
|
+
return config.someFeatureFlag === false;
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
// Register and implement the tool
|
|
136
|
+
exec(server, { ctx, name, description }) {
|
|
137
|
+
server.tool(
|
|
138
|
+
name,
|
|
139
|
+
description,
|
|
140
|
+
{
|
|
141
|
+
// Define input parameters using Zod
|
|
142
|
+
param1: z.string().describe("Description of param1"),
|
|
143
|
+
param2: z
|
|
144
|
+
.enum(["option1", "option2"])
|
|
145
|
+
.optional()
|
|
146
|
+
.describe("Optional parameter with enum values"),
|
|
147
|
+
},
|
|
148
|
+
async ({ param1, param2 }) => {
|
|
149
|
+
try {
|
|
150
|
+
// Tool implementation
|
|
151
|
+
const result = await processData(param1, param2);
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
content: [
|
|
155
|
+
{
|
|
156
|
+
type: "text",
|
|
157
|
+
text: JSON.stringify(result, null, 2),
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
};
|
|
161
|
+
} catch (error) {
|
|
162
|
+
return {
|
|
163
|
+
content: [
|
|
164
|
+
{
|
|
165
|
+
type: "text",
|
|
166
|
+
text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Step 2: Register the Tool
|
|
178
|
+
|
|
179
|
+
Add your tool to `src/tools/index.ts`:
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import { myNewTool } from "./my-new-tool.ts";
|
|
183
|
+
|
|
184
|
+
const tools: Tool[] = [
|
|
185
|
+
getComponentPropsTool,
|
|
186
|
+
getComponentPropsStorybookTool,
|
|
187
|
+
listComponentsTool,
|
|
188
|
+
getTailwindTokensTool,
|
|
189
|
+
myNewTool, // Add your tool here
|
|
190
|
+
];
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Step 3: Add TypeScript Types (if needed)
|
|
194
|
+
|
|
195
|
+
If your tool requires custom types, add them to `src/lib/types.ts`:
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
export interface MyToolData {
|
|
199
|
+
// Define your data structure
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Step 4: Add Data Generation Script (if needed)
|
|
204
|
+
|
|
205
|
+
If your tool requires pre-generated data, create a script in `scripts/`:
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
// scripts/generate-my-data.ts
|
|
209
|
+
import { writeFileSync } from "fs";
|
|
210
|
+
import { join } from "path";
|
|
211
|
+
|
|
212
|
+
async function generateMyData() {
|
|
213
|
+
const data = await collectData();
|
|
214
|
+
|
|
215
|
+
const outputPath = join(process.cwd(), "data", "my-data.json");
|
|
216
|
+
writeFileSync(outputPath, JSON.stringify(data, null, 2));
|
|
217
|
+
|
|
218
|
+
console.log("✓ Generated my-data.json");
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
generateMyData().catch(console.error);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Add the script to `package.json`:
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"scripts": {
|
|
229
|
+
"generate:my-data": "tsx scripts/generate-my-data.ts",
|
|
230
|
+
"generate:all": "... && yarn generate:my-data"
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Testing Your Changes
|
|
236
|
+
|
|
237
|
+
### Using the MCP Inspector
|
|
238
|
+
|
|
239
|
+
The MCP Inspector provides an interactive UI for testing your tools:
|
|
240
|
+
|
|
241
|
+
1. **Start the inspector from monorepo root with your local server:**
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
yarn mcp:inspect:dev
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
You can also navigate to the MCP package directory first and then run the commands directly from there:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
cd packages/mcp
|
|
251
|
+
yarn inspect:dev
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
This will open a web interface where you can:
|
|
255
|
+
|
|
256
|
+
- See all available tools
|
|
257
|
+
- Test tool invocations with different parameters
|
|
258
|
+
- View responses in real-time
|
|
259
|
+
- Debug any issues
|
|
260
|
+
|
|
261
|
+
2. **Test your specific tool:**
|
|
22
262
|
|
|
23
|
-
|
|
263
|
+
- Click "Connect" in the left sidebar to connect to the MCP server.
|
|
264
|
+
- Click "List Tools" to view all available tools.
|
|
265
|
+
- Fill in the required parameters.
|
|
266
|
+
- Click "Run Tool" to execute it and view the response.
|
|
267
|
+
- Verify both the output format and the content.
|
|
268
|
+
|
|
269
|
+
### Manual Testing with the Built Server
|
|
270
|
+
|
|
271
|
+
1. **Build the server:**
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
cd packages/mcp
|
|
275
|
+
yarn build
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
2. **Run the inspector with the built version:**
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
cd packages/mcp
|
|
282
|
+
yarn inspect
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Publishing to NPM
|
|
286
|
+
|
|
287
|
+
### Pre-publish Checklist
|
|
288
|
+
|
|
289
|
+
Navigate to the MCP package directory first and then run the following commands:
|
|
290
|
+
|
|
291
|
+
1. **Ensure all data is generated:**
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
yarn generate:all
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
2. **Build the package:**
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
yarn build
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
3. **Test the built package:**
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
yarn inspect
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Publishing Process
|
|
310
|
+
|
|
311
|
+
The SDS monorepo uses Lerna for publishing. From the repository root:
|
|
312
|
+
|
|
313
|
+
1. **Commit all changes:**
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
git add .
|
|
317
|
+
git commit
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
2. **Push to main branch** (after PR approval):
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
git push origin main
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
3. **Publish via CI/CD:**
|
|
327
|
+
The automated workflow handles publishing when changes are pushed to the `prod` branch:
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
# Sync prod with main
|
|
331
|
+
git checkout prod
|
|
332
|
+
git pull origin main
|
|
333
|
+
git push origin prod
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Real-World Testing
|
|
337
|
+
|
|
338
|
+
### Testing in Claude Desktop
|
|
339
|
+
|
|
340
|
+
1. **Configure Claude Desktop:**
|
|
341
|
+
|
|
342
|
+
Add to your Claude Desktop configuration file:
|
|
343
|
+
|
|
344
|
+
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
345
|
+
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
346
|
+
|
|
347
|
+
For local MCP testing, make sure the path to your sci-components project matches your setup.
|
|
348
|
+
|
|
349
|
+
```json
|
|
350
|
+
{
|
|
351
|
+
"mcpServers": {
|
|
352
|
+
"sds-mcp": {
|
|
353
|
+
"command": "node",
|
|
354
|
+
"args": ["/sci-components/packages/mcp/dist/stdio.js"]
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
To test the published version simply use npx to run the mcp server package:
|
|
24
361
|
|
|
25
362
|
```json
|
|
26
363
|
{
|
|
27
364
|
"mcpServers": {
|
|
28
365
|
"sds-mcp": {
|
|
366
|
+
"type": "stdio",
|
|
29
367
|
"command": "npx",
|
|
30
368
|
"args": ["-y", "@czi-sds/mcp"]
|
|
31
369
|
}
|
|
32
370
|
}
|
|
33
371
|
}
|
|
34
372
|
```
|
|
373
|
+
|
|
374
|
+
3. **Restart Claude Desktop** and test your tool in conversations
|
|
375
|
+
|
|
376
|
+
### Testing in Other MCP Clients
|
|
377
|
+
|
|
378
|
+
The server can be integrated with any MCP-compatible client:
|
|
379
|
+
|
|
380
|
+
1. **Via NPX (without installation):**
|
|
381
|
+
|
|
382
|
+
```json
|
|
383
|
+
{
|
|
384
|
+
"mcpServers": {
|
|
385
|
+
"sds-mcp": {
|
|
386
|
+
"type": "stdio",
|
|
387
|
+
"command": "npx",
|
|
388
|
+
"args": ["-y", "@czi-sds/mcp"]
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## Best Practices
|
|
395
|
+
|
|
396
|
+
### Tool Design
|
|
397
|
+
|
|
398
|
+
1. **Clear Naming**: Use descriptive, snake_case names (e.g., `get_component_props`)
|
|
399
|
+
2. **Comprehensive Descriptions**: Help AI assistants understand when to use your tool
|
|
400
|
+
3. **Error Handling**: Always wrap async operations in try-catch blocks
|
|
401
|
+
4. **Structured Output**: Return consistent JSON structures
|
|
402
|
+
5. **Parameter Validation**: Use Zod schemas to validate inputs
|
|
403
|
+
|
|
404
|
+
### Performance
|
|
405
|
+
|
|
406
|
+
1. **Lazy Loading**: Load data only when needed using the `ctx()` function
|
|
407
|
+
2. **Caching**: Cache expensive operations in the tool context
|
|
408
|
+
3. **Data Size**: Keep responses under reasonable size limits
|
|
409
|
+
4. **Async Operations**: Use async/await for all I/O operations
|
|
410
|
+
|
|
411
|
+
## Common Issues and Solutions
|
|
412
|
+
|
|
413
|
+
### Issue: Tool not appearing in inspector
|
|
414
|
+
|
|
415
|
+
**Solution**: Ensure the tool is properly registered in `src/tools/index.ts` and rebuild
|
|
416
|
+
|
|
417
|
+
### Issue: Data files not found
|
|
418
|
+
|
|
419
|
+
**Solution**: Run `yarn generate:all` before building
|
|
420
|
+
|
|
421
|
+
### Issue: Permission denied when running built script
|
|
422
|
+
|
|
423
|
+
**Solution**: Run `chmod +x dist/stdio.js` after building
|
|
424
|
+
|
|
425
|
+
## Getting Help
|
|
426
|
+
|
|
427
|
+
- **GitHub Issues**: [Report bugs or request features](https://github.com/chanzuckerberg/sci-components/issues)
|
|
428
|
+
- **Design System Docs**: [sds.czi.design](https://sds.czi.design)
|
|
429
|
+
- **MCP Documentation**: [Model Context Protocol](https://modelcontextprotocol.io)
|
|
430
|
+
|
|
431
|
+
## Contributing Guidelines
|
|
432
|
+
|
|
433
|
+
1. Fork the repository
|
|
434
|
+
2. Create a feature branch (`git checkout -b feature/new-tool`)
|
|
435
|
+
3. Make your changes
|
|
436
|
+
4. Write/update tests if applicable
|
|
437
|
+
5. Submit a pull request
|
|
438
|
+
|
|
439
|
+
Thank you for contributing to the SDS MCP Server!
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@czi-sds/mcp",
|
|
3
3
|
"description": "The official MCP server for SDS",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"main": "dist/stdio.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"tsx": "^4.20.3",
|
|
63
63
|
"typescript": "^5.9.2"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "fa7e676b7f69b6999cc8d6fe86c04b8069bfdb1e"
|
|
66
66
|
}
|