Skip to content

Conversation

@mattt
Copy link
Contributor

@mattt mattt commented Mar 17, 2025

Alternative to #13

Some methods allow for params to be omitted. For example, here's the specification for
PingRequest:

PingRequest schema
"PingRequest": {
    "description": "A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected.",
    "properties": {
        "method": {
            "const": "ping",
            "type": "string"
        },
        "params": {
            "additionalProperties": {},
            "properties": {
                "_meta": {
                    "properties": {
                        "progressToken": {
                            "$ref": "#/definitions/ProgressToken",
                            "description": "If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications."
                        }
                    },
                    "type": "object"
                }
            },
            "type": "object"
        }
    },
    "required": [
        "method"
    ],
    "type": "object"
},

This PR makes it so that requests for the methods ping, prompts/list, resources/list, and tools/list can be correctly decoded when the params is omitted.

@mattt mattt changed the title Allow params field to be omitted in requests for methods with empty parameters Allow params field to be omitted in requests for methods that don't require them Mar 17, 2025
@mattt mattt merged commit 6f1f65a into main Mar 17, 2025
1 check passed
@mattt mattt deleted the mattt/optional-params-ping branch March 17, 2025 12:26
devyhan pushed a commit to devyhan/swift-sdk that referenced this pull request Apr 4, 2025
… require them (modelcontextprotocol#17)

* Allow `params` field to be omitted in requests for methods with empty parameters

* Add ping request to roundtrip test

* Generalize decoding of non-required parameters
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