Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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"
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ const logger = new Logger("StdioServer", { logsToStderr: true });
const main = async (): Promise<void> => {
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());
}

const server = new YepCodeMcpServer(
{},
{ logsToStderr: true, tools, runCodeCleanup }
{ logsToStderr: true, tools, runCodeCleanup, skipCodingRules }
);
try {
const transport = new StdioServerTransport();
Expand Down
10 changes: 9 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -175,6 +178,7 @@ class YepCodeMcpServer extends Server {

this.tools = tools;
this.runCodeCleanup = runCodeCleanup;
this.skipCodingRules = skipCodingRules;
this.setupHandlers();
this.setupErrorHandling();

Expand Down Expand Up @@ -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;
Expand Down
34 changes: 25 additions & 9 deletions src/tools/run-code-tool-definitinos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,30 @@ export const RunCodeOptionsSchema = z.object({

export const getCodingRules = async (): Promise<string> => {
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 "";
}
Expand Down Expand Up @@ -132,8 +142,14 @@ export const ExecutionResultSchema = z.object({

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

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,
Expand Down