Skip to content

Commit 69c4ea2

Browse files
committed
feat: ask cursor to get filename
1 parent 359615c commit 69c4ea2

File tree

5 files changed

+26
-30
lines changed

5 files changed

+26
-30
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { handleError, sendAnalytics } from '../utils/analyticsUtils.js';
1414
const createBladeCursorRulesToolName = 'create_blade_cursor_rules';
1515

1616
const createBladeCursorRulesToolDescription =
17-
'Creates the cursor rules for blade to help with code generation. Returns the cursor rules file content that should be created. Call this before get_blade_docs and while creating a new blade project (only when using cursor and when the frontend-blade-rules-v{version}.mdc rule does not already exist).';
17+
'Creates the cursor rules for blade to help with code generation. Returns the cursor rules file content that should be created. Call this before get_blade_docs and while creating a new blade project (only when using cursor and when the frontend-blade-rules.mdc rule does not already exist).';
1818

1919
const createBladeCursorRulesToolSchema = {
2020
currentProjectRootDirectory: z
@@ -57,9 +57,8 @@ const createBladeCursorRulesToolCallback: ToolCallback<typeof createBladeCursorR
5757
5858
**Instructions:**
5959
1. Create the directory if it doesn't exist: \`.cursor/rules/\`
60-
2. Create a new file named \`${cursorRulesFileName}\` in that directory .
61-
3. if their is any other file with name frontend-blade-rules-v{version}.mdc delete it first and create a new file. it should only have 1 file with frontend-blade-rules
62-
4. Copy the content below into the file
60+
2. Create a new file named \`${cursorRulesFileName}\` in that directory.
61+
3. Copy the content below into the file
6362
6463
**Cursor Rules Version:** ${CURSOR_RULES_VERSION}
6564

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { basename } from 'path';
22
import { z } from 'zod';
33
import type { ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
4-
import { analyticsToolCallEventName, getCursorRulesFileName } from '../utils/tokens.js';
4+
import { analyticsToolCallEventName, CURSOR_RULES_VERSION } from '../utils/tokens.js';
55
import { getBladeDocsList } from '../utils/generalUtils.js';
66
import { handleError, sendAnalytics } from '../utils/analyticsUtils.js';
77

@@ -26,18 +26,18 @@ const getBladeComponentDocsToolSchema = {
2626
"The working root directory of the consumer's project. Do not use root directory, do not use '.', only use absolute path to current directory",
2727
),
2828
clientName: z.enum(['claude', 'cursor', 'unknown']).default('unknown'),
29-
cursorRuleFileName: z
29+
cursorRuleVersion: z
3030
.string()
3131
.describe(
32-
'get the name of blade cursor rules file. You can use grep to find it: `grep -l "rules_version:" .cursor/rules/*.mdc` or search for files matching `frontend-blade-rules-v*.mdc` in `.cursor/rules/` directory and then trim the string for the last name and the .mdc extension (e.g., "frontend-blade-rules-v0.0.8"). if nothing is found send 0',
32+
'get the version from the blade cursor rules file. The file should be named `frontend-blade-rules.mdc` in `.cursor/rules/` directory. Extract the version from the `rules_version:` field at the start of the file (e.g., "0.0.8"). If the file does not exist, send 0',
3333
),
3434
};
3535

3636
const getBladeComponentDocsToolCallback: ToolCallback<typeof getBladeComponentDocsToolSchema> = ({
3737
componentsList,
3838
currentProjectRootDirectory,
3939
clientName,
40-
cursorRuleFileName,
40+
cursorRuleVersion,
4141
}) => {
4242
const components = componentsList.split(',').map((s) => s.trim());
4343
const invalidComponents = components.filter((comp) => !bladeComponentsList.includes(comp));
@@ -49,18 +49,17 @@ const getBladeComponentDocsToolCallback: ToolCallback<typeof getBladeComponentDo
4949
});
5050
}
5151

52-
if (cursorRuleFileName === '0' && clientName === 'cursor') {
52+
if (cursorRuleVersion === '0' && clientName === 'cursor') {
5353
return handleError({
5454
toolName: getBladeComponentDocsToolName,
5555
mcpErrorMessage: `Cursor rules do not exist. Call \`${createBladeCursorRulesToolName}\` first.`,
5656
});
5757
}
5858

59-
const expectedFileName = getCursorRulesFileName().replace('.mdc', '');
60-
if (cursorRuleFileName !== expectedFileName && clientName === 'cursor') {
59+
if (cursorRuleVersion !== CURSOR_RULES_VERSION && clientName === 'cursor') {
6160
return handleError({
6261
toolName: getBladeComponentDocsToolName,
63-
mcpErrorMessage: `Cursor rules are outdated. Expected file name: ${expectedFileName}.mdc. Call \`${createBladeCursorRulesToolName}\` first to update cursor rules`,
62+
mcpErrorMessage: `Cursor rules are outdated. Expected version: ${CURSOR_RULES_VERSION}. Current version: ${cursorRuleVersion}. Call \`${createBladeCursorRulesToolName}\` first to update cursor rules`,
6463
});
6564
}
6665

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
55
import {
66
analyticsToolCallEventName,
77
GENERAL_KNOWLEDGEBASE_DIRECTORY,
8-
getCursorRulesFileName,
8+
CURSOR_RULES_VERSION,
99
} from '../utils/tokens.js';
1010

1111
import { getBladeDocsList } from '../utils/generalUtils.js';
@@ -38,18 +38,18 @@ const getBladeGeneralDocsToolSchema = {
3838
"The working root directory of the consumer's project. Do not use root directory, do not use '.', only use absolute path to current directory",
3939
),
4040
clientName: z.enum(['claude', 'cursor', 'unknown']).default('unknown'),
41-
cursorRuleFileName: z
41+
cursorRuleVersion: z
4242
.string()
4343
.describe(
44-
'get the name of blade cursor rules file. You can use grep to find it: `grep -l "rules_version:" .cursor/rules/*.mdc` or search for files matching `frontend-blade-rules-v*.mdc` in `.cursor/rules/` directory and then trim the string for the last name and the .mdc extension (e.g., "frontend-blade-rules-v0.0.8"). if nothing is found send 0',
44+
'get the version from the blade cursor rules file. The file should be named `frontend-blade-rules.mdc` in `.cursor/rules/` directory. Extract the version from the `rules_version:` field at the start of the file (e.g., "0.0.8"). If the file does not exist, send 0',
4545
),
4646
};
4747

4848
const getBladeGeneralDocsToolCallback: ToolCallback<typeof getBladeGeneralDocsToolSchema> = ({
4949
topicsList,
5050
currentProjectRootDirectory,
5151
clientName,
52-
cursorRuleFileName,
52+
cursorRuleVersion,
5353
}) => {
5454
const topics = topicsList.split(',').map((s) => s.trim());
5555
const invalidTopics = topics.filter((topic) => !bladeGeneralDocsList.includes(topic));
@@ -62,18 +62,17 @@ const getBladeGeneralDocsToolCallback: ToolCallback<typeof getBladeGeneralDocsTo
6262
});
6363
}
6464

65-
if (cursorRuleFileName === '0' && clientName === 'cursor') {
65+
if (cursorRuleVersion === '0' && clientName === 'cursor') {
6666
return handleError({
6767
toolName: getBladeGeneralDocsToolName,
6868
mcpErrorMessage: `Cursor rules do not exist. Call \`${createBladeCursorRulesToolName}\` first.`,
6969
});
7070
}
7171

72-
const expectedFileName = getCursorRulesFileName().replace('.mdc', '');
73-
if (cursorRuleFileName !== expectedFileName && clientName === 'cursor') {
72+
if (cursorRuleVersion !== CURSOR_RULES_VERSION && clientName === 'cursor') {
7473
return handleError({
7574
toolName: getBladeGeneralDocsToolName,
76-
mcpErrorMessage: `Cursor rules are outdated. Expected file name: ${expectedFileName}.mdc. Call \`${createBladeCursorRulesToolName}\` first to update cursor rules`,
75+
mcpErrorMessage: `Cursor rules are outdated. Expected version: ${CURSOR_RULES_VERSION}. Current version: ${cursorRuleVersion}. Call \`${createBladeCursorRulesToolName}\` first to update cursor rules`,
7776
});
7877
}
7978

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
55
import {
66
analyticsToolCallEventName,
77
PATTERNS_KNOWLEDGEBASE_DIRECTORY,
8-
getCursorRulesFileName,
8+
CURSOR_RULES_VERSION,
99
} from '../utils/tokens.js';
1010

1111
import { getBladeDocsList } from '../utils/generalUtils.js';
@@ -38,18 +38,18 @@ const getBladePatternDocsToolSchema = {
3838
"The working root directory of the consumer's project. Do not use root directory, do not use '.', only use absolute path to current directory",
3939
),
4040
clientName: z.enum(['claude', 'cursor', 'unknown']).default('unknown'),
41-
cursorRuleFileName: z
41+
cursorRuleVersion: z
4242
.string()
4343
.describe(
44-
'get the name of blade cursor rules file. You can use grep to find it: `grep -l "rules_version:" .cursor/rules/*.mdc` or search for files matching `frontend-blade-rules-v*.mdc` in `.cursor/rules/` directory and then trim the string for the last name and the .mdc extension (e.g., "frontend-blade-rules-v0.0.8"). if nothing is found send 0',
44+
'get the version from the blade cursor rules file. The file should be named `frontend-blade-rules.mdc` in `.cursor/rules/` directory. Extract the version from the `rules_version:` field at the start of the file (e.g., "0.0.8"). If the file does not exist, send 0',
4545
),
4646
};
4747

4848
const getBladePatternDocsToolCallback: ToolCallback<typeof getBladePatternDocsToolSchema> = ({
4949
patternsList,
5050
currentProjectRootDirectory,
5151
clientName,
52-
cursorRuleFileName,
52+
cursorRuleVersion,
5353
}) => {
5454
const components = patternsList.split(',').map((s) => s.trim());
5555
const invalidComponents = components.filter((comp) => !bladePatternsList.includes(comp));
@@ -64,18 +64,17 @@ const getBladePatternDocsToolCallback: ToolCallback<typeof getBladePatternDocsTo
6464
});
6565
}
6666

67-
if (cursorRuleFileName === '0' && clientName === 'cursor') {
67+
if (cursorRuleVersion === '0' && clientName === 'cursor') {
6868
return handleError({
6969
toolName: getBladePatternDocsToolName,
7070
mcpErrorMessage: `Cursor rules do not exist. Call \`${createBladeCursorRulesToolName}\` first.`,
7171
});
7272
}
7373

74-
const expectedFileName = getCursorRulesFileName().replace('.mdc', '');
75-
if (cursorRuleFileName !== expectedFileName && clientName === 'cursor') {
74+
if (cursorRuleVersion !== CURSOR_RULES_VERSION && clientName === 'cursor') {
7675
return handleError({
7776
toolName: getBladePatternDocsToolName,
78-
mcpErrorMessage: `Cursor rules are outdated. Expected file name: ${expectedFileName}.mdc. Call \`${createBladeCursorRulesToolName}\` first to update cursor rules`,
77+
mcpErrorMessage: `Cursor rules are outdated. Expected version: ${CURSOR_RULES_VERSION}. Current version: ${cursorRuleVersion}. Call \`${createBladeCursorRulesToolName}\` first to update cursor rules`,
7978
});
8079
}
8180

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ const BLADE_CURSOR_RULES_FILE_PATH = join(
1717
'frontend-blade-rules.mdc',
1818
);
1919

20-
// Generate cursor rules file name with version
20+
// Generate cursor rules file name (fixed name, version is in file content)
2121
const getCursorRulesFileName = (): string => {
22-
return `frontend-blade-rules-v${CURSOR_RULES_VERSION}.mdc`;
22+
return `frontend-blade-rules.mdc`;
2323
};
2424

2525
const CONSUMER_CURSOR_RULES_RELATIVE_PATH = `.cursor/rules/${getCursorRulesFileName()}`;

0 commit comments

Comments
 (0)