6119
My
mysis / files
mysis / internal / mcp / stub.go
2.9 KB
1package mcp 2 3import ( 4 "context" 5 "encoding/json" 6 "fmt" 7) 8 9// StubClient is an offline MCP client that returns mock data. 10type StubClient struct{} 11 12// NewStubClient creates a new stub MCP client. 13func NewStubClient() *StubClient { 14 return &StubClient{} 15} 16 17// Initialize simulates the MCP handshake. 18func (c *StubClient) Initialize(ctx context.Context, clientInfo map[string]interface{}) (*Response, error) { 19 return &Response{ 20 JSONRPC: "2.0", 21 ID: 1, 22 Result: json.RawMessage(`{ 23 "protocolVersion": "2024-11-05", 24 "capabilities": {}, 25 "serverInfo": { 26 "name": "spacemolt-stub", 27 "version": "1.0.0" 28 } 29 }`), 30 }, nil 31} 32 33// ListTools returns a list of mock tools. 34func (c *StubClient) ListTools(ctx context.Context) ([]Tool, error) { 35 return []Tool{ 36 { 37 Name: "get_status", 38 Description: "Get player status (stub)", 39 InputSchema: json.RawMessage(`{"type": "object", "properties": {}}`), 40 }, 41 { 42 Name: "get_system", 43 Description: "Get system info (stub)", 44 InputSchema: json.RawMessage(`{"type": "object", "properties": {}}`), 45 }, 46 { 47 Name: "get_ship", 48 Description: "Get ship info (stub)", 49 InputSchema: json.RawMessage(`{"type": "object", "properties": {}}`), 50 }, 51 { 52 Name: "get_poi", 53 Description: "Get POI info (stub)", 54 InputSchema: json.RawMessage(`{"type": "object", "properties": {}}`), 55 }, 56 { 57 Name: "get_notifications", 58 Description: "Get queued game events (stub)", 59 InputSchema: json.RawMessage(`{"type": "object", "properties": {}}`), 60 }, 61 }, nil 62} 63 64// CallTool executes a mock tool call. 65func (c *StubClient) CallTool(ctx context.Context, name string, arguments interface{}) (*ToolResult, error) { 66 var content string 67 68 switch name { 69 case "get_status": 70 content = `{ 71 "current_tick": 42, 72 "player": { 73 "id": "stub_player", 74 "username": "offline_cmdr", 75 "credits": 1000, 76 "faction_id": "stub_faction" 77 }, 78 "ship": { 79 "id": "stub_ship", 80 "name": "Stub Ship", 81 "health": 100, 82 "fuel": 1000 83 } 84 }` 85 case "get_system": 86 content = `{ 87 "current_tick": 42, 88 "id": "stub_system", 89 "name": "Stub System", 90 "sector": "0,0", 91 "security": 1.0 92 }` 93 case "get_ship": 94 content = `{ 95 "current_tick": 42, 96 "id": "stub_ship", 97 "name": "Stub Ship", 98 "class": "scout", 99 "modules": [], 100 "cargo": [] 101 }` 102 case "get_poi": 103 content = `{ 104 "current_tick": 42, 105 "id": "stub_poi", 106 "name": "Stub Station", 107 "type": "station", 108 "system_id": "stub_system" 109 }` 110 case "get_notifications": 111 // Match real API format (server v0.44.4+) 112 content = `{ 113 "count": 0, 114 "current_tick": 42, 115 "notifications": [], 116 "remaining": 0 117 }` 118 default: 119 return &ToolResult{ 120 Content: []ContentBlock{{Type: "text", Text: fmt.Sprintf("tool %s not implemented in stub", name)}}, 121 IsError: true, 122 }, nil 123 } 124 125 return &ToolResult{ 126 Content: []ContentBlock{{Type: "text", Text: content}}, 127 }, nil 128}