formatToolError converts an error into an MCP error result. If the error is a *toolError, it returns structured JSON with code/message/suggestion. Otherwise, it returns the error message as plain text.
(err error)
| 141 | // If the error is a *toolError, it returns structured JSON with code/message/suggestion. |
| 142 | // Otherwise, it returns the error message as plain text. |
| 143 | func formatToolError(err error) *mcp.CallToolResult { |
| 144 | var te *toolError |
| 145 | if errors.As(err, &te) { |
| 146 | jsonBytes, _ := json.MarshalIndent(te, "", " ") |
| 147 | return &mcp.CallToolResult{ |
| 148 | Content: []mcp.Content{&mcp.TextContent{Text: string(jsonBytes)}}, |
| 149 | IsError: true, |
| 150 | } |
| 151 | } |
| 152 | return &mcp.CallToolResult{ |
| 153 | Content: []mcp.Content{&mcp.TextContent{Text: err.Error()}}, |
| 154 | IsError: true, |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // queryResponse is the typed response from the SQL Query API. |
| 159 | type queryResponse struct { |
no test coverage detected