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

feat: support go1.18

Open HChengH opened this issue 8 months ago • 1 comments

Hi! I'm wondering if maybe the package can support even a lower go version such as go1.18 so I forked the repo and tested by myself. It seems fine (passed all tests) after I modified the go version and did some minor changes (for i := range 5 is supported > go1.22 so I changed it back to the old school way). Looking forward to receiving suggestions / comments. If you guys don't think it's necessary to downgrade to 1.18 then I can simply use the forked one in my project. (Sorry, my project is a very old one still using 1.18)

The test output as following

@HChengH ➜ /workspaces/mcp-go (feat/support1.18) $ go test -v './...'
go: downloading github.com/yosida95/uritemplate/v3 v3.0.2
go: downloading github.com/stretchr/testify v1.9.0
go: downloading github.com/google/uuid v1.6.0
go: downloading github.com/davecgh/go-spew v1.1.1
go: downloading github.com/pmezard/go-difflib v1.0.0
go: downloading gopkg.in/yaml.v3 v3.0.1
=== RUN   TestSSEMCPClient
=== RUN   TestSSEMCPClient/Can_create_client
=== RUN   TestSSEMCPClient/Can_initialize_and_make_requests
=== RUN   TestSSEMCPClient/Handles_errors_properly
=== RUN   TestSSEMCPClient/CallTool
--- PASS: TestSSEMCPClient (0.01s)
    --- PASS: TestSSEMCPClient/Can_create_client (0.00s)
    --- PASS: TestSSEMCPClient/Can_initialize_and_make_requests (0.01s)
    --- PASS: TestSSEMCPClient/Handles_errors_properly (0.00s)
    --- PASS: TestSSEMCPClient/CallTool (0.00s)
=== RUN   TestStdioMCPClient
=== RUN   TestStdioMCPClient/Initialize
=== RUN   TestStdioMCPClient/Ping
=== RUN   TestStdioMCPClient/ListResources
=== RUN   TestStdioMCPClient/ReadResource
=== RUN   TestStdioMCPClient/Subscribe_and_Unsubscribe
=== RUN   TestStdioMCPClient/ListPrompts
=== RUN   TestStdioMCPClient/GetPrompt
=== RUN   TestStdioMCPClient/ListTools
=== RUN   TestStdioMCPClient/CallTool
=== RUN   TestStdioMCPClient/SetLevel
=== RUN   TestStdioMCPClient/Complete
=== RUN   TestStdioMCPClient/CheckLogs
--- PASS: TestStdioMCPClient (0.25s)
    --- PASS: TestStdioMCPClient/Initialize (0.00s)
    --- PASS: TestStdioMCPClient/Ping (0.00s)
    --- PASS: TestStdioMCPClient/ListResources (0.00s)
    --- PASS: TestStdioMCPClient/ReadResource (0.00s)
    --- PASS: TestStdioMCPClient/Subscribe_and_Unsubscribe (0.00s)
    --- PASS: TestStdioMCPClient/ListPrompts (0.00s)
    --- PASS: TestStdioMCPClient/GetPrompt (0.00s)
    --- PASS: TestStdioMCPClient/ListTools (0.00s)
    --- PASS: TestStdioMCPClient/CallTool (0.00s)
    --- PASS: TestStdioMCPClient/SetLevel (0.00s)
    --- PASS: TestStdioMCPClient/Complete (0.00s)
    --- PASS: TestStdioMCPClient/CheckLogs (0.00s)
PASS
ok      github.com/mark3labs/mcp-go/client      0.268s
?       github.com/mark3labs/mcp-go/examples/custom_context     [no test files]
?       github.com/mark3labs/mcp-go/examples/everything [no test files]
?       github.com/mark3labs/mcp-go/examples/filesystem_stdio_client    [no test files]
=== RUN   TestToolWithBothSchemasError
--- PASS: TestToolWithBothSchemasError (0.00s)
=== RUN   TestToolWithRawSchema
--- PASS: TestToolWithRawSchema (0.00s)
=== RUN   TestUnmarshalToolWithRawSchema
--- PASS: TestUnmarshalToolWithRawSchema (0.00s)
=== RUN   TestUnmarshalToolWithoutRawSchema
--- PASS: TestUnmarshalToolWithoutRawSchema (0.00s)
=== RUN   TestToolWithObjectAndArray
--- PASS: TestToolWithObjectAndArray (0.00s)
PASS
ok      github.com/mark3labs/mcp-go/mcp 0.004s
=== RUN   TestMCPServer_NewMCPServer
--- PASS: TestMCPServer_NewMCPServer (0.00s)
=== RUN   TestMCPServer_Capabilities
=== RUN   TestMCPServer_Capabilities/No_capabilities
=== RUN   TestMCPServer_Capabilities/All_capabilities
=== RUN   TestMCPServer_Capabilities/Specific_capabilities
--- PASS: TestMCPServer_Capabilities (0.00s)
    --- PASS: TestMCPServer_Capabilities/No_capabilities (0.00s)
    --- PASS: TestMCPServer_Capabilities/All_capabilities (0.00s)
    --- PASS: TestMCPServer_Capabilities/Specific_capabilities (0.00s)
