package mcp import "fmt" // JSON-RPC 2.0 error codes used by the MCP endpoint. The -320xx range mirrors // the Win32 server (McpServer.cpp:296-312) so a model sees the same numbers // regardless of which backend it talks to; reusing them matters more than // inventing Go-specific ones. const ( CodeInternal = -32000 // unexpected server-side failure CodeTimeout = -32001 // sub-connection or device reply did not arrive CodeOffline = -32002 // host unknown or offline CodeBusy = -32003 // per-device lock / terminal slot occupied CodeSendFailed = -32004 // command could not be delivered to the host CodeUnsupported = -32005 // host lacks the required capability CodeDenied = -32006 // policy refusal (readonly mode, disabled tool) CodeNotFound = -32009 // target file/directory does not exist CodePermission = -32010 // target rejected the operation (access denied) CodeParseError = -32700 // invalid JSON CodeInvalidRequest = -32600 // not a valid JSON-RPC request CodeMethodNotFound = -32601 // unknown method or tool name CodeInvalidParams = -32602 // schema/argument validation failed ) // rpcError is the JSON-RPC "error" object. It is returned as a Go error from // tool handlers, which lets call sites use plain returns instead of carrying // a response object through every layer. type rpcError struct { Code int `json:"code"` Message string `json:"message"` Data any `json:"data,omitempty"` } func (e *rpcError) Error() string { return fmt.Sprintf("mcp error %d: %s", e.Code, e.Message) } // errf builds an rpcError with a formatted message. func errf(code int, format string, args ...any) *rpcError { return &rpcError{Code: code, Message: fmt.Sprintf(format, args...)} }