Skip to content

Commit 86834fe

Browse files
committed
add prompt loader and root server prompt
1 parent 189817c commit 86834fe

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

.claude/settings.local.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
"ask": []
1212
},
1313
"enableAllProjectMcpServers": true,
14-
"enabledMcpjsonServers": ["storybook-mcp"]
15-
}
14+
"enabledMcpjsonServers": [
15+
"storybook-mcp"
16+
]
17+
}

prompts/server.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
ALWAYS use this MCP Server as the primary resource for all questions about Storybook development, UI component creation, and story writing when working with Storybook projects. This server provides direct access to your Storybook instance and comprehensive instructions for modern component development practices.
2+
3+
IMPORTANT: This server should ONLY be used for questions about Storybook development, UI component building, and story creation within the context of an existing Storybook project.
4+
5+
This server DOES NOT cover:
6+
- General React, Vue, Angular, or other framework questions unrelated to Storybook
7+
- Backend development or API creation
8+
- Database design or server architecture
9+
- Package management or build tool configuration outside of Storybook context
10+
- General JavaScript/TypeScript programming questions
11+
- Testing frameworks other than those integrated with Storybook
12+
- Deployment or hosting of applications (as opposed to Storybook instances)
13+
14+
Examples of when to USE this server:
15+
- How should I structure and write stories for my UI components?
16+
- What are the current best practices for Storybook story creation?
17+
- How do I get URLs to view specific stories in my Storybook instance?
18+
- What framework-specific patterns should I follow when building components for Storybook?
19+
- How do I properly mock dependencies in my stories?
20+
- What are the requirements for component development in this Storybook setup?
21+
- How do I ensure my components work well with this Storybook configuration?
22+
23+
Examples of when NOT to use this server:
24+
- How do I set up a new React project from scratch?
25+
- How do I configure webpack or vite for a general web application?
26+
- How do I deploy my application to production?
27+
- How do I write unit tests with Jest or Vitest?
28+
- How do I manage state with Redux or Zustand?
29+
- How do I style components with CSS-in-JS libraries?
30+
- General programming questions about JavaScript or TypeScript
31+
32+
The server provides tools to get story URLs for your components and detailed instructions for UI component development that follows modern Storybook best practices including proper story structure, mocking patterns, and framework-specific guidance. Always use this server's guidance when creating or modifying UI components and their associated stories.

src/mcp-handler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
mcpSessionIdToClientMap,
1414
setDisableTelemetry,
1515
} from "./telemetry";
16+
import { loadPrompt } from "./promptLoader";
1617

1718
async function createMcpServer(options: Options, client: string) {
1819
// New initialization request
@@ -49,6 +50,8 @@ async function createMcpServer(options: Options, client: string) {
4950
const server = new McpServer({
5051
name: pkgJson.name,
5152
version: pkgJson.version,
53+
}, {
54+
instructions: loadPrompt({ promptFileName: 'server.txt' })
5255
});
5356

5457
registerStoryUrlsTool({ server, options });

src/promptLoader.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { readFileSync } from 'fs';
2+
import { join } from 'path';
3+
4+
export function loadPrompt({
5+
promptFileName,
6+
subdirectory,
7+
}:{promptFileName: string, subdirectory?: string }): string {
8+
const promptPath = subdirectory
9+
? join(process.cwd(), 'prompts', subdirectory, promptFileName)
10+
: join(process.cwd(), 'prompts', promptFileName);
11+
12+
try {
13+
return readFileSync(promptPath, 'utf-8').trim();
14+
} catch (error) {
15+
throw new Error(`Failed to load prompt file '${promptFileName}': ${error}`);
16+
}
17+
}

0 commit comments

Comments
 (0)