{"record":{"id":"68b3d3c3a2914e9a","repo":"twentyhq/twenty","slug":"mcp-error-result-error-get-message-unknow","errorCode":null,"errorMessage":"MCP Error: {result['error'].get('message', 'Unknown error')}","messagePattern":"MCP Error: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"packages/twenty-server/src/engine/core-modules/tool/tools/code-interpreter-tool/twenty-mcp-helper.const.ts","lineNumber":204,"sourceCode":"\n    def _raw_mcp_call(self, name: str, arguments: dict = None):\n        \"\"\"Low-level: issue a tools/call against the MCP surface verbatim.\"\"\"\n        response = requests.post(\n            f\"{self.url}/mcp\",\n            headers={\"Authorization\": f\"Bearer {self.token}\"},\n            json={\n                \"jsonrpc\": \"2.0\",\n                \"id\": 1,\n                \"method\": \"tools/call\",\n                \"params\": {\"name\": name, \"arguments\": arguments or {}}\n            },\n            timeout=30\n        )\n        response.raise_for_status()\n        result = response.json()\n\n        if \"error\" in result:\n            raise Exception(f\"MCP Error: {result['error'].get('message', 'Unknown error')}\")\n\n        content = result.get(\"result\", {}).get(\"content\", [])\n        if content and content[0].get(\"type\") == \"text\":\n            return json.loads(content[0][\"text\"])\n        return result.get(\"result\")\n\n# --------------------------------------------------------------------------\n# \\`twenty\\` is a pre-built instance of the TwentyMCP class above. It is\n# already bound in this module scope — DO NOT \\`import twenty\\`. There is\n# no Python package by that name. Just use it directly, e.g.:\n#     companies = twenty.call_tool('find_many_companies', {'limit': 10})\n# --------------------------------------------------------------------------\ntwenty = TwentyMCP()\n`;\n","sourceCodeStart":186,"sourceCodeEnd":219,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-server/src/engine/core-modules/tool/tools/code-interpreter-tool/twenty-mcp-helper.const.ts#L186-L219","documentation":"Raised by TwentyMCP._raw_mcp_call when the raw JSON-RPC response from POST {TWENTY_SERVER_URL}/mcp contains a top-level `error` object. This is the JSON-RPC 2.0 error channel (distinct from execute_tool's success envelope) and fires for protocol/transport-level failures: method not found, invalid params, parse errors, or server-internal errors at the MCP layer. The message uses error.message, defaulting to 'Unknown error'.","triggerScenarios":"Calling a tool name the /mcp endpoint does not expose (method/params rejected); the server is up but the MCP surface returned a JSON-RPC error (e.g. auth rejected at the gateway, malformed jsonrpc payload); a server-side exception inside the MCP handler that the framework serializes as a JSON-RPC error rather than an execute_tool failure envelope.","commonSituations":"Token is expired or revoked (auth middleware rejects before reaching the tool); calling an MCP-native tool name that was renamed or removed in a newer server version; a network proxy returning its own JSON body that happens to contain `error`; version skew between the helper's expected method names and the deployed server.","solutions":["Read the embedded message — it is the server's JSON-RPC error detail.","If the message indicates auth (401/403), rotate/regenerate TWENTY_API_TOKEN and confirm it is current.","Confirm the tool name exists by calling `learn_tools` (an MCP-native tool) and inspecting the catalog before calling catalog tools.","Check response.status_code by enriching the helper to log it — raise_for_status runs first, so a JSON-RPC error here means HTTP 200 with an error body, typical of MCP protocol-level failures.","Verify version alignment between the code-interpreter helper and the Twenty server release."],"exampleFix":"# before — only the message string is surfaced, hard to triage transport vs logic\nif \"error\" in result:\n    raise Exception(f\"MCP Error: {result['error'].get('message', 'Unknown error')}\")\n# after — include the JSON-RPC error code and HTTP status for faster diagnosis\nif \"error\" in result:\n    err = result['error']\n    raise Exception(\n        f\"MCP Error (code={err.get('code')}, http={response.status_code}): \"\n        f\"{err.get('message', 'Unknown error')}\"\n    )","handlingStrategy":"try-catch","validationCode":"# Cheap pre-check: confirm the /mcp endpoint is reachable and the token is accepted before user code calls tools.\nimport requests, os\n\ndef mcp_endpoint_ok() -> bool:\n    url = os.environ.get('TWENTY_SERVER_URL', '')\n    token = os.environ.get('TWENTY_API_TOKEN', '')\n    if not (url and token):\n        return False\n    try:\n        r = requests.post(\n            f'{url}/mcp',\n            headers={'Authorization': f'Bearer {token}'},\n            json={'jsonrpc': '2.0', 'id': 1, 'method': 'tools/list', 'params': {}},\n            timeout=5,\n        )\n        return r.status_code == 200 and 'error' not in r.json()\n    except requests.RequestException:\n        return False","typeGuard":"from typing import Any\n\ndef is_jsonrpc_error(response: Any) -> bool:\n    return isinstance(response, dict) and 'error' in response","tryCatchPattern":"try:\n    result = twenty.call_tool('find_many_companies', {'limit': 5})\nexcept Exception as e:\n    msg = str(e)\n    if msg.startswith('MCP Error:'):\n        # JSON-RPC level failure — auth, method-not-found, or server error\n        if 'unauthorized' in msg.lower() or 'forbidden' in msg.lower():\n            raise RuntimeError('TWENTY_API_TOKEN rejected by /mcp; rotate the token.') from e\n        if 'method not found' in msg.lower() or 'not found' in msg.lower():\n            raise RuntimeError('Tool name unknown to this server version; call learn_tools to refresh the catalog.') from e\n        raise  # other server-side JSON-RPC errors\n    raise","preventionTips":["Smoke-test the /mcp endpoint with a tools/list call at sandbox startup; fail fast with a clear message.","Keep the helper version in lockstep with the deployed Twenty server so tool/method names match.","After any token rotation, redeploy sandboxes so they pick up the new credential rather than emitting JSON-RPC auth errors."],"tags":["python","code-interpreter","mcp","json-rpc","api-error"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}