Akron | 90f6521 | 2025-06-12 14:32:55 +0200 | [diff] [blame] | 1 | package mcp |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/mark3labs/mcp-go/mcp" |
| 8 | "github.com/stretchr/testify/assert" |
| 9 | ) |
| 10 | |
| 11 | func TestNewServer(t *testing.T) { |
| 12 | server := NewServer("test-server", "1.0.0") |
| 13 | assert.NotNil(t, server) |
| 14 | |
| 15 | name, version := server.GetServerInfo() |
| 16 | assert.Equal(t, "test-server", name) |
| 17 | assert.Equal(t, "1.0.0", version) |
| 18 | } |
| 19 | |
| 20 | func TestAddTool(t *testing.T) { |
| 21 | server := NewServer("test-server", "1.0.0") |
| 22 | |
| 23 | // Test adding a valid tool |
| 24 | err := server.AddTool("test-tool", "A test tool", map[string]interface{}{ |
| 25 | "type": "object", |
| 26 | "properties": map[string]interface{}{ |
| 27 | "input": map[string]interface{}{ |
| 28 | "type": "string", |
| 29 | }, |
| 30 | }, |
| 31 | }, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 32 | return mcp.NewToolResultText("test result"), nil |
| 33 | }) |
| 34 | |
| 35 | assert.NoError(t, err) |
| 36 | |
| 37 | // Test adding tool with empty name |
| 38 | err = server.AddTool("", "description", map[string]interface{}{}, nil) |
| 39 | assert.Error(t, err) |
| 40 | assert.Contains(t, err.Error(), "tool name cannot be empty") |
| 41 | |
| 42 | // Test adding tool with empty description |
| 43 | err = server.AddTool("name", "", map[string]interface{}{}, nil) |
| 44 | assert.Error(t, err) |
| 45 | assert.Contains(t, err.Error(), "tool description cannot be empty") |
| 46 | } |
| 47 | |
| 48 | func TestGetMCPServer(t *testing.T) { |
| 49 | server := NewServer("test-server", "1.0.0") |
| 50 | mcpServer := server.GetMCPServer() |
| 51 | assert.NotNil(t, mcpServer) |
| 52 | } |