Skip to content

Commit 571e8da

Browse files
tewariganuraghazra
andauthored
feat: add description to clientName in toolcall & refactor logic for calling createCursorRule tools Call (#3010)
* feat: add describe to client name * feat: add changeset * feat: refactor ai tool call * chore: update changes * chore: add more comments * fix: lint * fix: spacing * Update packages/blade-mcp/src/utils/cursorRulesUtils.ts Co-authored-by: Anurag Hazra <[email protected]> * Update .changeset/shy-candles-whisper.md Co-authored-by: Anurag Hazra <[email protected]> --------- Co-authored-by: Anurag Hazra <[email protected]>
1 parent f3b724d commit 571e8da

File tree

6 files changed

+131
-66
lines changed

6 files changed

+131
-66
lines changed

.changeset/shy-candles-whisper.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@razorpay/blade-mcp': minor
3+
---
4+
5+
feat(blade-mcp): add description to client name in get docs tool call & refactor logic for calling createCursorRule tools Call

packages/blade-mcp/src/tools/createBladeCursorRules.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,7 @@ import type { ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
22
import { z } from 'zod';
33
import { analyticsToolCallEventName, CURSOR_RULES_VERSION } from '../utils/tokens.js';
44
import { handleError, sendAnalytics } from '../utils/analyticsUtils.js';
5-
6-
const bashScriptContent = `
7-
#!/bin/bash
8-
# Download frontend-blade-rules.mdc from GitHub and save to .cursor/rules
9-
TARGET_DIR=".cursor/rules"
10-
URL="https://raw.githubusercontent.com/razorpay/blade/master/packages/blade-mcp/cursorRules/frontend-blade-rules.mdc"
11-
FILE_PATH="$TARGET_DIR/frontend-blade-rules.mdc"
12-
# Create directory if it doesn't exist (works even if it already exists)
13-
mkdir -p "$TARGET_DIR"
14-
curl -sSL "$URL" -o "$FILE_PATH"
15-
`;
5+
import { cursorRuleCreationInstructions } from '../utils/cursorRulesUtils.js';
166

177
const createBladeCursorRulesToolName = 'create_blade_cursor_rules';
188

@@ -44,25 +34,7 @@ const createBladeCursorRulesToolCallback: ToolCallback<typeof createBladeCursorR
4434
content: [
4535
{
4636
type: 'text',
47-
text: `##
48-
**Instructions:**
49-
1. Change to the working directory: \`cd "${currentProjectRootDirectory}"\`
50-
2. Run the bash script below (copy and execute the commands from the script)
51-
3. This will create the cursor rules file at \`.cursor/rules/frontend-blade-rules.mdc\`
52-
53-
Run the following bash script to create cursor rules:
54-
55-
56-
**Bash Script:**
57-
58-
\`\`\`bash
59-
${bashScriptContent}
60-
\`\`\`
61-
62-
**Working Directory:** \`${currentProjectRootDirectory}\`
63-
64-
65-
`,
37+
text: `${cursorRuleCreationInstructions(currentProjectRootDirectory)}`,
6638
},
6739
],
6840
};

packages/blade-mcp/src/tools/getBladeComponentDocs.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import { getBladeDocsList } from '../utils/generalUtils.js';
99
import { handleError, sendAnalytics } from '../utils/analyticsUtils.js';
1010

1111
import { getBladeDocsResponseText } from '../utils/getBladeDocsResponseText.js';
12-
import { isCursorRuleFileMissing, areCursorRulesOutdated } from '../utils/cursorRulesUtils.js';
13-
import { createBladeCursorRulesToolName } from './createBladeCursorRules.js';
12+
import {
13+
isCursorRuleFileMissing,
14+
areCursorRulesOutdated,
15+
cursorRuleCreationInstructions,
16+
} from '../utils/cursorRulesUtils.js';
1417

1518
const bladeComponentsList = getBladeDocsList('components');
1619
const bladeComponentsListString = bladeComponentsList.join(', ');
@@ -29,7 +32,12 @@ const getBladeComponentDocsToolSchema = {
2932
.describe(
3033
"The working root directory of the consumer's project. Do not use root directory, do not use '.', only use absolute path to current directory",
3134
),
32-
clientName: z.enum(['claude', 'cursor', 'unknown']).default('unknown'),
35+
clientName: z
36+
.enum(['claude', 'cursor', 'unknown'])
37+
.default('unknown')
38+
.describe(
39+
'The name of the client that is calling the tool. It can be "claude", "cursor", or "unknown". Use "unknown" if you are not sure.',
40+
),
3341
cursorRuleVersion: z.string().describe(CHECK_CURSOR_RULES_DESCRIPTION),
3442
};
3543

@@ -50,17 +58,26 @@ const getBladeComponentDocsToolCallback: ToolCallback<typeof getBladeComponentDo
5058
}
5159

