Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MCP Client Validation and Protocol Compliance #13

Open
tzolov opened this issue Feb 18, 2025 · 0 comments · May be fixed by #14
Open

Improve MCP Client Validation and Protocol Compliance #13

tzolov opened this issue Feb 18, 2025 · 0 comments · May be fixed by #14
Assignees
Labels
bug Something isn't working client lifecycle

Comments

@tzolov
Copy link
Contributor

tzolov commented Feb 18, 2025

Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.

Expected Behavior

The MCP client should:

  1. Properly validate its state and server capabilities before operations
  2. Only expose client-appropriate methods
  3. Handle protocol version negotiation clearly

Example of expected validation:

// Client should validate state before operations
public Mono<McpSchema.CallToolResult> callTool(McpSchema.CallToolRequest request) {
    if (!this.isInitialized()) {
        return Mono.error(new McpError("Client must be initialized before calling tools"));
    }
    if (this.serverCapabilities.tools() == null) {
        return Mono.error(new McpError("Server does not provide tools capability"));
    }
    return this.mcpSession.sendRequest(...);
}

Current Behavior

  1. Client operations don't validate initialization state or server capabilities, potentially leading to runtime errors
  2. Client exposes server-side notification methods that shouldn't be called by clients:
// These methods should not exist in client
public Mono<Void> sendResourcesListChanged()
public Mono<Void> promptListChangedNotification()
  1. Protocol version handling lacks clear documentation and validation

Context

This issue affects developers using the MCP client in several ways:

  • Lack of validation can lead to confusing runtime errors when client isn't properly initialized
  • Exposed server methods can lead to protocol violations if called by client applications
  • Unclear protocol version handling can cause compatibility issues

Current workaround:

  • Developers must manually check initialization state and capabilities before operations, but this is error-prone and leads to duplicated code.
@tzolov tzolov added bug Something isn't working client lifecycle labels Feb 18, 2025
@tzolov tzolov self-assigned this Feb 18, 2025
tzolov added a commit that referenced this issue Feb 18, 2025
Add client initialization and capability validation checks

- New isInitialized() method to check client state
- Validate server capabilities before tool/resource operations
- Add clear error messages for common failure cases
- Remove server-side notification methods from client: sendResourcesListChanged(), promptListChangedNotification()
- Improve protocol version handling
- Testing improvements and new initialization tests

Resolves #13

Signed-off-by: Christian Tzolov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working client lifecycle
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant