HTTP client sends handler exception messages back to the server

未关闭
#660 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@atesgoral 已经在做这个了。

开始于 2026年11月6日。

  • #664 来自 @atesgoral —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
ruby

调研方向

Read lib/mcp/client/http.rb:1192-1206, comparing the ServerRequestError handling with the unexpected exception path in MCP::Client::HTTP#dispatch_server_request. Check the existing client HTTP tests for server request callbacks and add coverage that confirms unexpected exceptions return a generic message while ServerRequestError retains its explicit message. The issue links open pull request #664, so the work is already under way.

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

描述

bug

When a handler registered with on_server_request (for example the on_elicitation callback) raises, MCP::Client::HTTP#dispatch_server_request answers the server with "Internal error handling #{method} request: #{e.message}" (http.rb:1198-1206). Exception messages often contain local details such as file paths, host names or library internals.

The server side stopped sending exception messages to clients in #486, for #485. This is the same problem on the client side. ServerRequestError keeps its explicit message (http.rb:1192-1197), which is correct because the handler chose that text.

Repro

Run from the repository root with bundle exec ruby -I lib repro.rb:

require "mcp"
require "mcp/client/http"
require "webmock"
include WebMock::API
WebMock.enable!

url = "http://localhost:9292/mcp"
reply = nil
stub_request(:post, url).to_return do |request|
  body = JSON.parse(request.body)
  if body["method"] == "tools/list"
    events = [
      { jsonrpc: "2.0", id: "s1", method: "elicitation/create", params: { message: "Name?", requestedSchema: { type: "object", properties: {} } } },
      { jsonrpc: "2.0", id: body["id"], result: { tools: [] } },
    ]
    { status: 200, headers: { "Content-Type" => "text/event-stream" }, body: events.map { |event| "data: #{event.to_json}\n\n" }.join }
  else
    reply = body
    { status: 202 }
  end
end

transport = MCP::Client::HTTP.new(url: url)
transport.on_server_request("elicitation/create") { |_params| File.read("/etc/example-app/ui.yml") }
transport.send_request(request: { jsonrpc: "2.0", id: "1", method: "tools/list" })

p reply["error"]

Expected: a generic message, for example {"code" => -32603, "message" => "Internal error"}.

Actual:

{"code" => -32603, "message" => "Internal error handling elicitation/create request: No such file or directory @ rb_sysopen - /etc/example-app/ui.yml"}
Suggested fix

Send a fixed message such as "Internal error" (optionally with the method name) for unexpected exceptions, and make the exception available to the application locally, for example through a reporter callback or a log line. Keep the current behavior for ServerRequestError.

主要语言
Ruby
星标
940
派生
143
平均合并
1 天 3 小时
30 天内合并 PR
47

环境准备

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

从这里开始

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

modelcontextprotocol/ruby-sdk 的其他 Issue

查看 modelcontextprotocol/ruby-sdk 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

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