5260
if (isCursorRuleFileMissing(cursorRuleVersion, clientName)) {
53-
return handleError({
54-
toolName: getBladeComponentDocsToolName,
55-
mcpErrorMessage: `Cursor rules do not exist. Call \`${createBladeCursorRulesToolName}\` first.`,
56-
});
61+
return {
62+
content: [
63+
{
64+
type: 'text',
65+
text: `Cursor rules do not exist. Create them using the following instructions: \n\n
66+
${cursorRuleCreationInstructions(currentProjectRootDirectory)}`,
67+
},
68+
],
69+
};
5770
}
58-
5971
if (areCursorRulesOutdated(cursorRuleVersion, clientName)) {
60-
return handleError({
61-
toolName: getBladeComponentDocsToolName,
62-
mcpErrorMessage: `Cursor rules are outdated. Expected version: ${CURSOR_RULES_VERSION}. Current version: ${cursorRuleVersion}. Call \`${createBladeCursorRulesToolName}\` first to update cursor rules`,
63-
});
72+
return {
73+
content: [
74+
{
75+
type: 'text',
76+
text: `Cursor rules are outdated. Expected version: ${CURSOR_RULES_VERSION}. Current version: ${cursorRuleVersion}. Update them using the following instructions: \n\n
77+
${cursorRuleCreationInstructions(currentProjectRootDirectory)}`,
78+
},
79+
],
80+
};
6481
}
6582

