From 24b6121059d91562792c71049157348a138a0aab Mon Sep 17 00:00:00 2001 From: alvaro Date: Thu, 11 Dec 2025 13:27:45 +0100 Subject: [PATCH] Add mcp option to ignore coding rules --- README.md | 3 ++- src/index.ts | 4 ++- src/server.ts | 10 +++++++- src/tools/run-code-tool-definitinos.ts | 34 +++++++++++++++++++------- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index eaf98fb..dd58d09 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,7 @@ Executes code in YepCode's secure environment. YepCode MCP server supports the following options: - `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. +- `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. Options can be passed as a comma-separated list in the `YEPCODE_MCP_OPTIONS` environment variable. @@ -189,7 +190,7 @@ If not specified, all built-in tools are enabled by default, but no process tool "args": ["-y", "@yepcode/mcp-server"], "env": { "YEPCODE_API_TOKEN": "your_api_token_here", - "YEPCODE_MCP_OPTIONS": "runCodeCleanup", + "YEPCODE_MCP_OPTIONS": "runCodeCleanup,skipCodingRules", "YEPCODE_MCP_TOOLS": "run_code,yc_api,mcp-tool,core" } } diff --git a/src/index.ts b/src/index.ts index 5038398..1d3a287 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,9 +10,11 @@ const logger = new Logger("StdioServer", { logsToStderr: true }); const main = async (): Promise => { let tools: string[] | undefined; let runCodeCleanup = false; + let skipCodingRules = false; if (process.env.YEPCODE_MCP_OPTIONS) { const mcpOptions = process.env.YEPCODE_MCP_OPTIONS.split(","); runCodeCleanup = mcpOptions.includes("runCodeCleanup"); + skipCodingRules = mcpOptions.includes("skipCodingRules"); } if (process.env.YEPCODE_MCP_TOOLS) { tools = process.env.YEPCODE_MCP_TOOLS.split(",").map((tool) => tool.trim()); @@ -20,7 +22,7 @@ const main = async (): Promise => { const server = new YepCodeMcpServer( {}, - { logsToStderr: true, tools, runCodeCleanup } + { logsToStderr: true, tools, runCodeCleanup, skipCodingRules } ); try { const transport = new StdioServerTransport(); diff --git a/src/server.ts b/src/server.ts index 87d813e..f3b0b36 100644 --- a/src/server.ts +++ b/src/server.ts @@ -147,16 +147,19 @@ class YepCodeMcpServer extends Server { private logger: Logger; private tools: string[]; private runCodeCleanup: boolean; + private skipCodingRules: boolean; constructor( config: YepCodeApiConfig, { logsToStderr = false, tools = DEFAULT_TOOL_TAGS, runCodeCleanup = false, + skipCodingRules = false, }: { logsToStderr?: boolean; tools?: string[]; runCodeCleanup?: boolean; + skipCodingRules?: boolean; } = {} ) { super( @@ -175,6 +178,7 @@ class YepCodeMcpServer extends Server { this.tools = tools; this.runCodeCleanup = runCodeCleanup; + this.skipCodingRules = skipCodingRules; this.setupHandlers(); this.setupErrorHandling(); @@ -320,7 +324,11 @@ class YepCodeMcpServer extends Server { } if (this.tools.includes(RUN_CODE_TOOL_TAG)) { const envVars = await this.yepCodeEnv.getEnvVars(); - tools.push(...(await runCodeToolDefinitions(envVars))); + tools.push( + ...(await runCodeToolDefinitions(envVars, { + skipCodingRules: this.skipCodingRules, + })) + ); } let page = 0; diff --git a/src/tools/run-code-tool-definitinos.ts b/src/tools/run-code-tool-definitinos.ts index 20516a6..2529803 100644 --- a/src/tools/run-code-tool-definitinos.ts +++ b/src/tools/run-code-tool-definitinos.ts @@ -47,20 +47,30 @@ export const RunCodeOptionsSchema = z.object({ export const getCodingRules = async (): Promise => { try { - let rulesMdFile = await fetch( - "https://yepcode.io/docs/yepcode-coding-rules.md" + let jsRulesFile = await fetch( + "https://yepcode.io/docs/ai-rules/code/javascript.md" ).then((res) => res.text()); - rulesMdFile = rulesMdFile.substring( - rulesMdFile.indexOf("## General Rules") + jsRulesFile = jsRulesFile.substring( + jsRulesFile.indexOf("# JavaScript Code Rules") ); - rulesMdFile = rulesMdFile.replace( + jsRulesFile = jsRulesFile.replace( + /(\[Section titled “.*”\]\(#.*\)\n)/g, + "" + ); + let pythonRulesFile = await fetch( + "https://yepcode.io/docs/ai-rules/code/python.md" + ).then((res) => res.text()); + pythonRulesFile = pythonRulesFile.substring( + pythonRulesFile.indexOf("# Python Code Rules") + ); + pythonRulesFile = pythonRulesFile.replace( /(\[Section titled “.*”\]\(#.*\)\n)/g, "" ); - return `Here you can find the general rules for YepCode coding: - ${rulesMdFile}`; +${jsRulesFile} +${pythonRulesFile}`; } catch (error) { return ""; } @@ -132,8 +142,14 @@ export const ExecutionResultSchema = z.object({ export type ExecutionResultSchema = z.infer; -export const runCodeToolDefinitions = async (envVars: EnvVar[]) => { - const codingRules = await getCodingRules(); +export const runCodeToolDefinitions = async ( + envVars: EnvVar[], + { skipCodingRules = false }: { skipCodingRules?: boolean } = {} +) => { + let codingRules = ""; + if (!skipCodingRules) { + codingRules = await getCodingRules(); + } return [ { name: runCodeToolNames.runCode,