=== RUN   TestMCPServer_Tools
=== RUN   TestMCPServer_Tools/SetTools_sends_no_notifications/tools/list_changed_without_active_sessions
=== RUN   TestMCPServer_Tools/SetTools_sends_single_notifications/tools/list_changed_with_one_active_session
=== RUN   TestMCPServer_Tools/SetTools_sends_single_notifications/tools/list_changed_per_each_active_session
=== RUN   TestMCPServer_Tools/AddTool_sends_multiple_notifications/tools/list_changed
=== RUN   TestMCPServer_Tools/DeleteTools_sends_single_notifications/tools/list_changed
--- PASS: TestMCPServer_Tools (1.00s)
    --- PASS: TestMCPServer_Tools/SetTools_sends_no_notifications/tools/list_changed_without_active_sessions (1.00s)
    --- PASS: TestMCPServer_Tools/SetTools_sends_single_notifications/tools/list_changed_with_one_active_session (0.00s)
    --- PASS: TestMCPServer_Tools/SetTools_sends_single_notifications/tools/list_changed_per_each_active_session (0.00s)
    --- PASS: TestMCPServer_Tools/AddTool_sends_multiple_notifications/tools/list_changed (0.00s)
    --- PASS: TestMCPServer_Tools/DeleteTools_sends_single_notifications/tools/list_changed (0.00s)
=== RUN   TestMCPServer_HandleValidMessages
=== RUN   TestMCPServer_HandleValidMessages/Initialize_request
=== RUN   TestMCPServer_HandleValidMessages/Ping_request
=== RUN   TestMCPServer_HandleValidMessages/List_resources
--- PASS: TestMCPServer_HandleValidMessages (0.00s)
    --- PASS: TestMCPServer_HandleValidMessages/Initialize_request (0.00s)
    --- PASS: TestMCPServer_HandleValidMessages/Ping_request (0.00s)
    --- PASS: TestMCPServer_HandleValidMessages/List_resources (0.00s)
=== RUN   TestMCPServer_HandlePagination
=== RUN   TestMCPServer_HandlePagination/List_resources_with_cursor
--- PASS: TestMCPServer_HandlePagination (0.00s)
    --- PASS: TestMCPServer_HandlePagination/List_resources_with_cursor (0.00s)
=== RUN   TestMCPServer_HandleNotifications
--- PASS: TestMCPServer_HandleNotifications (0.00s)
=== RUN   TestMCPServer_SendNotificationToClient
=== RUN   TestMCPServer_SendNotificationToClient/no_active_session
=== RUN   TestMCPServer_SendNotificationToClient/uninit_session
=== RUN   TestMCPServer_SendNotificationToClient/active_session
=== RUN   TestMCPServer_SendNotificationToClient/session_with_blocked_channel
--- PASS: TestMCPServer_SendNotificationToClient (0.00s)
    --- PASS: TestMCPServer_SendNotificationToClient/no_active_session (0.00s)
    --- PASS: TestMCPServer_SendNotificationToClient/uninit_session (0.00s)
    --- PASS: TestMCPServer_SendNotificationToClient/active_session (0.00s)
    --- PASS: TestMCPServer_SendNotificationToClient/session_with_blocked_channel (0.00s)
=== RUN   TestMCPServer_PromptHandling
=== RUN   TestMCPServer_PromptHandling/List_prompts
=== RUN   TestMCPServer_PromptHandling/Get_prompt
=== RUN   TestMCPServer_PromptHandling/Get_prompt_with_missing_argument
--- PASS: TestMCPServer_PromptHandling (0.00s)
    --- PASS: TestMCPServer_PromptHandling/List_prompts (0.00s)
    --- PASS: TestMCPServer_PromptHandling/Get_prompt (0.00s)
    --- PASS: TestMCPServer_PromptHandling/Get_prompt_with_missing_argument (0.00s)
=== RUN   TestMCPServer_HandleInvalidMessages
=== RUN   TestMCPServer_HandleInvalidMessages/Invalid_JSON
=== RUN   TestMCPServer_HandleInvalidMessages/Invalid_method
=== RUN   TestMCPServer_HandleInvalidMessages/Invalid_parameters
=== RUN   TestMCPServer_HandleInvalidMessages/Missing_JSONRPC_version
--- PASS: TestMCPServer_HandleInvalidMessages (0.00s)
    --- PASS: TestMCPServer_HandleInvalidMessages/Invalid_JSON (0.00s)
    --- PASS: TestMCPServer_HandleInvalidMessages/Invalid_method (0.00s)
    --- PASS: TestMCPServer_HandleInvalidMessages/Invalid_parameters (0.00s)
    --- PASS: TestMCPServer_HandleInvalidMessages/Missing_JSONRPC_version (0.00s)
=== RUN   TestMCPServer_HandleUndefinedHandlers
=== RUN   TestMCPServer_HandleUndefinedHandlers/Undefined_tool
=== RUN   TestMCPServer_HandleUndefinedHandlers/Undefined_prompt
=== RUN   TestMCPServer_HandleUndefinedHandlers/Undefined_resource
--- PASS: TestMCPServer_HandleUndefinedHandlers (0.00s)
    --- PASS: TestMCPServer_HandleUndefinedHandlers/Undefined_tool (0.00s)
    --- PASS: TestMCPServer_HandleUndefinedHandlers/Undefined_prompt (0.00s)
    --- PASS: TestMCPServer_HandleUndefinedHandlers/Undefined_resource (0.00s)
=== RUN   TestMCPServer_HandleMethodsWithoutCapabilities
=== RUN   TestMCPServer_HandleMethodsWithoutCapabilities/Tools_without_capabilities
=== RUN   TestMCPServer_HandleMethodsWithoutCapabilities/Prompts_without_capabilities
=== RUN   TestMCPServer_HandleMethodsWithoutCapabilities/Resources_without_capabilities
--- PASS: TestMCPServer_HandleMethodsWithoutCapabilities (0.00s)
    --- PASS: TestMCPServer_HandleMethodsWithoutCapabilities/Tools_without_capabilities (0.00s)
    --- PASS: TestMCPServer_HandleMethodsWithoutCapabilities/Prompts_without_capabilities (0.00s)
    --- PASS: TestMCPServer_HandleMethodsWithoutCapabilities/Resources_without_capabilities (0.00s)
=== RUN   TestMCPServer_Instructions
=== RUN   TestMCPServer_Instructions/No_instructions
=== RUN   TestMCPServer_Instructions/With_instructions
=== RUN   TestMCPServer_Instructions/With_multiline_instructions
--- PASS: TestMCPServer_Instructions (0.00s)
    --- PASS: TestMCPServer_Instructions/No_instructions (0.00s)
    --- PASS: TestMCPServer_Instructions/With_instructions (0.00s)
    --- PASS: TestMCPServer_Instructions/With_multiline_instructions (0.00s)
=== RUN   TestMCPServer_ResourceTemplates
=== RUN   TestMCPServer_ResourceTemplates/Get_resource_template
--- PASS: TestMCPServer_ResourceTemplates (0.00s)
    --- PASS: TestMCPServer_ResourceTemplates/Get_resource_template (0.00s)
=== RUN   TestMCPServer_WithHooks
--- PASS: TestMCPServer_WithHooks (0.00s)
=== RUN   TestSSEServer
=== RUN   TestSSEServer/Can_instantiate
=== RUN   TestSSEServer/Can_send_and_receive_messages
=== RUN   TestSSEServer/Can_handle_multiple_sessions
=== RUN   TestSSEServer/Can_be_used_as_http.Handler
=== RUN   TestSSEServer/Works_with_middleware
=== RUN   TestSSEServer/Works_with_custom_mux
=== RUN   TestSSEServer/test_useFullURLForMessageEndpoint
=== RUN   TestSSEServer/works_as_http.Handler_with_custom_basePath
=== RUN   TestSSEServer/Can_use_a_custom_context_function
=== RUN   TestSSEServer/SSEOption_should_not_have_negative_effects_when_used_repeatedly_but_should_always_remain_consistent.
--- PASS: TestSSEServer (0.33s)
    --- PASS: TestSSEServer/Can_instantiate (0.00s)
    --- PASS: TestSSEServer/Can_send_and_receive_messages (0.01s)
    --- PASS: TestSSEServer/Can_handle_multiple_sessions (0.00s)
    --- PASS: TestSSEServer/Can_be_used_as_http.Handler (0.10s)
    --- PASS: TestSSEServer/Works_with_middleware (0.10s)
    --- PASS: TestSSEServer/Works_with_custom_mux (0.00s)
    --- PASS: TestSSEServer/test_useFullURLForMessageEndpoint (0.00s)
    --- PASS: TestSSEServer/works_as_http.Handler_with_custom_basePath (0.10s)
    --- PASS: TestSSEServer/Can_use_a_custom_context_function (0.00s)
    --- PASS: TestSSEServer/SSEOption_should_not_have_negative_effects_when_used_repeatedly_but_should_always_remain_consistent. (0.00s)
=== RUN   TestStdioServer
=== RUN   TestStdioServer/Can_instantiate
=== RUN   TestStdioServer/Can_send_and_receive_messages
=== RUN   TestStdioServer/Can_use_a_custom_context_function
--- PASS: TestStdioServer (0.00s)
    --- PASS: TestStdioServer/Can_instantiate (0.00s)
    --- PASS: TestStdioServer/Can_send_and_receive_messages (0.00s)
    --- PASS: TestStdioServer/Can_use_a_custom_context_function (0.00s)
PASS
ok      github.com/mark3labs/mcp-go/server      1.336s
?       github.com/mark3labs/mcp-go/server/internal/gen [no test files]
@HChengH ➜ /workspaces/mcp-go (feat/support1.18) $ 

Summary by CodeRabbit

  • Chores

    • Updated the build configuration to require Go 1.18, ensuring compatibility with supported versions.
  • Tests

    • Refined test iteration patterns for improved clarity and consistency.

HChengH avatar Apr 09 '25 06:04 HChengH

Walkthrough

The changes update the module configuration and test loop structures. In the go.mod file, the Go version is changed from 1.23 to 1.18, modifying the minimum version required for builds. In the test file (server/server_test.go), loop constructs are revised by replacing implicit range iterations with explicit indexed loops (e.g., from for i := range 5 to for i := 0; i < 5; i++), affecting multiple test cases.

Changes

File Change Summary
go.mod Updated module’s Go version from 1.23 to 1.18, altering the minimum required Go version for building the module.
server/server_test.go Replaced implicit range loops (e.g., for i := range 5, for range 10) with explicit indexed for-loops (e.g., for i := 0; i < 5; i++), affecting relevant test cases.

[!WARNING]

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


📜 Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a0e968a752722d87063eb36ea0d55938e752f6dd and 5d6fef5a288cac82507abe8c219e13d15bdcd5ed.

📒 Files selected for processing (2)
  • go.mod (1 hunks)
  • server/server_test.go (3 hunks)
🔇 Additional comments (5)
go.mod (1)

3-3: Successful downgrade to Go 1.18

The change from Go 1.23 to 1.18 aligns perfectly with the PR objective of enabling compatibility with older Go environments. This modification allows users who are still on Go 1.18 to use this package.

server/server_test.go (4)

211-211: Appropriate loop syntax adjustment for Go 1.18 compatibility

The replacement of for i := range 5 with the traditional for i := 0; i < 5; i++ loop ensures compatibility with Go 1.18, as the range-over-integer syntax was only introduced in Go 1.22.


220-220: Correct loop syntax modification for backward compatibility

Similarly to the previous loop, this change correctly replaces the newer Go 1.22+ syntax with a loop construct that's compatible with Go 1.18.


530-531: Proper loop adjustment for Go 1.18 support

The change from the newer for range 10 construct to the traditional indexed loop ensures compatibility with Go 1.18 while maintaining the same functionality.


535-536: Consistent backward-compatible loop syntax

This change properly replaces the Go 1.22+ loop construct with one that's compatible with Go 1.18, maintaining consistency with the other loop changes in this file.

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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 Apr 09 '25 06:04 coderabbitai[bot]