roke-buddy 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- roke_buddy/__init__.py +23 -0
- roke_buddy/__main__.py +155 -0
- roke_buddy/access_control.py +845 -0
- roke_buddy/binary_reads.py +130 -0
- roke_buddy/config.py +401 -0
- roke_buddy/error_handling.py +311 -0
- roke_buddy/error_sanitizer.py +593 -0
- roke_buddy/field_security.py +159 -0
- roke_buddy/file_types.py +111 -0
- roke_buddy/formatters.py +616 -0
- roke_buddy/json2_client.py +358 -0
- roke_buddy/json_values.py +43 -0
- roke_buddy/logging_config.py +341 -0
- roke_buddy/odoo_connection.py +1715 -0
- roke_buddy/odoo_errors.py +143 -0
- roke_buddy/performance.py +551 -0
- roke_buddy/resources.py +1644 -0
- roke_buddy/schemas.py +436 -0
- roke_buddy/server.py +489 -0
- roke_buddy/tools.py +4916 -0
- roke_buddy/uri_schema.py +398 -0
- roke_buddy/user_context.py +261 -0
- roke_buddy-0.0.2.dist-info/METADATA +117 -0
- roke_buddy-0.0.2.dist-info/RECORD +27 -0
- roke_buddy-0.0.2.dist-info/WHEEL +4 -0
- roke_buddy-0.0.2.dist-info/entry_points.txt +2 -0
- roke_buddy-0.0.2.dist-info/licenses/LICENSE +848 -0
roke_buddy/__init__.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""面向 Roke企业服务的模型上下文协议服务器。"""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.0.2"
|
|
4
|
+
__author__ = "Roke"
|
|
5
|
+
__license__ = "LGPL-3.0-only"
|
|
6
|
+
|
|
7
|
+
from .access_control import AccessControlError, AccessController, ModelPermissions
|
|
8
|
+
from .config import OdooConfig, load_config
|
|
9
|
+
from .odoo_connection import OdooConnection, OdooConnectionError, create_connection
|
|
10
|
+
from .server import OdooMCPServer
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"OdooMCPServer",
|
|
14
|
+
"OdooConfig",
|
|
15
|
+
"load_config",
|
|
16
|
+
"OdooConnection",
|
|
17
|
+
"OdooConnectionError",
|
|
18
|
+
"create_connection",
|
|
19
|
+
"AccessController",
|
|
20
|
+
"AccessControlError",
|
|
21
|
+
"ModelPermissions",
|
|
22
|
+
"__version__",
|
|
23
|
+
]
|
roke_buddy/__main__.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""roke-buddy 包的入口点。
|
|
2
|
+
|
|
3
|
+
本模块提供运行 RokeBuddy 的命令行接口,
|
|
4
|
+
既可通过已安装的 ``roke-buddy`` 命令,
|
|
5
|
+
也可通过 ``python -m roke_buddy`` 使用。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import asyncio
|
|
10
|
+
import logging
|
|
11
|
+
import os
|
|
12
|
+
import sys
|
|
13
|
+
from typing import Optional
|
|
14
|
+
|
|
15
|
+
from .config import load_config
|
|
16
|
+
from .server import SERVER_VERSION, OdooMCPServer
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def main(argv: Optional[list[str]] = None) -> int:
|
|
20
|
+
"""MCP 服务器的主入口点。
|
|
21
|
+
|
|
22
|
+
本函数处理命令行参数、加载配置,
|
|
23
|
+
并以指定的 transport 运行 MCP 服务器。
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
argv: 命令行参数(默认为 sys.argv[1:])
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
退出码(成功为 0,失败为非零)
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
# 创建参数解析器
|
|
33
|
+
parser = argparse.ArgumentParser(
|
|
34
|
+
prog="roke-buddy",
|
|
35
|
+
description="RokeBuddy - Model Context Protocol server for Roke enterprise services",
|
|
36
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
37
|
+
epilog="""Environment variables:
|
|
38
|
+
ODOO_URL Odoo server URL (required)
|
|
39
|
+
ODOO_API_KEY Odoo API key (preferred authentication)
|
|
40
|
+
ODOO_USER Odoo username (fallback if no API key)
|
|
41
|
+
ODOO_PASSWORD Odoo password (required with username)
|
|
42
|
+
ODOO_DB Odoo database name (auto-detected if not set)
|
|
43
|
+
ODOO_YOLO YOLO mode: off, read, or true (default: off)
|
|
44
|
+
off — standard mode (requires Odoo MCP module)
|
|
45
|
+
read — read-only via vanilla XML-RPC, or JSON-2 on
|
|
46
|
+
Odoo 19+ with an API key (no module needed)
|
|
47
|
+
true — full read/write, same transports as read
|
|
48
|
+
ODOO_LOCALE Locale for formatting (e.g. en_US, de_DE)
|
|
49
|
+
ODOO_ALLOWED_COMPANIES Company IDs to scope every call to (e.g. 1,3)
|
|
50
|
+
ODOO_RPC_TRANSPORT RPC protocol in YOLO mode: auto, xmlrpc or json2 (default: auto)
|
|
51
|
+
|
|
52
|
+
Optional environment variables:
|
|
53
|
+
ODOO_MCP_LOG_LEVEL Log level: DEBUG, INFO, WARNING, ERROR, CRITICAL (default: INFO)
|
|
54
|
+
ODOO_MCP_LOG_JSON Enable structured JSON log output (default: false)
|
|
55
|
+
ODOO_MCP_LOG_FILE Path for rotating log file (10 MB, 5 backups)
|
|
56
|
+
ODOO_MCP_LOG_FORMAT Python logging format string for text logs
|
|
57
|
+
ODOO_MCP_SLOW_OPERATION_THRESHOLD_MS Log operations slower than this
|
|
58
|
+
many milliseconds as slow (default: 1000)
|
|
59
|
+
ODOO_MCP_DEFAULT_LIMIT Default record limit (default: 25)
|
|
60
|
+
ODOO_MCP_MAX_LIMIT Maximum record limit (default: 100)
|
|
61
|
+
ODOO_MCP_MAX_SMART_FIELDS Max fields in smart selection (default: 15)
|
|
62
|
+
ODOO_MCP_TRANSPORT Transport type: stdio or streamable-http (default: stdio)
|
|
63
|
+
ODOO_MCP_HOST Server host for HTTP transports (default: localhost)
|
|
64
|
+
ODOO_MCP_PORT Server port for HTTP transports (default: 8000)
|
|
65
|
+
ODOO_MCP_ENABLE_METHOD_CALLS Enable call_model_method tool, requires ODOO_YOLO=true (default: false)
|
|
66
|
+
ODOO_MCP_ALLOWED_HOSTS Comma-separated list of allowed Host headers for
|
|
67
|
+
DNS rebinding protection (e.g., odoo.example.com,localhost)
|
|
68
|
+
ODOO_MCP_SESSION_IDLE_TIMEOUT Seconds of inactivity before an HTTP session
|
|
69
|
+
is closed and its resources freed (default: never)
|
|
70
|
+
ODOO_MCP_MAX_BINARY_SIZE Max bytes for one binary/attachment resource read
|
|
71
|
+
(default: 52428800 = 50 MB)
|
|
72
|
+
|
|
73
|
+
Documentation: see README.md in the package directory.""",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
parser.add_argument(
|
|
77
|
+
"--version",
|
|
78
|
+
action="version",
|
|
79
|
+
version=f"roke-buddy v{SERVER_VERSION}",
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
# CLI 标志默认用 None 作哨兵:load_config() 会从环境变量
|
|
83
|
+
# 以及 .env 文件中解析实际值。若提前把环境变量写进
|
|
84
|
+
# argparse 默认值(并在下面回写到 os.environ),
|
|
85
|
+
# 会掩盖 .env 的设置,因为 load_dotenv()
|
|
86
|
+
# 从不覆盖环境中已存在的变量。
|
|
87
|
+
parser.add_argument(
|
|
88
|
+
"--transport",
|
|
89
|
+
choices=["stdio", "streamable-http"],
|
|
90
|
+
default=None,
|
|
91
|
+
help="Transport type to use (default: stdio; env: ODOO_MCP_TRANSPORT)",
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
parser.add_argument(
|
|
95
|
+
"--host",
|
|
96
|
+
default=None,
|
|
97
|
+
help="Server host for HTTP transports (default: localhost; env: ODOO_MCP_HOST)",
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
parser.add_argument(
|
|
101
|
+
"--port",
|
|
102
|
+
type=int,
|
|
103
|
+
default=None,
|
|
104
|
+
help="Server port for HTTP transports (default: 8000; env: ODOO_MCP_PORT)",
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
# 解析参数
|
|
108
|
+
args = parser.parse_args(argv)
|
|
109
|
+
|
|
110
|
+
try:
|
|
111
|
+
# 用显式传入的 CLI 参数覆盖环境变量
|
|
112
|
+
if args.transport is not None:
|
|
113
|
+
os.environ["ODOO_MCP_TRANSPORT"] = args.transport
|
|
114
|
+
if args.host is not None:
|
|
115
|
+
os.environ["ODOO_MCP_HOST"] = args.host
|
|
116
|
+
if args.port is not None:
|
|
117
|
+
os.environ["ODOO_MCP_PORT"] = str(args.port)
|
|
118
|
+
|
|
119
|
+
# 从环境加载配置
|
|
120
|
+
config = load_config()
|
|
121
|
+
|
|
122
|
+
# 创建服务器实例
|
|
123
|
+
server = OdooMCPServer(config)
|
|
124
|
+
|
|
125
|
+
# 以指定的 transport 运行服务器
|
|
126
|
+
if config.transport == "stdio":
|
|
127
|
+
asyncio.run(server.run_stdio())
|
|
128
|
+
elif config.transport == "streamable-http":
|
|
129
|
+
asyncio.run(server.run_http())
|
|
130
|
+
else:
|
|
131
|
+
raise ValueError(f"Unsupported transport: {config.transport}")
|
|
132
|
+
|
|
133
|
+
return 0
|
|
134
|
+
|
|
135
|
+
except KeyboardInterrupt:
|
|
136
|
+
# 处理 Ctrl+C 时的优雅关闭
|
|
137
|
+
print("\nServer stopped by user", file=sys.stderr)
|
|
138
|
+
return 0
|
|
139
|
+
|
|
140
|
+
except ValueError as e:
|
|
141
|
+
# 配置错误
|
|
142
|
+
print(f"Configuration error: {e}", file=sys.stderr)
|
|
143
|
+
print("\nPlease check your environment variables or .env file", file=sys.stderr)
|
|
144
|
+
return 1
|
|
145
|
+
|
|
146
|
+
except Exception as e:
|
|
147
|
+
# 其他错误
|
|
148
|
+
logging.error(f"Server error: {e}", exc_info=True)
|
|
149
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
150
|
+
return 1
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
# 模块执行的入口点
|
|
154
|
+
if __name__ == "__main__":
|
|
155
|
+
sys.exit(main())
|