Skip to content

Commit 1b588f7

Browse files
committed
test: add comprehensive test coverage for MCP parser
- Added tests for all new MCP methods from 2025-06-18 specification - Added edge case tests for error handling and malformed inputs - Added tests for JSON-RPC notifications (messages without ID) - Improved test coverage from ~66% to 91.7% for pkg/mcp - All parser functions now have 83-100% coverage
1 parent 82bc34a commit 1b588f7

File tree

2 files changed

+553
-2
lines changed

2 files changed

+553
-2
lines changed

pkg/mcp/parser.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,25 @@ func parseMCPRequest(bodyBytes []byte) *ParsedMCPRequest {
136136
return nil
137137
}
138138

139-
// Handle only request messages
139+
// Handle only request messages (both calls with ID and notifications without ID)
140140
req, ok := msg.(*jsonrpc2.Request)
141141
if !ok {
142+
// Response or error messages are not parsed here
142143
return nil
143144
}
144145

145146
// Extract resource ID and arguments based on the method
146147
resourceID, arguments := extractResourceAndArguments(req.Method, req.Params)
147148

149+
// Determine the ID - will be nil for notifications
150+
var id interface{}
151+
if req.ID.IsValid() {
152+
id = req.ID.Raw()
153+
}
154+
148155
return &ParsedMCPRequest{
149156
Method: req.Method,
150-
ID: req.ID.Raw(),
157+
ID: id,
151158
Params: req.Params,
152159
ResourceID: resourceID,
153160
Arguments: arguments,

0 commit comments

Comments
 (0)