-
-
Notifications
You must be signed in to change notification settings - Fork 42
[18.0] [MIG] ai_oca_mcp #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 18.0
Are you sure you want to change the base?
Changes from all commits
b1a69d2
4590960
f8043ca
96ffc2f
0c1dea4
600427b
5ac6fe0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| ========== | ||
| Ai Oca Mcp | ||
| ========== | ||
|
|
||
| .. | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! This file is generated by oca-gen-addon-readme !! | ||
| !! changes will be overwritten. !! | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! source digest: sha256:3d96a5eaf8e647e8ed470a84e39780908086610d1c72402ea1a85830b2d0e709 | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
| :target: https://odoo-community.org/page/development-status | ||
| :alt: Beta | ||
| .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
| :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
| :alt: License: AGPL-3 | ||
| .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fai-lightgray.png?logo=github | ||
| :target: https://github.com/OCA/ai/tree/18.0/ai_oca_mcp | ||
| :alt: OCA/ai | ||
| .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
| :target: https://translation.odoo-community.org/projects/ai-18-0/ai-18-0-ai_oca_mcp | ||
| :alt: Translate me on Weblate | ||
| .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
| :target: https://runboat.odoo-community.org/builds?repo=OCA/ai&target_branch=18.0 | ||
| :alt: Try me on Runboat | ||
|
|
||
| |badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
|
||
| This module exposes Odoo AI tools as an MCP (Model Context Protocol) | ||
| server, allowing external AI clients such as n8n or custom agents to | ||
| call Odoo functions via the standardized MCP protocol. Authentication is | ||
| handled via per-client API keys. | ||
|
|
||
| Note: Claude Desktop requires OAuth 2.0, which is not supported directly | ||
| by this module. An extension could be required. | ||
|
|
||
| **Table of contents** | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| Usage | ||
| ===== | ||
|
|
||
| - Access in Developer mode | ||
| - Go to ``AI > MCP Server`` | ||
| - Create a new MCP Server and add the ``generic`` tools you want to | ||
| expose | ||
| - Click **Add Key** to generate a new API key for a client — the key is | ||
| only shown once | ||
| - Use the provided URL and the generated key to configure your AI client | ||
|
|
||
| Connecting from n8n | ||
| ------------------- | ||
|
|
||
| Use the MCP node with: | ||
|
|
||
| - **URL**: the value shown in the ``URL`` field | ||
| - **Authentication**: Bearer Token | ||
| - **Token**: the generated API key | ||
|
|
||
| Tool limitations | ||
| ---------------- | ||
|
|
||
| Only tools of kind ``generic`` are supported. Tools requiring a record | ||
| context (``generic_model``, ``record``) cannot be used via MCP. | ||
|
|
||
| Security | ||
| -------- | ||
|
|
||
| Each client should have its own API key. Keys can be expired | ||
| individually from the server form or from ``AI > MCP Server Log`` to | ||
| audit all calls. | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues <https://github.com/OCA/ai/issues>`_. | ||
| In case of trouble, please check there if your issue has already been reported. | ||
| If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
| `feedback <https://github.com/OCA/ai/issues/new?body=module:%20ai_oca_mcp%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
|
||
| Do not contact contributors directly about support or help with technical issues. | ||
|
|
||
| Credits | ||
| ======= | ||
|
|
||
| Authors | ||
| ------- | ||
|
|
||
| * Dixmit | ||
|
|
||
| Contributors | ||
| ------------ | ||
|
|
||
| - `Dixmit <https://www.dixmit.com>`__ | ||
|
|
||
| - Enric Tobella | ||
|
|
||
| Maintainers | ||
| ----------- | ||
|
|
||
| This module is maintained by the OCA. | ||
|
|
||
| .. image:: https://odoo-community.org/logo.png | ||
| :alt: Odoo Community Association | ||
| :target: https://odoo-community.org | ||
|
|
||
| OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
| mission is to support the collaborative development of Odoo features and | ||
| promote its widespread use. | ||
|
|
||
| This module is part of the `OCA/ai <https://github.com/OCA/ai/tree/18.0/ai_oca_mcp>`_ project on GitHub. | ||
|
|
||
| You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from . import controllers | ||
| from . import models | ||
| from . import wizards |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Copyright 2026 Dixmit | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| { | ||
| "name": "Ai Oca Mcp", | ||
| "summary": """MCP Interface for Odoo""", | ||
| "version": "18.0.1.0.0", | ||
| "license": "AGPL-3", | ||
| "author": "Dixmit,Odoo Community Association (OCA)", | ||
| "website": "https://github.com/OCA/ai", | ||
| "depends": [ | ||
| "ai_tool", | ||
| ], | ||
| "data": [ | ||
| "views/mcp_server_log.xml", | ||
| "security/ir.model.access.csv", | ||
| "views/mcp_server_key.xml", | ||
| "wizards/mcp_server_key_add.xml", | ||
| "views/mcp_server.xml", | ||
| ], | ||
| "demo": [], | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import mcp_controller |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||
| import json | ||||||
| import re | ||||||
|
|
||||||
| from odoo import fields, http | ||||||
| from odoo.http import request | ||||||
|
|
||||||
|
|
||||||
| class McpController(http.Controller): | ||||||
| @http.route( | ||||||
| "/mcp/<string:key>", type="http", auth="none", methods=["POST"], csrf=False | ||||||
| ) | ||||||
| def mcp_endpoint(self, key, **kwargs): | ||||||
| match = re.match( | ||||||
| r"Bearer (.+)", request.httprequest.headers.get("Authorization", "") | ||||||
| ) | ||||||
| payload = json.loads(request.httprequest.data.decode("utf-8")) | ||||||
| if not match: | ||||||
| return request.make_json_response( | ||||||
| { | ||||||
| "jsonrpc": "2.0", | ||||||
| "id": payload.get("id"), | ||||||
| "error": {"code": -32000, "message": "Connection failed"}, | ||||||
| }, | ||||||
| status=401, | ||||||
| ) | ||||||
| security_key = match.group(1).strip() | ||||||
| server_id, expiration_date = ( | ||||||
| request.env["mcp.server.key"] | ||||||
| .sudo() | ||||||
| ._get_mcp_server_by_key(key, security_key) | ||||||
| ) | ||||||
| if expiration_date and expiration_date < fields.Datetime.now(): | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the interest of this condition because _get_mcp_server_by_key already filter expired server key. Do I miss a case? or is it because the cache is not invalidated when expiration_date changed? |
||||||
| request.env["mcp.server.key"].sudo().browse(server_id).expire_key() | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think will never been called because the filter, I would separate the way how the expire state is changed, using ir.cron ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably called if the key come from cache |
||||||
| server_id = False | ||||||
| if not server_id: | ||||||
| return request.make_json_response( | ||||||
| { | ||||||
| "jsonrpc": "2.0", | ||||||
| "id": payload.get("id"), | ||||||
| "error": {"code": -32000, "message": "Connection failed"}, | ||||||
| } | ||||||
| ) | ||||||
| server = request.env["mcp.server.key"].sudo().browse(server_id) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you rename this variable to something like
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in this commit: 0ef5ad3 (in migratoin PR to v17) |
||||||
| server = server.with_user(server.user_id.id) | ||||||
| method = payload.get("method") | ||||||
| if method == "initialize": | ||||||
| return request.make_json_response( | ||||||
| { | ||||||
| "jsonrpc": "2.0", | ||||||
| "id": payload.get("id"), | ||||||
| "result": { | ||||||
| "protocolVersion": "2025-03-26", | ||||||
| "capabilities": {"tools": {"listChanged": True}}, | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't seen any call to notified clients, do I miss something or mis understand th protocal, As far I understand this listChanded capabilities indicate the client the it will be notified when tools list result would changed
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done by d621868 (in migratoin PR to v17) |
||||||
| "serverInfo": {"name": "odoo-mcp", "version": "0.1.0"}, | ||||||
| }, | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| if method == "tools/list": | ||||||
| return request.make_json_response(server._tools_list(payload)) | ||||||
|
|
||||||
| if method == "tools/call": | ||||||
| return request.make_json_response(server._tools_call(payload)) | ||||||
|
|
||||||
| return request.make_json_response( | ||||||
| { | ||||||
| "jsonrpc": "2.0", | ||||||
| "id": payload.get("id"), | ||||||
| "error": {"code": -32601, "message": "Method not found"}, | ||||||
| } | ||||||
| ) | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm would suggested to create a dedicated auth="ai_mcp" and de-coupled authentication and business logic even it generate an extra request.