Skip to content

Commit f2d1095

Browse files
Will-hxwclaude
andcommitted
fix(everything): require key parameter for get-env tool
Prevent leaking all process.env variables by requiring a specific key. This addresses a security concern where the tool was returning the entire environment without any parameter or filtering. Issue: #3986 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent e95f39e commit f2d1095

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

src/everything/tools/get-env.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,50 @@ const name = "get-env";
66
const config = {
77
title: "Print Environment Tool",
88
description:
9-
"Returns all environment variables, helpful for debugging MCP server configuration",
10-
inputSchema: {},
9+
"Returns the value of a specific environment variable, helpful for debugging MCP server configuration",
10+
inputSchema: {
11+
type: "object",
12+
properties: {
13+
key: {
14+
type: "string",
15+
description:
16+
"The name of the environment variable to retrieve (e.g., 'PATH', 'HOME', 'USER')",
17+
},
18+
},
19+
required: ["key"],
20+
},
1121
};
1222

1323
/**
1424
* Registers the 'get-env' tool.
1525
*
16-
* The registered tool Retrieves and returns the environment variables
17-
* of the current process as a JSON-formatted string encapsulated in a text response.
26+
* The registered tool retrieves and returns the value of a specific
27+
* environment variable from the current process.
1828
*
1929
* @param {McpServer} server - The McpServer instance where the tool will be registered.
2030
* @returns {void}
2131
*/
2232
export const registerGetEnvTool = (server: McpServer) => {
2333
server.registerTool(name, config, async (args): Promise<CallToolResult> => {
34+
const { key } = args as { key: string };
35+
const value = process.env[key];
36+
37+
if (value === undefined) {
38+
return {
39+
content: [
40+
{
41+
type: "text",
42+
text: `Environment variable '${key}' is not set.`,
43+
},
44+
],
45+
};
46+
}
47+
2448
return {
2549
content: [
2650
{
2751
type: "text",
28-
text: JSON.stringify(process.env, null, 2),
52+
text: `${key}=${value}`,
2953
},
3054
],
3155
};

0 commit comments

Comments
 (0)