Skip to content

Commit 7a49a35

Browse files
committed
docs: add comprehensive Cursor IDE rules for MCP DevTools development
This commit introduces a set of detailed Cursor IDE rules to standardize development practices: - Create rules for AI-assisted development guidelines - Define core libraries usage standards - Establish MCP server and tool implementation patterns - Add testing and TypeScript coding standards - Provide guidelines for package creation and documentation - Enhance repository structure documentation
1 parent d0e6fc0 commit 7a49a35

10 files changed

+1318
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
description: AI-Assisted Development Guidelines
3+
globs: **/*
4+
alwaysApply: false
5+
---
6+
7+
# AI-Assisted Development Guidelines
8+
9+
Follow these guidelines when using Cursor IDE with AI assistance for MCP DevTools development:
10+
11+
@url https://docs.cursor.com/
12+
@file .cursor/rules/repository-structure.md
13+
14+
## Effective AI Prompts
15+
16+
1. **Be Specific**
17+
18+
- Include file paths and line numbers when referencing code
19+
- Specify the expected behavior, not just the task
20+
- Include relevant context (e.g., "This is part of the Jira MCP integration")
21+
22+
2. **Chunk Complex Tasks**
23+
24+
- Break down complex tasks into smaller steps
25+
- Ask for one implementation at a time
26+
- Verify each step before proceeding to the next
27+
28+
3. **Request Explanations**
29+
- Ask AI to explain its reasoning
30+
- Request documentation alongside implementation
31+
- Ask for alternative approaches when appropriate
32+
33+
## Code Review Assistance
34+
35+
1. **Request Focused Reviews**
36+
37+
- Ask AI to review specific aspects (security, performance, etc.)
38+
- Provide the full context of the code being reviewed
39+
- Ask for specific improvements rather than general feedback
40+
41+
2. **Validation Assistance**
42+
- Ask AI to help write tests for your code
43+
- Request validation of edge cases
44+
- Use AI to check for potential bugs or edge cases
45+
46+
## Documentation Assistance
47+
48+
1. **Generate Documentation**
49+
50+
- Ask AI to create or update README sections
51+
- Request JSDoc comments for functions
52+
- Use AI to help document complex algorithms
53+
54+
2. **Consistency**
55+
- Ask AI to ensure documentation follows the project standards
56+
- Request help maintaining consistent terminology
57+
- Use AI to check for documentation gaps
58+
59+
## Best Practices
60+
61+
1. **Always Review AI-Generated Code**
62+
63+
- Check for correctness and appropriateness
64+
- Verify complex algorithms
65+
- Ensure it meets project standards
66+
67+
2. **Iterative Refinement**
68+
69+
- Start with a basic implementation
70+
- Refine with more specific requirements
71+
- Use AI to help optimize the code
72+
73+
3. **Enhance, Don't Replace**
74+
- Use AI as a collaborator, not a replacement
75+
- Maintain ownership of the code
76+
- Understand the code AI generates
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
description: Core Libraries Usage Guidelines
3+
globs: packages/*/src/**/*.ts
4+
alwaysApply: true
5+
---
6+
7+
# Core Libraries Usage Guidelines
8+
9+
When developing MCP DevTools packages, prefer using shared core libraries over custom implementations to ensure consistency and maintainability.
10+
11+
@file packages/jira/src/index.ts
12+
@file .cursor/rules/mcp-server-implementation.md
13+
14+
## Required Core Libraries
15+
16+
| Library | Package | Purpose | Import Statement |
17+
| ------------- | --------------------------------- | ------------------------- | ------------------------------------------------------------------------ |
18+
| MCP Server | `@modelcontextprotocol/server` | Core server functionality | `import { createMcpServer } from '@modelcontextprotocol/server';` |
19+
| MCP Inspector | `@modelcontextprotocol/inspector` | Debugging tools | `import { inspector } from '@modelcontextprotocol/inspector';` |
20+
| MCP Types | `@modelcontextprotocol/types` | Shared type definitions | `import { McpRequest, McpResponse } from '@modelcontextprotocol/types';` |
21+
22+
## Common Utilities
23+
24+
The MCP DevTools core utilities should be used instead of reimplementing common functionality:
25+
26+
```typescript
27+
// PREFERRED: Import from core utilities
28+
import { validateEnvVars, formatErrorResponse } from "@mcp-devtools/core/utils";
29+
30+
// AVOID: Custom implementation of utilities
31+
const validateEnvVars = (required) => {
32+
/* ... */
33+
}; // Don't do this
34+
```
35+
36+
## Configuration Management
37+
38+
Use the shared configuration management from core:
39+
40+
```typescript
41+
import { loadConfig } from "@mcp-devtools/core/config";
42+
43+
// Load configuration with standard validation
44+
const config = loadConfig({
45+
requiredVars: ["API_KEY", "API_URL"],
46+
optionalVars: {
47+
TIMEOUT: "30000",
48+
DEBUG: "false",
49+
},
50+
});
51+
```
52+
53+
## HTTP Client
54+
55+
Use the shared HTTP client with standard error handling:
56+
57+
```typescript
58+
import { httpClient } from "@mcp-devtools/core/http";
59+
60+
// Make HTTP requests with standard error handling
61+
const response = await httpClient.get("https://api.example.com/data", {
62+
headers: { Authorization: `Bearer ${config.API_KEY}` },
63+
});
64+
```
65+
66+
## Logging
67+
68+
Use the standardized logging system:
69+
70+
```typescript
71+
import { logger } from "@mcp-devtools/core/logger";
72+
73+
// Log with standard levels and formatting
74+
logger.info("Operation successful", { operationId: "123" });
75+
logger.error("API call failed", { error, statusCode: 500 });
76+
```
77+
78+
## Authentication Helpers
79+
80+
Use shared authentication utilities:
81+
82+
```typescript
83+
import { createAuthHeaders, validateToken } from "@mcp-devtools/core/auth";
84+
85+
// Create standard auth headers
86+
const headers = createAuthHeaders(config.API_KEY, config.API_SECRET);
87+
```
88+
89+
## Guidelines
90+
91+
1. **Always check core libraries first** before implementing new functionality
92+
2. **Keep dependencies updated** to ensure security and compatibility
93+
3. **Contribute improvements** back to core libraries instead of creating package-specific versions
94+
4. **Document usage** of core libraries in your package's README
95+
5. **Follow versioning guidelines** when updating core library dependencies
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
description: MCP Server Implementation Guidelines
3+
globs: packages/*/src/index.ts
4+
alwaysApply: true
5+
---
6+
7+
# MCP Server Implementation Guidelines
8+
9+
When implementing a new MCP server or updating an existing one, follow these guidelines:
10+
11+
@file packages/jira/src/index.ts
12+
@file .cursor/rules/core-libraries-usage.md
13+
@file .cursor/rules/typescript-style.md
14+
15+
## Server Setup
16+
17+
```typescript
18+
import { createMcpServer } from "@modelcontextprotocol/server";
19+
import { registerTool1 } from "./tools/tool1";
20+
import { registerTool2 } from "./tools/tool2";
21+
// Import more tools as needed
22+
23+
// Create configuration with proper error handling
24+
const getConfig = (): Config => {
25+
const required = ["REQUIRED_ENV_VAR1", "REQUIRED_ENV_VAR2"];
26+
for (const env of required) {
27+
if (!process.env[env]) {
28+
console.error(`Missing required environment variable: ${env}`);
29+
process.exit(1);
30+
}
31+
}
32+
33+
return {
34+
var1: process.env.REQUIRED_ENV_VAR1,
35+
var2: process.env.REQUIRED_ENV_VAR2,
36+
optionalVar: process.env.OPTIONAL_ENV_VAR || "default",
37+
};
38+
};
39+
40+
// Initialize server
41+
const initServer = async () => {
42+
try {
43+
const config = getConfig();
44+
const server = createMcpServer();
45+
46+
// Register all tools
47+
registerTool1(server);
48+
registerTool2(server);
49+
// Register more tools
50+
51+
// Start the server
52+
server.start();
53+
console.log("MCP server started successfully");
54+
} catch (error) {
55+
console.error("Failed to start MCP server:", error);
56+
process.exit(1);
57+
}
58+
};
59+
60+
// Start the server
61+
initServer();
62+
```
63+
64+
## Guidelines
65+
66+
1. **Environment Variables**
67+
68+
- Validate all required environment variables at startup
69+
- Provide sensible defaults for optional variables
70+
- Document all environment variables in README
71+
72+
2. **Error Handling**
73+
74+
- Implement proper error handling for server initialization
75+
- Log meaningful error messages
76+
- Exit with non-zero code on critical errors
77+
78+
3. **Tool Registration**
79+
80+
- Register each tool from its own module
81+
- Keep registration code organized and maintainable
82+
- Use consistent patterns across all tools
83+
84+
4. **Logging**
85+
86+
- Log server start/stop events
87+
- Include appropriate context in logs
88+
- Avoid logging sensitive information
89+
90+
5. **Server Configuration**
91+
- Centralize configuration in one place
92+
- Validate configuration at startup
93+
- Use typed configuration objects
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
description: MCP Tool Implementation Guidelines
3+
globs: packages/*/src/tools/*.ts
4+
alwaysApply: true
5+
---
6+
7+
# MCP Tool Implementation Guidelines
8+
9+
When implementing a new MCP tool, follow these patterns:
10+
11+
@file packages/jira/src/tools/getTicket.ts
12+
@file .cursor/rules/typescript-style.mdc
13+
14+
## Tool Registration
15+
16+
```typescript
17+
export const registerToolName = (server: McpServer): void => {
18+
const toolParams = {
19+
// Define parameters according to JSON schema
20+
};
21+
22+
// For tools with aliases, use an array of tool names
23+
const toolNames = ["primary_tool_name", "alias_1", "alias_2"];
24+
25+
// Register all tool names with the same handler
26+
for (const tool of toolNames) {
27+
server.tool(tool, toolParams, async (params) => {
28+
try {
29+
// Implementation
30+
return {
31+
message: "Success message",
32+
};
33+
} catch (error) {
34+
return {
35+
error: `Error message: ${error.message}`,
36+
};
37+
}
38+
});
39+
}
40+
};
41+
```
42+
43+
## Parameter Validation
44+
45+
- Always validate required parameters early in the function
46+
- Use TypeScript types/interfaces for parameter typing
47+
- Document parameters with clear descriptions
48+
49+
## Error Handling
50+
51+
- Use try/catch blocks for all API calls
52+
- Return meaningful error messages
53+
- Log errors with appropriate context
54+
55+
## Documentation
56+
57+
- Update the README.md with your new tool
58+
- Add the tool to the Tool Reference table with all parameters
59+
- Include any aliases in the documentation

0 commit comments

Comments
 (0)