MCPcopy Create free account
hub / github.com/bytebase/bytebase / formatToolError

Function formatToolError

backend/api/mcp/tool_query.go:143–156  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
143func 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.
159type queryResponse struct {

Callers 5

handleQueryDatabaseMethod · 0.85
handleChangeMethod · 0.85
resolveChangeTargetMethod · 0.85
handleGetSchemaMethod · 0.85
resolveSchemaTargetMethod · 0.85

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected