Skip to content

Conversation

@adamwulf
Copy link
Contributor

Also allow AnyRequest to decode with missing params, as id is required for a Request, but params are not. Ping should return an {}, and ListTools cursor parameter is optional.

… decode with missing params, as id is required for a Request, but params are not. Ping should return an {}, and ListTools cursor parameter is optional.
@mattt
Copy link
Contributor

mattt commented Mar 17, 2025

Hi @adamwulf. Thanks so much for your PR! Digging into this some more, I came up with a more generalized solution with #17.

Comment on lines -404 to +408
// Ping
withMethodHandler(Ping.self) { _ in return Empty() }
// Ping. Specification shows empty dictionary as the response:
// https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/utilities/ping/
withMethodHandler(Ping.self) { params in
return .object([:])
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Empty is already encoded as an empty JSON object ({}), so we should be good here.

@mattt
Copy link
Contributor

mattt commented Mar 17, 2025

@adamwulf Thanks again for your help. I just merged #17 and released it in 0.4.1. Please give it a look, and let me know if things still aren't working as expected.

@mattt mattt closed this Mar 17, 2025
@adamwulf
Copy link
Contributor Author

Hey @mattt, #17 gets very close but doesn't quite solve what I was running into. When the Server decodes a request in its read loop, it first decodes to AnyRequest, which is Request<AnyMethod> where the Result = Value. If the params is missing in the request, this decoding fails and it falls through to decode AnyMessage which succeeds.

Below is a screenshot in the debugger when this request comes in, fails, and gets marked as a Message. This request is from Cursor 0.47.5.

CleanShot 2025-03-17 at 12 12 36@2x

@mattt
Copy link
Contributor

mattt commented Mar 18, 2025

@adamwulf Thanks for following up. I'll take another look at that today.

@mattt
Copy link
Contributor

mattt commented Mar 18, 2025

@adamwulf I just opened up #22, which should resolve that. I added a test case specifically for the tools/list you're seeing here: https://github.com/loopwork-ai/mcp-swift-sdk/pull/22/files#diff-cc7ad403202e8c51952ae2111771e0f3e8d46b4f7cf00bb1cb3e226b89e2f9e7R222

This is now live in 0.5.0, so please give that a try at your convenience.

@adamwulf
Copy link
Contributor Author

Thanks! I'll give that a test later today and verify. I think that it might also want to check for Value parameters and use Value.null if params is not found

@mattt
Copy link
Contributor

mattt commented Mar 18, 2025

@adamwulf Thanks! I just opened #23, which adds some more test coverage specifically around the type-erased requests. If 0.5.0 isn't working as expected, try 94301ff from that branch.

@adamwulf
Copy link
Contributor Author

Unfortunately neither of these are working for me. I'm going to see if I can get a unit test to mirror the behavior I'm seeing in my simple mcp command line app. I'll hopefully have time to do that tomorrow afternoon.

@adamwulf
Copy link
Contributor Author

I was able to spend some more time tonight, and I added two tests to #24 as well as an explanation of what's happening when i caught it in the debugger.

@mattt
Copy link
Contributor

mattt commented Mar 19, 2025

@adamwulf Brilliant! Moving over to that thread.

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.

2 participants