Skip to content

Commit 0f5c502

Browse files
authored
Merge pull request #21 from yepcode/feature/skip-coding-rules
Add mcp option to ignore coding rules
2 parents 3b83721 + 24b6121 commit 0f5c502

4 files changed

Lines changed: 39 additions & 12 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ Executes code in YepCode's secure environment.
151151
YepCode MCP server supports the following options:
152152

153153
- `runCodeCleanup`: Skip the run_code cleanup. By default, run_code processes source code is removed after execution. If you want to keep it for audit purposes, you can use this option.
154+
- `skipCodingRules`: Skip including coding rules in the run_code tool definition. By default, JavaScript and Python coding rules from YepCode documentation are included in the tool schema to guide AI-generated code. If you want to skip this for faster tool initialization or smaller tool definitions, you can use this option.
154155

155156
Options can be passed as a comma-separated list in the `YEPCODE_MCP_OPTIONS` environment variable.
156157

@@ -189,7 +190,7 @@ If not specified, all built-in tools are enabled by default, but no process tool
189190
"args": ["-y", "@yepcode/mcp-server"],
190191
"env": {
191192
"YEPCODE_API_TOKEN": "your_api_token_here",
192-
"YEPCODE_MCP_OPTIONS": "runCodeCleanup",
193+
"YEPCODE_MCP_OPTIONS": "runCodeCleanup,skipCodingRules",
193194
"YEPCODE_MCP_TOOLS": "run_code,yc_api,mcp-tool,core"
194195
}
195196
}

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ const logger = new Logger("StdioServer", { logsToStderr: true });
1010
const main = async (): Promise<void> => {
1111
let tools: string[] | undefined;
1212
let runCodeCleanup = false;
13+
let skipCodingRules = false;
1314
if (process.env.YEPCODE_MCP_OPTIONS) {
1415
const mcpOptions = process.env.YEPCODE_MCP_OPTIONS.split(",");
1516
runCodeCleanup = mcpOptions.includes("runCodeCleanup");
17+
skipCodingRules = mcpOptions.includes("skipCodingRules");
1618
}
1719
if (process.env.YEPCODE_MCP_TOOLS) {
1820
tools = process.env.YEPCODE_MCP_TOOLS.split(",").map((tool) => tool.trim());
1921
}
2022

2123
const server = new YepCodeMcpServer(
2224
{},
23-
{ logsToStderr: true, tools, runCodeCleanup }
25+
{ logsToStderr: true, tools, runCodeCleanup, skipCodingRules }
2426
);
2527
try {
2628
const transport = new StdioServerTransport();

src/server.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,19 @@ class YepCodeMcpServer extends Server {
147147
private logger: Logger;
148148
private tools: string[];
149149
private runCodeCleanup: boolean;
150+
private skipCodingRules: boolean;
150151
constructor(
151152
config: YepCodeApiConfig,
152153
{
153154
logsToStderr = false,
154155
tools = DEFAULT_TOOL_TAGS,
155156
runCodeCleanup = false,
157+
skipCodingRules = false,
156158
}: {
157159
logsToStderr?: boolean;
158160
tools?: string[];
159161
runCodeCleanup?: boolean;
162+
skipCodingRules?: boolean;
160163
} = {}
161164
) {
162165
super(
@@ -175,6 +178,7 @@ class YepCodeMcpServer extends Server {
175178

176179
this.tools = tools;
177180
this.runCodeCleanup = runCodeCleanup;
181+
this.skipCodingRules = skipCodingRules;
178182
this.setupHandlers();
179183
this.setupErrorHandling();
180184

@@ -320,7 +324,11 @@ class YepCodeMcpServer extends Server {
320324
}
321325
if (this.tools.includes(RUN_CODE_TOOL_TAG)) {
322326
const envVars = await this.yepCodeEnv.getEnvVars();
323-
tools.push(...(await runCodeToolDefinitions(envVars)));
327+
tools.push(
328+
...(await runCodeToolDefinitions(envVars, {
329+
skipCodingRules: this.skipCodingRules,
330+
}))
331+
);
324332
}
325333

326334
let page = 0;

src/tools/run-code-tool-definitinos.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,30 @@ export const RunCodeOptionsSchema = z.object({
4747

4848
export const getCodingRules = async (): Promise<string> => {
4949
try {
50-
let rulesMdFile = await fetch(
51-
"https://yepcode.io/docs/yepcode-coding-rules.md"
50+
let jsRulesFile = await fetch(
51+
"https://yepcode.io/docs/ai-rules/code/javascript.md"
5252
).then((res) => res.text());
53-
rulesMdFile = rulesMdFile.substring(
54-
rulesMdFile.indexOf("## General Rules")
53+
jsRulesFile = jsRulesFile.substring(
54+
jsRulesFile.indexOf("# JavaScript Code Rules")
5555
);
56-
rulesMdFile = rulesMdFile.replace(
56+
jsRulesFile = jsRulesFile.replace(
57+
/(\[Section titled .*\]\(#.*\)\n)/g,
58+
""
59+
);
60+
let pythonRulesFile = await fetch(
61+
"https://yepcode.io/docs/ai-rules/code/python.md"
62+
).then((res) => res.text());
63+
pythonRulesFile = pythonRulesFile.substring(
64+
pythonRulesFile.indexOf("# Python Code Rules")
65+
);
66+
pythonRulesFile = pythonRulesFile.replace(
5767
/(\[Section titled .*\]\(#.*\)\n)/g,
5868
""
5969
);
60-
6170
return `Here you can find the general rules for YepCode coding:
6271
63-
${rulesMdFile}`;
72+
${jsRulesFile}
73+
${pythonRulesFile}`;
6474
} catch (error) {
6575
return "";
6676
}
@@ -132,8 +142,14 @@ export const ExecutionResultSchema = z.object({
132142

133143
export type ExecutionResultSchema = z.infer<typeof ExecutionResultSchema>;
134144

135-
export const runCodeToolDefinitions = async (envVars: EnvVar[]) => {
136-
const codingRules = await getCodingRules();
145+
export const runCodeToolDefinitions = async (
146+
envVars: EnvVar[],
147+
{ skipCodingRules = false }: { skipCodingRules?: boolean } = {}
148+
) => {
149+
let codingRules = "";
150+
if (!skipCodingRules) {
151+
codingRules = await getCodingRules();
152+
}
137153
return [
138154
{
139155
name: runCodeToolNames.runCode,

0 commit comments

Comments
 (0)