Skip to content

Commit 8ff3734

Browse files
refactor(http): clarify subscription rejection
Document why header validation precedes the unsupported-method rejection and use named SDK error constants in tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 06d5dda1-4086-4996-8d18-152e45e611b0
1 parent 5bbab3c commit 8ff3734

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

pkg/http/handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
223223
return
224224
}
225225

226+
// Let the SDK validate missing or mismatched method headers before the
227+
// middleware rejects a well-formed request as unsupported.
226228
if r.Header.Get(headers.MCPMethodHeader) == subscriptionsListenMethod {
227229
ghServer.AddReceivingMiddleware(rejectSubscriptionsListen)
228230
}

pkg/http/handler_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/github/github-mcp-server/pkg/translations"
2020
"github.com/github/github-mcp-server/pkg/utils"
2121
"github.com/go-chi/chi/v5"
22+
"github.com/modelcontextprotocol/go-sdk/jsonrpc"
2223
"github.com/modelcontextprotocol/go-sdk/mcp"
2324
"github.com/stretchr/testify/assert"
2425
"github.com/stretchr/testify/require"
@@ -937,18 +938,18 @@ func TestSubscriptionsListenIsRejected(t *testing.T) {
937938
name: "matching method header",
938939
methodHeader: subscriptionsListenMethod,
939940
expectedStatus: http.StatusNotFound,
940-
expectedJSONCode: -32601,
941+
expectedJSONCode: jsonrpc.CodeMethodNotFound,
941942
},
942943
{
943944
name: "missing method header",
944945
expectedStatus: http.StatusBadRequest,
945-
expectedJSONCode: -32020,
946+
expectedJSONCode: mcp.CodeHeaderMismatch,
946947
},
947948
{
948949
name: "mismatched method header",
949950
methodHeader: "tools/list",
950951
expectedStatus: http.StatusBadRequest,
951-
expectedJSONCode: -32020,
952+
expectedJSONCode: mcp.CodeHeaderMismatch,
952953
},
953954
}
954955

0 commit comments

Comments
 (0)