[Bug] [BanyanDB] MCP server ignores .env values and silently accepts malformed numeric/TRANSPORT settings

已关闭
#14,194 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

已经有一个关联 PR 被合并了。

  • #1460 来自 @wanjinhao1 —— 已合并

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
node.js, typescript
领域
backend

调研方向

Start in mcp/src/config.ts and mcp/src/index.ts, where configuration is read and .env is loaded; then inspect the MCP tests and docs/operation/mcp/setup.md mentioned in the issue. Reproduce the three cases from the issue and check how the existing MCP_PORT range validation reports errors. Done means .env values are applied, malformed numeric values and unsupported TRANSPORT values fail clearly, and tests cover each case; a pull request is already open.

由索引模型根据 Issue 内容生成。

描述

bug
Search before asking
  • I had searched in the issues and found no similar issues.
Apache SkyWalking Component

BanyanDB (apache/skywalking-banyandb)

What happened

While setting up the BanyanDB MCP server (mcp/, main at adc78b88) I found three config problems. All are silent: the server starts, but with values the user didn't ask for.

  1. Values in .env are ignored. src/index.ts calls dotenv.config() in its body, but src/config.ts reads process.env at module load, and ES module imports run first. By the time .env is loaded, every exported config value is already fixed.
  2. Numeric settings are parsed leniently. parseInt stops at the first non-digit, so units or typos are cut off without an error: MCP_MAX_BODY_BYTES=1MiB → 1 byte, MCP_RATE_LIMIT_WINDOW_MS=60s → 60 ms, MCP_PORT=3000abc → 3000.
  3. TRANSPORT isn't validated. index.ts only checks TRANSPORT === 'http', so HTTP, Http or a typo silently falls back to stdio.
What you expected to happen

Values from .env are applied, and invalid values fail at startup with a clear error. The code already does this for an out-of-range MCP_PORT and for values <= 0, so a value like "1MiB" or "HTTP" should be rejected the same way instead of being silently changed.

How to reproduce

In mcp/ on main (adc78b88):

# problems 2 and 3
cat > _check1.mts <<'EOF'
const c = await import('./src/config.ts');
console.log({ MCP_PORT: c.MCP_PORT, MCP_MAX_BODY_BYTES: c.MCP_MAX_BODY_BYTES, MCP_RATE_LIMIT_WINDOW_MS: c.MCP_RATE_LIMIT_WINDOW_MS, TRANSPORT: c.TRANSPORT });
EOF
MCP_PORT=3000abc MCP_MAX_BODY_BYTES=1MiB MCP_RATE_LIMIT_WINDOW_MS=60s TRANSPORT=HTTP npx tsx _check1.mts

Output:

{ MCP_PORT: 3000, MCP_MAX_BODY_BYTES: 1, MCP_RATE_LIMIT_WINDOW_MS: 60, TRANSPORT: 'HTTP' }
# problem 1 (same import order as src/index.ts)
printf 'MCP_PORT=4555\nTRANSPORT=http\n' > /tmp/test.env
cat > _check2.mts <<'EOF'
import dotenv from 'dotenv';
import { MCP_PORT, TRANSPORT } from './src/config.ts';
dotenv.config({ path: '/tmp/test.env', quiet: true });
console.log({ config: { MCP_PORT, TRANSPORT }, env: { MCP_PORT: process.env.MCP_PORT, TRANSPORT: process.env.TRANSPORT } });
EOF
npx tsx _check2.mts

Output:

{ config: { MCP_PORT: 3000, TRANSPORT: 'stdio' }, env: { MCP_PORT: '4555', TRANSPORT: 'http' } }
Anything else

Happens every time. A possible fix, contained to mcp/src:

  • load .env before config.ts is evaluated (e.g. import 'dotenv/config' as the first import in index.ts, or call dotenv.config() at the top of config.ts);
  • parse integers strictly (the whole string must be digits) in parsePositiveInteger and for MCP_PORT;
  • accept only stdio / http for TRANSPORT (case-insensitive) and fail otherwise;
  • unit tests for each case, and a note about .env in docs/operation/mcp/setup.md.

Related history: the review of apache/skywalking-banyandb#1010 noted that a non-numeric MCP_PORT becomes NaN and that the docs mentioned streamable-http while the code only accepts http; #1036 then added the MCP_PORT range check. The cases above (partial numbers like "3000abc"/"1MiB", "HTTP" in a different case, and .env being loaded after config.ts) are still open on main.

Are you willing to submit a pull request to fix on your own?
  • Yes I am willing to submit a pull request on my own!
Code of Conduct
主要语言
Java
星标
25k
派生
6.6k
平均合并
12 小时 16 分钟
30 天内合并 PR
43

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/skywalking 的其他 Issue

查看 apache/skywalking 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。