Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`createMcpHandler` is validation-free; bare fetch mounts can skip the Host/Origin guards the framework helpers install |

未关闭
#2,844 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
nodejs, typescript

调研方向

The issue is about adding Host/Origin validation to createMcpHandler in packages/server/src/server/createMcpHandler.ts. Start by reading the existing JSDoc and the docs/serving/http.md guide to understand the current validation-free behavior. Look at the hostHeaderValidationResponse and originValidationResponse utilities to see how validation is applied. The goal is to design an API option or wrapper that adds these guards, while keeping an escape hatch for reverse-proxy deployments. Test by mounting the handler in a fetch-native runtime like Workers or Deno.

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

描述

v2

Static review of public source at commit 603217008710. No traffic was sent to any MCP environment.

createMcpHandler intentionally performs no Host/Origin (or token) checks — documented in the JSDoc and in docs/serving/http.md. Framework helpers (createMcpExpressApp / Hono / Fastify) arm those checks for loopback. The bare fetch entry does not:

packages/server/src/server/createMcpHandler.ts (doc comment on the export):

* When mounting bare on a fetch-native runtime,
* put Origin/Host validation in front of the handler — the entry itself is
* deliberately validation-free:
*
* const rejected =
*     hostHeaderValidationResponse(request, localhostAllowedHostnames()) ??
*     originValidationResponse(request, localhostAllowedOrigins());
* return rejected ?? handler.fetch(request);

On Workers / Deno / Bun, export default handler (as shown earlier in the same guide for “Mount it on your runtime”) is a one-liner that never installs those guards unless the reader continues to the later section. That is a footgun relative to the Express path, where loopback protection is automatic.

Suggested change:

  • Offer createMcpHandler(factory, { allowedHosts, allowedOrigins }) (or a withLocalhostProtection(handler) wrapper) that applies hostHeaderValidationResponse / originValidationResponse before fetch.
  • Or make the quickstart export default example always show the validation wrapper first.
  • Keep a documented escape hatch for authenticated reverse-proxy deployments.

Severity: low–medium / API footgun and defense-in-depth (complements finding #1 on non-loopback Express/Hono binds). No proof-of-concept.

Happy to send a focused PR if useful.

主要语言
TypeScript
星标
13.6k
派生
2.3k
平均合并
1 天 15 小时
30 天内合并 PR
51

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

modelcontextprotocol/typescript-sdk 的其他 Issue

查看 modelcontextprotocol/typescript-sdk 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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