-
Notifications
You must be signed in to change notification settings - Fork 57
Migrate to the official Go SDK for MCP #384
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
Open
BenCookie95
wants to merge
9
commits into
http-mcp-server
Choose a base branch
from
migrate-mcp-go-sdk
base: http-mcp-server
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6f93f7c
initial updates
BenCookie95 0e12741
part 2 of migration. Tests and server implementations
BenCookie95 cc9946b
fix tests
BenCookie95 4e6d192
upgrade to v.0.6.0
BenCookie95 98256c0
Merge remote-tracking branch 'origin/http-mcp-server' into migrate-mc…
BenCookie95 133a52f
tidy
BenCookie95 7522d83
use proper schema type
BenCookie95 8985fb3
remove comments and fix error helper
BenCookie95 aa81126
MCP tool improvements from mcp-interviewer results (#385)
BenCookie95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ package mcpserver_test | |
import ( | ||
"testing" | ||
|
||
"github.com/mark3labs/mcp-go/mcp" | ||
"github.com/modelcontextprotocol/go-sdk/mcp" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
|
@@ -55,8 +55,8 @@ func TestDevToolsWithDevModeEnabled(t *testing.T) { | |
"last_name": "User", | ||
} | ||
|
||
result := executeDevToolWithMCP(t, suite, "create_user", args) | ||
assert.False(t, result.IsError, "create_user should succeed in dev mode") | ||
result, err := executeDevToolWithMCP(t, suite, "create_user", args) | ||
require.NoError(t, err, "create_user should succeed in dev mode") | ||
assert.NotEmpty(t, result.Content, "create_user should return content") | ||
}) | ||
|
||
|
@@ -66,8 +66,8 @@ func TestDevToolsWithDevModeEnabled(t *testing.T) { | |
// missing email and password | ||
} | ||
|
||
result := executeDevToolWithMCP(t, suite, "create_user", args) | ||
assert.True(t, result.IsError, "create_user should fail with missing required fields") | ||
_, err := executeDevToolWithMCP(t, suite, "create_user", args) | ||
require.Error(t, err, "create_user should fail with missing required fields") | ||
}) | ||
}) | ||
|
||
|
@@ -80,8 +80,8 @@ func TestDevToolsWithDevModeEnabled(t *testing.T) { | |
"description": "Team created for dev testing", | ||
} | ||
|
||
result := executeDevToolWithMCP(t, suite, "create_team", args) | ||
assert.False(t, result.IsError, "create_team should succeed in dev mode") | ||
result, err := executeDevToolWithMCP(t, suite, "create_team", args) | ||
require.NoError(t, err, "create_team should succeed in dev mode") | ||
assert.NotEmpty(t, result.Content, "create_team should return content") | ||
}) | ||
|
||
|
@@ -92,8 +92,8 @@ func TestDevToolsWithDevModeEnabled(t *testing.T) { | |
"type": "X", // Invalid type | ||
} | ||
|
||
result := executeDevToolWithMCP(t, suite, "create_team", args) | ||
assert.True(t, result.IsError, "create_team should fail with invalid type") | ||
_, err := executeDevToolWithMCP(t, suite, "create_team", args) | ||
require.Error(t, err, "create_team should fail with invalid type") | ||
}) | ||
}) | ||
|
||
|
@@ -104,8 +104,8 @@ func TestDevToolsWithDevModeEnabled(t *testing.T) { | |
"email": "[email protected]", | ||
"password": "password123", | ||
} | ||
userResult := executeDevToolWithMCP(t, suite, "create_user", userArgs) | ||
require.False(t, userResult.IsError, "User creation should succeed for team test") | ||
_, err := executeDevToolWithMCP(t, suite, "create_user", userArgs) | ||
require.NoError(t, err, "User creation should succeed for team test") | ||
|
||
t.Run("HappyPath", func(t *testing.T) { | ||
// Extract user ID from result (simplified - in real implementation would parse JSON) | ||
|
@@ -115,8 +115,9 @@ func TestDevToolsWithDevModeEnabled(t *testing.T) { | |
"team_id": testData.Team.Id, | ||
} | ||
|
||
result := executeDevToolWithMCP(t, suite, "add_user_to_team", args) | ||
result, _ := executeDevToolWithMCP(t, suite, "add_user_to_team", args) | ||
// User might already be in team, so we just check the call doesn't crash | ||
// Don't require no error since user might already be in team | ||
assert.NotNil(t, result, "add_user_to_team should return a result") | ||
}) | ||
|
||
|
@@ -126,8 +127,8 @@ func TestDevToolsWithDevModeEnabled(t *testing.T) { | |
"team_id": testData.Team.Id, | ||
} | ||
|
||
result := executeDevToolWithMCP(t, suite, "add_user_to_team", args) | ||
assert.True(t, result.IsError, "add_user_to_team should fail with invalid user ID") | ||
_, err := executeDevToolWithMCP(t, suite, "add_user_to_team", args) | ||
require.Error(t, err, "add_user_to_team should fail with invalid user ID") | ||
}) | ||
}) | ||
|
||
|
@@ -138,8 +139,9 @@ func TestDevToolsWithDevModeEnabled(t *testing.T) { | |
"channel_id": testData.Channel.Id, | ||
} | ||
|
||
result := executeDevToolWithMCP(t, suite, "add_user_to_channel", args) | ||
result, _ := executeDevToolWithMCP(t, suite, "add_user_to_channel", args) | ||
// User might already be in channel, so we just check the call doesn't crash | ||
// Don't require no error since user might already be in channel | ||
assert.NotNil(t, result, "add_user_to_channel should return a result") | ||
}) | ||
|
||
|
@@ -149,8 +151,8 @@ func TestDevToolsWithDevModeEnabled(t *testing.T) { | |
"channel_id": "invalid-channel-id", | ||
} | ||
|
||
result := executeDevToolWithMCP(t, suite, "add_user_to_channel", args) | ||
assert.True(t, result.IsError, "add_user_to_channel should fail with invalid channel ID") | ||
_, err := executeDevToolWithMCP(t, suite, "add_user_to_channel", args) | ||
require.Error(t, err, "add_user_to_channel should fail with invalid channel ID") | ||
}) | ||
}) | ||
|
||
|
@@ -161,21 +163,21 @@ func TestDevToolsWithDevModeEnabled(t *testing.T) { | |
"email": "[email protected]", | ||
"password": "postpassword123", | ||
} | ||
userResult := executeDevToolWithMCP(t, suite, "create_user", userArgs) | ||
require.False(t, userResult.IsError, "User creation should succeed for post test") | ||
_, err := executeDevToolWithMCP(t, suite, "create_user", userArgs) | ||
require.NoError(t, err, "User creation should succeed for post test") | ||
|
||
// Add user to team and channel | ||
addTeamArgs := map[string]interface{}{ | ||
"user_id": testData.User.Id, // Using existing user for simplicity | ||
"team_id": testData.Team.Id, | ||
} | ||
executeDevToolWithMCP(t, suite, "add_user_to_team", addTeamArgs) | ||
_, _ = executeDevToolWithMCP(t, suite, "add_user_to_team", addTeamArgs) | ||
|
||
addChannelArgs := map[string]interface{}{ | ||
"user_id": testData.User.Id, | ||
"channel_id": testData.Channel.Id, | ||
} | ||
executeDevToolWithMCP(t, suite, "add_user_to_channel", addChannelArgs) | ||
_, _ = executeDevToolWithMCP(t, suite, "add_user_to_channel", addChannelArgs) | ||
|
||
t.Run("HappyPath", func(t *testing.T) { | ||
args := map[string]interface{}{ | ||
|
@@ -185,8 +187,9 @@ func TestDevToolsWithDevModeEnabled(t *testing.T) { | |
"message": "Hello from dev tool user!", | ||
} | ||
|
||
result := executeDevToolWithMCP(t, suite, "create_post_as_user", args) | ||
result, _ := executeDevToolWithMCP(t, suite, "create_post_as_user", args) | ||
// This might fail due to user permissions, but should not crash | ||
// Don't require no error since it might fail due to permissions | ||
assert.NotNil(t, result, "create_post_as_user should return a result") | ||
}) | ||
|
||
|
@@ -198,8 +201,8 @@ func TestDevToolsWithDevModeEnabled(t *testing.T) { | |
"message": "This should fail", | ||
} | ||
|
||
result := executeDevToolWithMCP(t, suite, "create_post_as_user", args) | ||
assert.True(t, result.IsError, "create_post_as_user should fail with wrong password") | ||
_, err := executeDevToolWithMCP(t, suite, "create_post_as_user", args) | ||
require.Error(t, err, "create_post_as_user should fail with wrong password") | ||
}) | ||
}) | ||
} | ||
|
@@ -226,22 +229,18 @@ func TestDevToolsSecurityGating(t *testing.T) { | |
"test": "value", // Generic args since they should be blocked anyway | ||
} | ||
|
||
result := executeDevToolWithMCP(t, suite, toolName, args) | ||
assert.True(t, result.IsError, "Dev tool %s should be blocked when dev mode is disabled", toolName) | ||
_, err := executeDevToolWithMCP(t, suite, toolName, args) | ||
require.Error(t, err, "Dev tool %s should be blocked when dev mode is disabled", toolName) | ||
|
||
// Check that the error indicates the tool is not available (correct security behavior) | ||
if len(result.Content) > 0 { | ||
if textContent, ok := result.Content[0].(mcp.TextContent); ok { | ||
assert.Contains(t, textContent.Text, "not found", | ||
"Error should indicate tool is not available when dev mode is disabled") | ||
} | ||
} | ||
assert.Contains(t, err.Error(), "unknown tool", | ||
"Error should indicate tool is not available when dev mode is disabled") | ||
}) | ||
} | ||
} | ||
|
||
// executeDevToolWithMCP calls the dev MCP tool through the unified helper | ||
func executeDevToolWithMCP(t *testing.T, suite *TestSuite, toolName string, args map[string]interface{}) *mcp.CallToolResult { | ||
require.NotNil(t, suite.mcpServer, "MCP server must be created before calling tools") | ||
// executeDevToolWithMCP creates a test MCP client session connected to the server and calls the dev tool | ||
func executeDevToolWithMCP(t *testing.T, suite *TestSuite, toolName string, args map[string]interface{}) (*mcp.CallToolResult, error) { | ||
require.NotNil(t, suite.mcpServer, "MCP server must be created before creating client sessions") | ||
return testhelpers.ExecuteMCPTool(t, suite.mcpServer.GetMCPServer(), toolName, args) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This got moved out into it's own package somewhere between v0.2.0 and v0.5.0 of github.com/modelcontextprotocol/go-sdk