Skip to content

Conversation

@findleyr
Copy link
Contributor

Audit all cases where params must not be null, and enforce this using methodInfo via a new methodFlags bitfield that parameterizes method requirements. Write extensive conformance tests catching all the (server-side) crashes that were possible.

We should go further and validate schema against the spec, but that is more indirect, more complicated, and potentially slower. For now we adopt this more explicit approach.

Still TODO in a subsequent CL: verify the client side of this with client conformance tests.

Additionally, improve some error messages that were redundant or leaked internal implementation details.

Fixes #195

samthanawalla
samthanawalla previously approved these changes Jul 31, 2025
mcp/shared.go Outdated
if req.ID.IsValid() {
return methodInfo{}, fmt.Errorf("%w: unexpected id for %q", jsonrpc2.ErrInvalidRequest, req.Method)
}
} else if !req.ID.IsValid() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the logic is harder to follow with this change. I think the 2 un-nested if statements was easier to read. (But up to you)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point; unnested.
(also fixed the id/ID inconsistency in these messages)

Audit all cases where params must not be null, and enforce this using
methodInfo via a new methodFlags bitfield that parameterizes method
requirements. Write extensive conformance tests catching all the
(server-side) crashes that were possible.

We should go further and validate schema against the spec, but that is
more indirect, more complicated, and potentially slower. For now we
adopt this more explicit approach.

Still TODO in a subsequent CL: verify the client side of this with
client conformance tests.

Additionally, improve some error messages that were redundant or leaked
internal implementation details.

Fixes modelcontextprotocol#195
@findleyr findleyr merged commit b34ba21 into modelcontextprotocol:main Jul 31, 2025
3 checks passed
davidleitw added a commit to davidleitw/go-sdk that referenced this pull request Jul 31, 2025
Complements the methodFlags system from modelcontextprotocol#210 with additional unit tests:
- Tests nil RawMessage and explicit JSON null handling in unmarshalParams
- Tests edge cases with different JSON types (empty string, array, number, boolean)
- Validates proper error handling for required vs optional params with methodFlags
- Provides focused unit test coverage alongside existing conformance tests

The tests verify that the panic vulnerability from modelcontextprotocol#186 is properly handled
by the upstream methodFlags implementation.
davidleitw added a commit to davidleitw/go-sdk that referenced this pull request Aug 4, 2025
Complements the methodFlags system from modelcontextprotocol#210 with additional unit tests:
- Tests nil RawMessage and explicit JSON null handling in unmarshalParams
- Tests edge cases with different JSON types (empty string, array, number, boolean)
- Validates proper error handling for required vs optional params with methodFlags
- Provides focused unit test coverage alongside existing conformance tests

The tests verify that the panic vulnerability from modelcontextprotocol#186 is properly handled
by the upstream methodFlags implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"initialize" panics without "params" field

2 participants