Skip to content

Commit 2c98213

Browse files
authored
Merge pull request #8 from yepcode/feature/YEP-3000
YEP-3000 Improve MCP tools filter (mcp-server)
2 parents acf7646 + f60ec6f commit 2c98213

5 files changed

Lines changed: 101 additions & 51 deletions

File tree

README.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,36 +150,58 @@ Executes code in YepCode's secure environment.
150150

151151
YepCode MCP server supports the following options:
152152

153-
- Disable the run_code tool: In some cases, you may want to disable the `run_code` tool. For example, if you want to use the MCP server as a provider only for the existing tools in your YepCode account.
154-
- 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.
153+
- `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.
155154

156-
Options can be passed as a comma-separated list in the `YEPCODE_MCP_OPTIONS` environment variable or as a query parameter in the MCP server URL.
155+
Options can be passed as a comma-separated list in the `YEPCODE_MCP_OPTIONS` environment variable.
156+
157+
##### Tool Selection
158+
159+
You can control which tools are enabled by setting the `YEPCODE_MCP_TOOLS` environment variable with a comma-separated list of tool categories and process tags:
160+
161+
**Built-in tool categories:**
162+
- `run_code`: Enables the code execution tool
163+
- `executions`: Enables execution management tools
164+
- `env_vars`: Enables environment variable management tools
165+
- `storage`: Enables storage management tools
166+
167+
**Process tags:**
168+
- Any tag used in your YepCode processes (e.g., `mcp-tool`, `core`, `api`, `automation`, etc.)
169+
- When you specify a process tag, all processes with that tag will be exposed as individual MCP tools
170+
- Process tools will be named `run_ycp_<process_slug>` (or `run_ycp_<process_id>` if the name is longer than 60 characters)
171+
172+
If not specified, all built-in tools are enabled by default, but no process tools will be exposed.
157173

158174
```typescript
159-
// SSE server configuration
175+
// SSE server configuration with options
160176
{
161177
"mcpServers": {
162178
"yepcode-mcp-server": {
163-
"url": "https://cloud.yepcode.io/mcp/sk-c2E....RD/sse?mcpOptions=disableRunCodeTool,runCodeCleanup"
179+
"url": "https://cloud.yepcode.io/mcp/sk-c2E....RD/sse?mcpOptions=runCodeCleanup&tools=run_code,storage,env_vars,core,api"
164180
}
165181
}
166182
}
167183

168-
// NPX configuration
184+
// NPX configuration with options
169185
{
170186
"mcpServers": {
171187
"yepcode-mcp-server": {
172188
"command": "npx",
173189
"args": ["-y", "@yepcode/mcp-server"],
174190
"env": {
175191
"YEPCODE_API_TOKEN": "your_api_token_here",
176-
"YEPCODE_MCP_OPTIONS": "disableRunCodeTool,runCodeCleanup"
192+
"YEPCODE_MCP_OPTIONS": "runCodeCleanup",
193+
"YEPCODE_MCP_TOOLS": "run_code,storage,env_vars,core,api"
177194
}
178195
}
179196
}
180197
}
181198
```
182199

200+
**Example scenarios:**
201+
- `YEPCODE_MCP_TOOLS=run_code,storage` - Only enables built-in code execution and storage tools
202+
- `YEPCODE_MCP_TOOLS=core,automation` - Only exposes processes tagged with "core" or "automation" as tools
203+
- `YEPCODE_MCP_TOOLS=run_code,storage,core` - Enables built-in tools plus all processes tagged with "core"
204+
183205
### Environment Management
184206

185207
#### set_env_var
@@ -288,10 +310,17 @@ Deletes a file from YepCode storage.
288310

289311
### Process Execution
290312

291-
The MCP server can expose your YepCode Processes as individual MCP tools, making them directly accessible to AI assistants. This feature is enabled by just adding the `mcp-tool` tag to your process (see our docs to learn more about [process tags](https://yepcode.io/docs/processes/tags)).
313+
The MCP server can expose your YepCode Processes as individual MCP tools, making them directly accessible to AI assistants. This feature is enabled by specifying process tags in the `YEPCODE_MCP_TOOLS` environment variable.
314+
315+
**How it works:**
316+
1. Tag your YepCode processes with any tag (e.g., `core`, `api`, `automation`, `mcp-tool`, etc.)
317+
2. Add those tags to the `YEPCODE_MCP_TOOLS` environment variable
318+
3. All processes with the specified tags will be exposed as individual MCP tools
292319

293320
There will be a tool for each exposed process: `run_ycp_<process_slug>` (or `run_ycp_<process_id>` if tool name is longer than 60 characters).
294321

322+
For more information about process tags, see our [process tags documentation](https://yepcode.io/docs/processes/tags).
323+
295324
#### run_ycp_<process_slug>
296325

297326
```typescript

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
},
5151
"dependencies": {
5252
"@modelcontextprotocol/sdk": "^1.17.0",
53-
"@yepcode/run": "^1.8.0",
53+
"@yepcode/run": "^1.9.0",
5454
"dotenv": "^16.4.7",
5555
"zod": "^3.24.2"
5656
},

src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ import { getVersion } from "./utils.js";
88
const logger = new Logger("StdioServer", { logsToStderr: true });
99

1010
const main = async (): Promise<void> => {
11-
let disableRunCodeTool = false;
11+
let tools: string[] | undefined;
1212
let runCodeCleanup = false;
1313
if (process.env.YEPCODE_MCP_OPTIONS) {
1414
const mcpOptions = process.env.YEPCODE_MCP_OPTIONS.split(",");
15-
disableRunCodeTool = mcpOptions.includes("disableRunCodeTool");
1615
runCodeCleanup = mcpOptions.includes("runCodeCleanup");
1716
}
17+
if (process.env.YEPCODE_MCP_TOOLS) {
18+
tools = process.env.YEPCODE_MCP_TOOLS.split(",").map((tool) => tool.trim());
19+
}
20+
1821
const server = new YepCodeMcpServer(
1922
{},
20-
{ logsToStderr: true, disableRunCodeTool, runCodeCleanup }
23+
{ logsToStderr: true, tools, runCodeCleanup }
2124
);
2225
try {
2326
const transport = new StdioServerTransport();

src/server.ts

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ import {
5050

5151
const RUN_PROCESS_TOOL_NAME_PREFIX = "run_ycp_";
5252
const RUN_PROCESS_TOOL_TAG = "mcp-tool";
53+
const RUN_CODE_TOOL_TAG = "run_code";
54+
const EXECUTIONS_TOOL_TAG = "executions";
55+
const ENV_VARS_TOOL_TAG = "env_vars";
56+
const STORAGE_TOOL_TAG = "storage";
57+
58+
const DEFAULT_TOOL_TAGS = [
59+
RUN_CODE_TOOL_TAG,
60+
EXECUTIONS_TOOL_TAG,
61+
ENV_VARS_TOOL_TAG,
62+
STORAGE_TOOL_TAG,
63+
RUN_PROCESS_TOOL_TAG,
64+
];
5365

5466
dotenv.config();
5567

@@ -58,17 +70,17 @@ class YepCodeMcpServer extends Server {
5870
private yepCodeEnv: YepCodeEnv;
5971
private yepCodeApi: YepCodeApi;
6072
private logger: Logger;
61-
private disableRunCodeTool: boolean;
73+
private tools: string[];
6274
private runCodeCleanup: boolean;
6375
constructor(
6476
config: YepCodeApiConfig,
6577
{
6678
logsToStderr = false,
67-
disableRunCodeTool = false,
79+
tools = DEFAULT_TOOL_TAGS,
6880
runCodeCleanup = false,
6981
}: {
7082
logsToStderr?: boolean;
71-
disableRunCodeTool?: boolean;
83+
tools?: string[];
7284
runCodeCleanup?: boolean;
7385
} = {}
7486
) {
@@ -86,7 +98,7 @@ class YepCodeMcpServer extends Server {
8698
}
8799
);
88100

89-
this.disableRunCodeTool = disableRunCodeTool;
101+
this.tools = tools;
90102
this.runCodeCleanup = runCodeCleanup;
91103
this.setupHandlers();
92104
this.setupErrorHandling();
@@ -216,48 +228,54 @@ class YepCodeMcpServer extends Server {
216228
private setupToolHandlers(): void {
217229
this.setRequestHandler(ListToolsRequestSchema, async () => {
218230
this.logger.info(`Handling ListTools request`);
219-
const tools = [
220-
...envVarsToolDefinitions,
221-
...storageToolDefinitions,
222-
...getExecutionToolDefinitions,
223-
];
224-
225-
if (!this.disableRunCodeTool) {
231+
const tools = [];
232+
if (this.tools.includes(EXECUTIONS_TOOL_TAG)) {
233+
tools.push(...getExecutionToolDefinitions);
234+
}
235+
if (this.tools.includes(STORAGE_TOOL_TAG)) {
236+
tools.push(...storageToolDefinitions);
237+
}
238+
if (this.tools.includes(ENV_VARS_TOOL_TAG)) {
239+
tools.push(...envVarsToolDefinitions);
240+
}
241+
if (this.tools.includes(RUN_CODE_TOOL_TAG)) {
226242
const envVars = await this.yepCodeEnv.getEnvVars();
227243
tools.push(...(await runCodeToolDefinitions(envVars)));
228244
}
229245

230246
let page = 0;
231247
let limit = 100;
232248
while (true) {
233-
const processes = await this.yepCodeApi.getProcesses({ page, limit });
249+
const processes = await this.yepCodeApi.getProcesses({
250+
page,
251+
limit,
252+
tags: this.tools,
253+
});
234254
this.logger.info(`Found ${processes?.data?.length} processes`);
235255
if (!processes.data) {
236256
break;
237257
}
238258
tools.push(
239-
...processes.data
240-
.filter((process) => process.tags?.includes(RUN_PROCESS_TOOL_TAG))
241-
.map((process) => {
242-
const inputSchema = zodToJsonSchema(RunProcessSchema) as any;
243-
if (!isEmpty(process.parametersSchema)) {
244-
inputSchema.properties.parameters = process.parametersSchema;
245-
} else {
246-
delete inputSchema.properties.parameters;
247-
}
248-
let toolName = `${RUN_PROCESS_TOOL_NAME_PREFIX}${process.slug}`;
249-
if (toolName.length > 60) {
250-
toolName = `${RUN_PROCESS_TOOL_NAME_PREFIX}${process.id}`;
251-
}
252-
return {
253-
name: toolName,
254-
title: process.name,
255-
description: `${process.name}${
256-
process.description ? ` - ${process.description}` : ""
257-
}`,
258-
inputSchema,
259-
};
260-
})
259+
...processes.data.map((process) => {
260+
const inputSchema = zodToJsonSchema(RunProcessSchema) as any;
261+
if (!isEmpty(process.parametersSchema)) {
262+
inputSchema.properties.parameters = process.parametersSchema;
263+
} else {
264+
delete inputSchema.properties.parameters;
265+
}
266+
let toolName = `${RUN_PROCESS_TOOL_NAME_PREFIX}${process.slug}`;
267+
if (toolName.length > 60) {
268+
toolName = `${RUN_PROCESS_TOOL_NAME_PREFIX}${process.id}`;
269+
}
270+
return {
271+
name: toolName,
272+
title: process.name,
273+
description: `${process.name}${
274+
process.description ? ` - ${process.description}` : ""
275+
}`,
276+
inputSchema,
277+
};
278+
})
261279
);
262280
if (!processes.hasNextPage) {
263281
break;
@@ -312,7 +330,7 @@ class YepCodeMcpServer extends Server {
312330

313331
switch (request.params.name) {
314332
case runCodeToolNames.runCode:
315-
if (this.disableRunCodeTool) {
333+
if (!this.tools.includes(RUN_CODE_TOOL_TAG)) {
316334
this.logger.error("Run code tool is disabled");
317335
throw new McpError(
318336
ErrorCode.MethodNotFound,

0 commit comments

Comments
 (0)