6683
try {

packages/blade-mcp/src/tools/getBladeGeneralDocs.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import type { ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
55
import {
66
analyticsToolCallEventName,
77
GENERAL_KNOWLEDGEBASE_DIRECTORY,
8-
CURSOR_RULES_VERSION,
98
CHECK_CURSOR_RULES_DESCRIPTION,
9+
CURSOR_RULES_VERSION,
1010
} from '../utils/tokens.js';
1111

1212
import { getBladeDocsList } from '../utils/generalUtils.js';
1313
import { handleError, sendAnalytics } from '../utils/analyticsUtils.js';
1414
import { getBladeDocsResponseText } from '../utils/getBladeDocsResponseText.js';
15-
import { isCursorRuleFileMissing, areCursorRulesOutdated } from '../utils/cursorRulesUtils.js';
16-
import { createBladeCursorRulesToolName } from './createBladeCursorRules.js';
15+
import {
16+
isCursorRuleFileMissing,
17+
areCursorRulesOutdated,
18+
cursorRuleCreationInstructions,
19+
} from '../utils/cursorRulesUtils.js';
1720

1821
const bladeGeneralDocsList = getBladeDocsList('general');
1922

@@ -39,7 +42,12 @@ const getBladeGeneralDocsToolSchema = {
3942
.describe(
4043
"The working root directory of the consumer's project. Do not use root directory, do not use '.', only use absolute path to current directory",
4144
),
42-
clientName: z.enum(['claude', 'cursor', 'unknown']).default('unknown'),
45+
clientName: z
46+
.enum(['claude', 'cursor', 'unknown'])
47+
.default('unknown')
48+
.describe(
49+
'The name of the client that is calling the tool. It can be "claude", "cursor", or "unknown". Use "unknown" if you are not sure.',
50+
),
4351
cursorRuleVersion: z.string().describe(CHECK_CURSOR_RULES_DESCRIPTION),
4452
};
4553

@@ -61,17 +69,27 @@ const getBladeGeneralDocsToolCallback: ToolCallback<typeof getBladeGeneralDocsTo
6169
}
6270

6371
if (isCursorRuleFileMissing(cursorRuleVersion, clientName)) {
64-
return handleError({
65-
toolName: getBladeGeneralDocsToolName,
66-
mcpErrorMessage: `Cursor rules do not exist. Call \`${createBladeCursorRulesToolName}\` first.`,
67-
});
72+
return {
73+
content: [
74+
{
75+
type: 'text',
76+
text: `Cursor rules do not exist. Create them using the following instructions: \n\n
77+
${cursorRuleCreationInstructions(currentProjectRootDirectory)}`,
78+
},
79+
],
80+
};
6881
}
6982

7083
if (areCursorRulesOutdated(cursorRuleVersion, clientName)) {
71-
return handleError({
72-
toolName: getBladeGeneralDocsToolName,
73-
mcpErrorMessage: `Cursor rules are outdated. Expected version: ${CURSOR_RULES_VERSION}. Current version: ${cursorRuleVersion}. Call \`${createBladeCursorRulesToolName}\` first to update cursor rules`,
74-
});
84+
return {
85+
content: [
86+
{
87+
type: 'text',
88+
text: `Cursor rules are outdated. Expected version: ${CURSOR_RULES_VERSION}. Current version: ${cursorRuleVersion}. Update them using the following instructions: \n\n
89+
${cursorRuleCreationInstructions(currentProjectRootDirectory)}`,
90+
},
91+
],
92+
};
7593
}
7694

7795
try {

packages/blade-mcp/src/tools/getBladePatternDocs.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ import {
1212
import { getBladeDocsList } from '../utils/generalUtils.js';
1313
import { handleError, sendAnalytics } from '../utils/analyticsUtils.js';
1414
import { getBladeDocsResponseText } from '../utils/getBladeDocsResponseText.js';
15-
import { isCursorRuleFileMissing, areCursorRulesOutdated } from '../utils/cursorRulesUtils.js';
15+
import {
16+
isCursorRuleFileMissing,
17+
areCursorRulesOutdated,
18+
cursorRuleCreationInstructions,
19+
} from '../utils/cursorRulesUtils.js';
1620
import { getBladeComponentDocsToolName } from './getBladeComponentDocs.js';
17-
import { createBladeCursorRulesToolName } from './createBladeCursorRules.js';
1821

1922
const bladePatternsList = getBladeDocsList('patterns');
2023
const whichPatternToUseGuide = readFileSync(
@@ -39,7 +42,12 @@ const getBladePatternDocsToolSchema = {
3942
.describe(
4043
"The working root directory of the consumer's project. Do not use root directory, do not use '.', only use absolute path to current directory",
4144
),
42-
clientName: z.enum(['claude', 'cursor', 'unknown']).default('unknown'),
45+
clientName: z
46+
.enum(['claude', 'cursor', 'unknown'])
47+
.default('unknown')
48+
.describe(
49+
'The name of the client that is calling the tool. It can be "claude", "cursor", or "unknown". Use "unknown" if you are not sure.',
50+
),
4351
cursorRuleVersion: z.string().describe(CHECK_CURSOR_RULES_DESCRIPTION),
4452
};
4553

@@ -63,17 +71,26 @@ const getBladePatternDocsToolCallback: ToolCallback<typeof getBladePatternDocsTo
6371
}
6472

6573
if (isCursorRuleFileMissing(cursorRuleVersion, clientName)) {
66-
return handleError({
67-
toolName: getBladePatternDocsToolName,
68-
mcpErrorMessage: `Cursor rules do not exist. Call \`${createBladeCursorRulesToolName}\` first.`,
69-
});
74+
return {
75+
content: [
76+
{
77+
type: 'text',
78+
text: `Cursor rules do not exist. Create them using the following instructions: \n\n
79+
${cursorRuleCreationInstructions(currentProjectRootDirectory)}`,
80+
},
81+
],
82+
};
7083
}
71-
7284
if (areCursorRulesOutdated(cursorRuleVersion, clientName)) {
73-
return handleError({
74-
toolName: getBladePatternDocsToolName,
75-
mcpErrorMessage: `Cursor rules are outdated. Expected version: ${CURSOR_RULES_VERSION}. Current version: ${cursorRuleVersion}. Call \`${createBladeCursorRulesToolName}\` first to update cursor rules`,
76-
});
85+
return {
86+
content: [
87+
{
88+
type: 'text',
89+
text: `Cursor rules are outdated. Expected version: ${CURSOR_RULES_VERSION}. Current version: ${cursorRuleVersion}. Update them using the following instructions: \n\n
90+
${cursorRuleCreationInstructions(currentProjectRootDirectory)}`,
91+
},
92+
],
93+
};
7794
}
7895

7996
try {

packages/blade-mcp/src/utils/cursorRulesUtils.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,39 @@ export function areCursorRulesOutdated(
2525
): boolean {
2626
return cursorRuleVersion !== CURSOR_RULES_VERSION && clientName === 'cursor';
2727
}
28+
29+
const bashScriptContent = `
30+
#!/bin/bash
31+
# Download frontend-blade-rules.mdc from GitHub and save to .cursor/rules
32+
TARGET_DIR=".cursor/rules"
33+
URL="https://raw.githubusercontent.com/razorpay/blade/master/packages/blade-mcp/cursorRules/frontend-blade-rules.mdc"
34+
FILE_PATH="$TARGET_DIR/frontend-blade-rules.mdc"
35+
# Create directory if it doesn't exist (works even if it already exists)
36+
mkdir -p "$TARGET_DIR"
37+
curl -sSL "$URL" -o "$FILE_PATH"
38+
`;
39+
40+
/**
41+
*
42+
* Generates formatted instructions for creating cursor rules files in a project.
43+
* @param currentProjectRootDirectory - The working root directory of the consumer's project
44+
* @returns The instructions text for creating cursor rules
45+
*/
46+
47+
export function cursorRuleCreationInstructions(currentProjectRootDirectory: string): string {
48+
return `##
49+
**Instructions:**
50+
1. Change to the working directory: \`cd "${currentProjectRootDirectory}"\`
51+
2. Run the bash script below (copy and execute the commands from the script)
52+
3. This will create the cursor rules file at \`.cursor/rules/frontend-blade-rules.m
53+
Run the following bash script to create cursor rules:
54+
55+
56+
**Bash Script:**
57+
58+
\`\`\`bash
59+
${bashScriptContent}
60+
\`
61+
**Working Directory:** \`${currentProjectRootDirectory}\`
62+
`;
63+
}

0 commit comments

Comments
 (0)