Skip to content

Commit 2c56bd8

Browse files
authored
Merge pull request #2 from storybookjs/Add-basic-instructions-and-MCP-description
Add a basic `getUIBuildingInstructions` tool
2 parents 5d11622 + 65e4ec4 commit 2c56bd8

File tree

3 files changed

+169
-4
lines changed

3 files changed

+169
-4
lines changed

package-lock.json

Lines changed: 116 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mcp-handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
55
import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
66
import pkgJson from "../package.json" with { type: "json" };
77
import { registerAdditionTool } from "./tools/addition";
8+
import { registerUIBuildingTool } from "./tools/getUIBuildingInstructions";
89

910
function createMcpServer() {
1011
// New initialization request
@@ -27,6 +28,7 @@ function createMcpServer() {
2728
version: pkgJson.version,
2829
});
2930
registerAdditionTool(server);
31+
registerUIBuildingTool(server);
3032

3133
server.connect(transport);
3234
return transport;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2+
3+
const INSTRUCTIONS = `
4+
# Writing User Interfaces
5+
6+
When writing UI, prefer breaking larger components up into smaller parts.
7+
8+
ALWAYS write a Storybook story for any component written. If editing a component, ensure appropriate changes have been made to stories for that component.
9+
10+
When writing stories, use CSF3 importing types from '@storybook/nextjs-vite'. Here is a simple example:
11+
12+
\`\`\`ts
13+
import { Meta, StoryObj } from '@storybook/nextjs-vite';
14+
15+
import { Break } from './Break';
16+
17+
type Story = StoryObj<typeof Break>;
18+
19+
const meta: Meta<typeof Break> = {
20+
component: Break,
21+
args: {},
22+
};
23+
24+
export default meta;
25+
26+
export const Horizontal: Story = {
27+
args: {
28+
orientation: 'horizontal',
29+
},
30+
};
31+
\`\`\`
32+
33+
After completing each step of the process, provide a link to each story added or modified in the format [Story Name](https://storybook.dev-chromatic.com/?path=/story/<storyId>).
34+
`;
35+
36+
export function registerUIBuildingTool(server: McpServer) {
37+
server.registerTool(
38+
"getUIBuildingInstructions",
39+
{
40+
title: "UI Building Instructions",
41+
description: `Instructions on how to do UI development.
42+
43+
ALWAYS call this tool before doing any UI/frontend/React development, including but not
44+
limited to adding or updating new components, pages, screens or layouts.`,
45+
inputSchema: {},
46+
},
47+
async () => ({
48+
content: [{ type: "text", text: INSTRUCTIONS }],
49+
}),
50+
);
51+
}

0 commit comments

Comments
 (0)