mcp-go icon indicating copy to clipboard operation
mcp-go copied to clipboard

added the configurable items sse_read_timeout and headers to mcp-client

Open resurgence72 opened this issue 8 months ago • 4 comments

Added the option design mode to mcp-client and added the configurable items sse_read_timeout and headers. The readSSE() method and sendRequest() method take effect with the SSEMCPClient object, respectively.

When I was looking at Python-sdk, I found that the mcp-client can specify headers and sse_read_timeout configurations when initializing objects. In my usage scenario, it is necessary for the mcp-client object to carry a custom request header. I think this is a universal scenario.

Summary by CodeRabbit

  • New Features

    • Introduced configuration options to customize connection headers.
    • Added the ability to set a read timeout for Server-Sent Events (SSE) connections.
    • Enhanced error handling for scenarios where the SSE read exceeds the specified timeout duration.
  • Changes

    • Updated JSON serialization to ensure the Properties field is always included in the output for the ToolInputSchema.

resurgence72 avatar Mar 18 '25 13:03 resurgence72

Walkthrough

The pull request enhances the SSEMCPClient in the client/sse.go file by introducing functional options for configuration, including custom HTTP headers and read timeout settings. The constructor is updated to accept these options, and the SSEMCPClient struct is modified to include new fields. Methods for reading SSE events and sending requests are revised to handle timeout scenarios and integrate custom headers. Additionally, the Properties field in the ToolInputSchema struct in mcp/tools.go is modified to always be included in the JSON output.

Changes

File(s) Change Summary
client/sse.go - Added functional options: WithHeaders (to set custom HTTP headers) and WithSSEReadTimeout (to set a custom read timeout).
- Modified NewSSEMCPClient to accept variadic options.
- Updated SSEMCPClient struct with new fields: headers map[string]string and sseReadTimeout time.Duration.
- Updated readSSE to utilize a context with timeout and handle timeout errors.
- Enhanced sendRequest to use custom HTTP headers.
mcp/tools.go - Updated Properties field in ToolInputSchema to ensure it is always included in JSON output by changing the JSON tag from json:"properties,omitempty" to json:"properties".
✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Mar 18 '25 13:03 coderabbitai[bot]

I introduced another commit in the current pr, sorry, I'm not familiar with the whole git process.

New submission to solve the problem (https://github.com/junjiem/dify-plugin-agent-mcp_sse/issues/1). in general, the current MCP - server InputSchema standards do not agree with MCP, Its InputSchema.properties cannot be empty in mcp. image

but in mcp-go tool.go image

As a result, when I used dify to interconnect with the parameterless tool written based on mcp-go, the mcp-client failed to pass the verification, resulting in an error, namely, the above issues

resurgence72 avatar Mar 21 '25 09:03 resurgence72

hi @ezynda3 could you please help check this PR? I hope we can work together as soon as possible. At present, there are already some conflicts. Do you need me to solve them? Thank you very much!

resurgence72 avatar Mar 25 '25 04:03 resurgence72

hi @ezynda3 could you please help check this PR? I hope we can work together as soon as possible. At present, there are already some conflicts. Do you need me to solve them? Thank you very much!

Yes please fix the merge conflicts and I can have a look at the PR

ezynda3 avatar Mar 25 '25 12:03 ezynda3