| package mcp |
| |
| import ( |
| "context" |
| "testing" |
| |
| "github.com/mark3labs/mcp-go/mcp" |
| "github.com/stretchr/testify/assert" |
| ) |
| |
| func TestNewServer(t *testing.T) { |
| server := NewServer("test-server", "1.0.0") |
| assert.NotNil(t, server) |
| |
| name, version := server.GetServerInfo() |
| assert.Equal(t, "test-server", name) |
| assert.Equal(t, "1.0.0", version) |
| } |
| |
| func TestAddTool(t *testing.T) { |
| server := NewServer("test-server", "1.0.0") |
| |
| // Test adding a valid tool |
| err := server.AddTool("test-tool", "A test tool", map[string]any{ |
| "type": "object", |
| "properties": map[string]any{ |
| "input": map[string]any{ |
| "type": "string", |
| }, |
| }, |
| }, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| return mcp.NewToolResultText("test result"), nil |
| }) |
| |
| assert.NoError(t, err) |
| |
| // Test adding tool with empty name |
| err = server.AddTool("", "description", map[string]any{}, nil) |
| assert.Error(t, err) |
| assert.Contains(t, err.Error(), "tool name cannot be empty") |
| |
| // Test adding tool with empty description |
| err = server.AddTool("name", "", map[string]any{}, nil) |
| assert.Error(t, err) |
| assert.Contains(t, err.Error(), "tool description cannot be empty") |
| } |
| |
| func TestGetMCPServer(t *testing.T) { |
| server := NewServer("test-server", "1.0.0") |
| mcpServer := server.GetMCPServer() |
| assert.NotNil(t, mcpServer) |
| } |