Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Requests with "id": null are run like notifications

Aberta
#601 0 comentários 0 reações 1 responsável Ver no GitHub

Mantenedores costumam responder em até 1 dia

@koic já está trabalhando nisso.

Desde 14/10/2026.

  • #612 de @koic — aberto

Avaliação

Esta issue ainda não foi avaliada.

Descrição

bug

I'm wiring the SDK into a Rails app (stateless Streamable HTTP, JSON responses) and noticed that a request with "id": null isn't rejected. The server treats it like a notification: the method runs, but no response is produced, so over HTTP the client gets a 202 Accepted with an empty body.

For a tool that changes data, that's a write the client never hears about. The spec rules null ids out for requests:

  • Requests MUST include a string or integer ID.
  • Unlike base JSON-RPC, the ID MUST NOT be null.

(Basic Protocol, Requests, same wording in 2026-07-28)

Repro with 1.7.0 (main at 9d12f51 behaves the same):

require "mcp"

calls = 0
echo = MCP::Tool.define(
  name: "echo",
  description: "Echoes the text back",
  input_schema: { properties: { text: { type: "string" } }, required: ["text"] },
) do |text:, server_context: nil|
  calls += 1
  MCP::Tool::Response.new([{ type: "text", text: text }])
end

server = MCP::Server.new(name: "repro", version: "1.0.0", tools: [echo], capabilities: { tools: {} })

server.handle_json('{"jsonrpc":"2.0","id":null,"method":"tools/call","params":{"name":"echo","arguments":{"text":"hi"}}}')
# => nil
server.handle_json('{"jsonrpc":"2.0","method":"tools/call","params":{"name":"echo","arguments":{"text":"hi"}}}')
# => nil

calls # => 2

JsonRpcHandler.valid_id? accepts nil on purpose (the error message says "or be an integer or null"), which fits plain JSON-RPC but not MCP.

The second call, without any id, is a notification by JSON-RPC rules, so it's a slightly different case. But tools/call isn't a notification in MCP, and the Streamable HTTP transport allows a server to answer a notification it can't accept with an HTTP error (e.g. 400). Running it silently seems like the riskiest option.

What I'd expect:

  • "id": null is answered with Invalid Request (-32600) and the method doesn't run.
  • A request method sent without an id is refused, or at least not executed.
Linguagem predominante
Ruby
Estrelas
924
Forks
136
Merge médio
1d 5h
PRs com merge (30d)
37

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de modelcontextprotocol/ruby-sdk

Todas as issues de modelcontextprotocol/ruby-sdk

Issues semelhantes

Mais issues de Ruby

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.