erpnext-agent 0.23.0__tar.gz

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.
Files changed (31) hide show
  1. erpnext_agent-0.23.0/LICENSE +21 -0
  2. erpnext_agent-0.23.0/PKG-INFO +203 -0
  3. erpnext_agent-0.23.0/README.md +175 -0
  4. erpnext_agent-0.23.0/erpnext_agent/__init__.py +64 -0
  5. erpnext_agent-0.23.0/erpnext_agent/__main__.py +4 -0
  6. erpnext_agent-0.23.0/erpnext_agent/agent_server.py +73 -0
  7. erpnext_agent-0.23.0/erpnext_agent/api/__init__.py +4 -0
  8. erpnext_agent-0.23.0/erpnext_agent/api/api_client_base.py +71 -0
  9. erpnext_agent-0.23.0/erpnext_agent/api/api_client_resource.py +87 -0
  10. erpnext_agent-0.23.0/erpnext_agent/api_client.py +10 -0
  11. erpnext_agent-0.23.0/erpnext_agent/auth.py +30 -0
  12. erpnext_agent-0.23.0/erpnext_agent/mcp/__init__.py +4 -0
  13. erpnext_agent-0.23.0/erpnext_agent/mcp/mcp_authentication.py +51 -0
  14. erpnext_agent-0.23.0/erpnext_agent/mcp/mcp_resource.py +51 -0
  15. erpnext_agent-0.23.0/erpnext_agent/mcp_config.json +12 -0
  16. erpnext_agent-0.23.0/erpnext_agent/mcp_server.py +58 -0
  17. erpnext_agent-0.23.0/erpnext_agent/models.py +10 -0
  18. erpnext_agent-0.23.0/erpnext_agent.egg-info/PKG-INFO +203 -0
  19. erpnext_agent-0.23.0/erpnext_agent.egg-info/SOURCES.txt +29 -0
  20. erpnext_agent-0.23.0/erpnext_agent.egg-info/dependency_links.txt +1 -0
  21. erpnext_agent-0.23.0/erpnext_agent.egg-info/entry_points.txt +3 -0
  22. erpnext_agent-0.23.0/erpnext_agent.egg-info/requires.txt +16 -0
  23. erpnext_agent-0.23.0/erpnext_agent.egg-info/top_level.txt +6 -0
  24. erpnext_agent-0.23.0/pyproject.toml +53 -0
  25. erpnext_agent-0.23.0/setup.cfg +4 -0
  26. erpnext_agent-0.23.0/tests/conftest.py +16 -0
  27. erpnext_agent-0.23.0/tests/test_api_client.py +116 -0
  28. erpnext_agent-0.23.0/tests/test_concept_parity.py +7 -0
  29. erpnext_agent-0.23.0/tests/test_init_dynamics.py +8 -0
  30. erpnext_agent-0.23.0/tests/test_mcp_server.py +84 -0
  31. erpnext_agent-0.23.0/tests/test_startup.py +9 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Advanced Agentic Coding
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,203 @@
1
+ Metadata-Version: 2.4
2
+ Name: erpnext-agent
3
+ Version: 0.23.0
4
+ Summary: ERPNext and Frappe REST/RPC MCP Server for Agentic AI!
5
+ Author-email: Audel Rouhi <knucklessg1@gmail.com>
6
+ License: MIT
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Environment :: Console
10
+ Classifier: Operating System :: POSIX :: Linux
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: <3.14,>=3.11
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: agent-utilities>=0.34.0
16
+ Provides-Extra: mcp
17
+ Requires-Dist: agent-utilities[mcp]>=0.34.0; extra == "mcp"
18
+ Provides-Extra: agent
19
+ Requires-Dist: agent-utilities[agent,logfire]>=0.34.0; extra == "agent"
20
+ Provides-Extra: all
21
+ Requires-Dist: agent-utilities[agent,logfire,mcp]>=0.34.0; extra == "all"
22
+ Provides-Extra: test
23
+ Requires-Dist: pytest-xdist>=3.6.0; extra == "test"
24
+ Requires-Dist: pytest; extra == "test"
25
+ Requires-Dist: pytest-asyncio; extra == "test"
26
+ Requires-Dist: pytest-cov; extra == "test"
27
+ Dynamic: license-file
28
+
29
+ # Erpnext MCP
30
+
31
+ [![Status](https://img.shields.io/badge/status-active-success)](https://github.com/genius-agents/erpnext-agent)
32
+ [![Version](https://img.shields.io/badge/version-0.15.0-blue)](pyproject.toml)
33
+ [![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
34
+
35
+ ERPNext and Frappe Framework enterprise resources planner. Built with the highest architectural standards, incorporating dynamic facades, custom API routing, and FastMCP tool decoration.
36
+
37
+ ## Table of Contents
38
+ - [Overview](#overview)
39
+ - [Features](#features)
40
+ - [Installation](#installation)
41
+ - [Usage](#usage)
42
+ - [Configuration](#configuration)
43
+ - [MCP Tools](#mcp-tools)
44
+ - [Architecture](#architecture)
45
+ - [Deployment](#deployment)
46
+ - [Contributing](#contributing)
47
+ - [License](#license)
48
+
49
+ ---
50
+
51
+ ## Overview
52
+
53
+ Erpnext MCP provides a high-performance, model-optimized interface to Erpnext capabilities. It isolates the model from underlying API transport complexity, ensuring safe, idempotent, and highly traceable system interactions.
54
+
55
+ ---
56
+
57
+ ## Features
58
+
59
+ - **Dynamic Facade Orchestration**: Integrates multi-inheritance clients cleanly under a single facade.
60
+ - **Battle-Tested Resilience**: Out-of-the-box credential authentication, connection polling, and request retry strategies.
61
+ - **FastMCP Declarative Tools**: Fast, native schema registration with full inline validation.
62
+ - **Complete Test Intent Diversity**: Deep, automated unit, integration, and mock tests ensuring high code coverage.
63
+
64
+ ---
65
+
66
+ ## ⚙️ Dynamic Tool Selection & Visibility
67
+
68
+ This MCP server supports dynamic toolset selection and visibility filtering at runtime. This allows you to restrict the set of exposed tools in order to prevent blowing up the LLM's context window.
69
+
70
+ You can configure tool filtering via multiple input channels:
71
+
72
+ - **CLI Arguments:** Pass `--tools` or `--toolsets` (or their disabled counterparts `--disabled-tools` and `--disabled-toolsets`) during startup.
73
+ - **Environment Variables:** Define standard environment variables:
74
+ - `MCP_ENABLED_TOOLS` / `MCP_DISABLED_TOOLS`
75
+ - `MCP_ENABLED_TAGS` / `MCP_DISABLED_TAGS`
76
+ - **HTTP SSE Request Headers:** Pass custom headers during transport initialization:
77
+ - `x-mcp-enabled-tools` / `x-mcp-disabled-tools`
78
+ - `x-mcp-enabled-tags` / `x-mcp-disabled-tags`
79
+ - **HTTP SSE Request Query Parameters:** Append query parameters directly to your transport connection URL:
80
+ - `?tools=tool1,tool2`
81
+ - `?tags=tag1`
82
+
83
+ When query strings or parameters are supplied, an LLM-free **Knowledge Graph resolution layer** (using `DynamicToolOrchestrator`) matches query intents against known tool tags, names, or descriptions, with safe fallback and automated 24-hour background cache refreshing.
84
+
85
+
86
+ ---
87
+
88
+ ## Installation
89
+
90
+ Install in editable mode directly inside your active workspace:
91
+
92
+ ```bash
93
+ pip install -e .[all]
94
+ ```
95
+
96
+ Or via the `uv` tool:
97
+
98
+ ```bash
99
+ uv pip install -e .
100
+ ```
101
+
102
+ ---
103
+
104
+ ## Usage
105
+
106
+ You can launch the FastMCP server in stdio mode via Python module execution:
107
+
108
+ ```python
109
+ import asyncio
110
+ from erpnext_agent.mcp_server import get_mcp_instance
111
+
112
+ async def main():
113
+ mcp = get_mcp_instance()
114
+ # Execute stdio loop or launch server
115
+ print("MCP Server ready.")
116
+
117
+ if __name__ == "__main__":
118
+ asyncio.run(main())
119
+ ```
120
+
121
+ For direct shell launch, execute:
122
+
123
+ ```bash
124
+ python -m erpnext_agent.mcp_server
125
+ ```
126
+
127
+ ---
128
+
129
+ ## Configuration
130
+
131
+ The package is fully configurable via the environment variables listed below:
132
+
133
+ | Variable | Description | Default | Required |
134
+ |----------|-------------|---------|----------|
135
+ | `ERPNEXT_URL` | ERPNext / Frappe server endpoint URL | `http://localhost:8000` | Yes |
136
+ | `ERPNEXT_TOKEN` | API authentication token (api_key:api_secret) | `your_api_key:your_api_secret` | Yes |
137
+
138
+ A local template is supplied inside [.env.example](.env.example). Copy this file as `.env` and fill out your specific service endpoint parameters before starting execution.
139
+
140
+ ---
141
+
142
+ ## MCP Tools
143
+
144
+ The following declarative FastMCP tools are registered and available to upstream AI agents:
145
+
146
+ | Tool Name | Description | Parameters |
147
+ |-----------|-------------|------------|
148
+ | `get_document` | Get specific Frappe/ERPNext document by doctype and name | `doctype: str, name: str` |
149
+ | `create_document` | Create new Frappe/ERPNext document | `doctype: str, data: dict` |
150
+ | `call_method` | Call a whitelisted ERPNext RPC method | `method: str, params: dict = None` |
151
+
152
+ See [docs/overview.md](docs/overview.md) or [docs/concepts.md](docs/concepts.md) for deeper operational examples.
153
+
154
+ ---
155
+
156
+ ## Architecture
157
+
158
+ This package uses the standardized Agent-Utilities dynamic facade architecture:
159
+
160
+ ```mermaid
161
+ graph TD
162
+ User([User Agent]) --> Server[FastMCP Server]
163
+ Server --> Facade[Api Dynamic Facade]
164
+ Facade --> ClientBase[ApiClientBase]
165
+ Facade --> Auth[Credentials Auth Handler]
166
+ ClientBase --> Service([External Service API])
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Deployment
172
+
173
+ ### Bare-Metal (Standard pip)
174
+ 1. Set up your Python virtual environment (>= 3.10).
175
+ 2. Install the package: `pip install .[all]`
176
+ 3. Export credentials:
177
+ ```bash
178
+ export ERPNEXT_URL="http://localhost:8000"
179
+ ```
180
+ 4. Run: `python -m erpnext_agent.mcp_server`
181
+
182
+ ### Container (Docker Compose)
183
+ A standard compose structure is provided inside the `docker/` folder. Build and deploy:
184
+
185
+ ```bash
186
+ docker compose -f docker/compose.yml up --build -d
187
+ ```
188
+
189
+ ---
190
+
191
+ ## Contributing
192
+
193
+ Please audit all code changes against ecosystem guidelines in [CONTRIBUTING.md](CONTRIBUTING.md) if available, and run:
194
+
195
+ ```bash
196
+ pre-commit run --all-files
197
+ ```
198
+
199
+ ---
200
+
201
+ ## License
202
+
203
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for complete details.
@@ -0,0 +1,175 @@
1
+ # Erpnext MCP
2
+
3
+ [![Status](https://img.shields.io/badge/status-active-success)](https://github.com/genius-agents/erpnext-agent)
4
+ [![Version](https://img.shields.io/badge/version-0.15.0-blue)](pyproject.toml)
5
+ [![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
6
+
7
+ ERPNext and Frappe Framework enterprise resources planner. Built with the highest architectural standards, incorporating dynamic facades, custom API routing, and FastMCP tool decoration.
8
+
9
+ ## Table of Contents
10
+ - [Overview](#overview)
11
+ - [Features](#features)
12
+ - [Installation](#installation)
13
+ - [Usage](#usage)
14
+ - [Configuration](#configuration)
15
+ - [MCP Tools](#mcp-tools)
16
+ - [Architecture](#architecture)
17
+ - [Deployment](#deployment)
18
+ - [Contributing](#contributing)
19
+ - [License](#license)
20
+
21
+ ---
22
+
23
+ ## Overview
24
+
25
+ Erpnext MCP provides a high-performance, model-optimized interface to Erpnext capabilities. It isolates the model from underlying API transport complexity, ensuring safe, idempotent, and highly traceable system interactions.
26
+
27
+ ---
28
+
29
+ ## Features
30
+
31
+ - **Dynamic Facade Orchestration**: Integrates multi-inheritance clients cleanly under a single facade.
32
+ - **Battle-Tested Resilience**: Out-of-the-box credential authentication, connection polling, and request retry strategies.
33
+ - **FastMCP Declarative Tools**: Fast, native schema registration with full inline validation.
34
+ - **Complete Test Intent Diversity**: Deep, automated unit, integration, and mock tests ensuring high code coverage.
35
+
36
+ ---
37
+
38
+ ## ⚙️ Dynamic Tool Selection & Visibility
39
+
40
+ This MCP server supports dynamic toolset selection and visibility filtering at runtime. This allows you to restrict the set of exposed tools in order to prevent blowing up the LLM's context window.
41
+
42
+ You can configure tool filtering via multiple input channels:
43
+
44
+ - **CLI Arguments:** Pass `--tools` or `--toolsets` (or their disabled counterparts `--disabled-tools` and `--disabled-toolsets`) during startup.
45
+ - **Environment Variables:** Define standard environment variables:
46
+ - `MCP_ENABLED_TOOLS` / `MCP_DISABLED_TOOLS`
47
+ - `MCP_ENABLED_TAGS` / `MCP_DISABLED_TAGS`
48
+ - **HTTP SSE Request Headers:** Pass custom headers during transport initialization:
49
+ - `x-mcp-enabled-tools` / `x-mcp-disabled-tools`
50
+ - `x-mcp-enabled-tags` / `x-mcp-disabled-tags`
51
+ - **HTTP SSE Request Query Parameters:** Append query parameters directly to your transport connection URL:
52
+ - `?tools=tool1,tool2`
53
+ - `?tags=tag1`
54
+
55
+ When query strings or parameters are supplied, an LLM-free **Knowledge Graph resolution layer** (using `DynamicToolOrchestrator`) matches query intents against known tool tags, names, or descriptions, with safe fallback and automated 24-hour background cache refreshing.
56
+
57
+
58
+ ---
59
+
60
+ ## Installation
61
+
62
+ Install in editable mode directly inside your active workspace:
63
+
64
+ ```bash
65
+ pip install -e .[all]
66
+ ```
67
+
68
+ Or via the `uv` tool:
69
+
70
+ ```bash
71
+ uv pip install -e .
72
+ ```
73
+
74
+ ---
75
+
76
+ ## Usage
77
+
78
+ You can launch the FastMCP server in stdio mode via Python module execution:
79
+
80
+ ```python
81
+ import asyncio
82
+ from erpnext_agent.mcp_server import get_mcp_instance
83
+
84
+ async def main():
85
+ mcp = get_mcp_instance()
86
+ # Execute stdio loop or launch server
87
+ print("MCP Server ready.")
88
+
89
+ if __name__ == "__main__":
90
+ asyncio.run(main())
91
+ ```
92
+
93
+ For direct shell launch, execute:
94
+
95
+ ```bash
96
+ python -m erpnext_agent.mcp_server
97
+ ```
98
+
99
+ ---
100
+
101
+ ## Configuration
102
+
103
+ The package is fully configurable via the environment variables listed below:
104
+
105
+ | Variable | Description | Default | Required |
106
+ |----------|-------------|---------|----------|
107
+ | `ERPNEXT_URL` | ERPNext / Frappe server endpoint URL | `http://localhost:8000` | Yes |
108
+ | `ERPNEXT_TOKEN` | API authentication token (api_key:api_secret) | `your_api_key:your_api_secret` | Yes |
109
+
110
+ A local template is supplied inside [.env.example](.env.example). Copy this file as `.env` and fill out your specific service endpoint parameters before starting execution.
111
+
112
+ ---
113
+
114
+ ## MCP Tools
115
+
116
+ The following declarative FastMCP tools are registered and available to upstream AI agents:
117
+
118
+ | Tool Name | Description | Parameters |
119
+ |-----------|-------------|------------|
120
+ | `get_document` | Get specific Frappe/ERPNext document by doctype and name | `doctype: str, name: str` |
121
+ | `create_document` | Create new Frappe/ERPNext document | `doctype: str, data: dict` |
122
+ | `call_method` | Call a whitelisted ERPNext RPC method | `method: str, params: dict = None` |
123
+
124
+ See [docs/overview.md](docs/overview.md) or [docs/concepts.md](docs/concepts.md) for deeper operational examples.
125
+
126
+ ---
127
+
128
+ ## Architecture
129
+
130
+ This package uses the standardized Agent-Utilities dynamic facade architecture:
131
+
132
+ ```mermaid
133
+ graph TD
134
+ User([User Agent]) --> Server[FastMCP Server]
135
+ Server --> Facade[Api Dynamic Facade]
136
+ Facade --> ClientBase[ApiClientBase]
137
+ Facade --> Auth[Credentials Auth Handler]
138
+ ClientBase --> Service([External Service API])
139
+ ```
140
+
141
+ ---
142
+
143
+ ## Deployment
144
+
145
+ ### Bare-Metal (Standard pip)
146
+ 1. Set up your Python virtual environment (>= 3.10).
147
+ 2. Install the package: `pip install .[all]`
148
+ 3. Export credentials:
149
+ ```bash
150
+ export ERPNEXT_URL="http://localhost:8000"
151
+ ```
152
+ 4. Run: `python -m erpnext_agent.mcp_server`
153
+
154
+ ### Container (Docker Compose)
155
+ A standard compose structure is provided inside the `docker/` folder. Build and deploy:
156
+
157
+ ```bash
158
+ docker compose -f docker/compose.yml up --build -d
159
+ ```
160
+
161
+ ---
162
+
163
+ ## Contributing
164
+
165
+ Please audit all code changes against ecosystem guidelines in [CONTRIBUTING.md](CONTRIBUTING.md) if available, and run:
166
+
167
+ ```bash
168
+ pre-commit run --all-files
169
+ ```
170
+
171
+ ---
172
+
173
+ ## License
174
+
175
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for complete details.
@@ -0,0 +1,64 @@
1
+ """CONCEPT:ECO-4.0 Unified ecosystem initialization dynamic check."""
2
+
3
+ import importlib
4
+ import inspect
5
+ from typing import Any
6
+
7
+ __version__ = "0.15.0"
8
+ __all__: list[str] = []
9
+
10
+ CORE_MODULES = ["erpnext_agent.api_client"]
11
+ OPTIONAL_MODULES = {
12
+ "erpnext_agent.agent_server": "agent",
13
+ "erpnext_agent.mcp_server": "mcp",
14
+ }
15
+
16
+
17
+ def _expose_members(module):
18
+ for name, obj in inspect.getmembers(module):
19
+ if (inspect.isclass(obj) or inspect.isfunction(obj)) and not name.startswith(
20
+ "_"
21
+ ):
22
+ globals()[name] = obj
23
+ if name not in __all__:
24
+ __all__.append(name)
25
+
26
+
27
+ for module_name in CORE_MODULES:
28
+ module = importlib.import_module(module_name)
29
+ _expose_members(module)
30
+
31
+ _loaded_optional_modules = {}
32
+
33
+
34
+ def _import_module_safely(module_name: str):
35
+ try:
36
+ return importlib.import_module(module_name)
37
+ except ImportError:
38
+ return None
39
+
40
+
41
+ def __getattr__(name: str) -> Any:
42
+ if name == "_MCP_AVAILABLE":
43
+ mcp_key = next((k for k in OPTIONAL_MODULES if "mcp_server" in k), None)
44
+ return _import_module_safely(mcp_key) is not None if mcp_key else False
45
+ if name == "_AGENT_AVAILABLE":
46
+ agent_key = next((k for k in OPTIONAL_MODULES if "agent_server" in k), None)
47
+ return _import_module_safely(agent_key) is not None if agent_key else False
48
+
49
+ for module_name in OPTIONAL_MODULES:
50
+ if module_name not in _loaded_optional_modules:
51
+ module = _import_module_safely(module_name)
52
+ if module is not None:
53
+ _loaded_optional_modules[module_name] = module
54
+ _expose_members(module)
55
+
56
+ module = _loaded_optional_modules.get(module_name)
57
+ if module is not None and hasattr(module, name):
58
+ return getattr(module, name)
59
+
60
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
61
+
62
+
63
+ def __dir__() -> list[str]:
64
+ return sorted(list(globals().keys()) + __all__)
@@ -0,0 +1,4 @@
1
+ from erpnext_agent.agent_server import agent_server
2
+
3
+ if __name__ == "__main__":
4
+ agent_server()
@@ -0,0 +1,73 @@
1
+ import logging
2
+ import os
3
+ import sys
4
+ import warnings
5
+
6
+ __version__ = "0.15.0"
7
+
8
+ logging.basicConfig(
9
+ level=logging.INFO,
10
+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
11
+ )
12
+ logger = logging.getLogger(__name__)
13
+
14
+ DEFAULT_AGENT_NAME = None
15
+ DEFAULT_AGENT_DESCRIPTION = None
16
+ DEFAULT_AGENT_SYSTEM_PROMPT = None
17
+
18
+
19
+ def agent_server():
20
+ """Start graph-based Pydantic AI agent server.
21
+ CONCEPT:ERPN-007
22
+ """
23
+ from agent_utilities import (
24
+ build_system_prompt_from_workspace,
25
+ create_agent_parser,
26
+ create_agent_server,
27
+ initialize_workspace,
28
+ load_identity,
29
+ )
30
+
31
+ global DEFAULT_AGENT_NAME, DEFAULT_AGENT_DESCRIPTION, DEFAULT_AGENT_SYSTEM_PROMPT
32
+ initialize_workspace()
33
+ meta = load_identity()
34
+ DEFAULT_AGENT_NAME = os.getenv(
35
+ "DEFAULT_AGENT_NAME", meta.get("name", "ERPNext Agent Agent")
36
+ )
37
+ DEFAULT_AGENT_DESCRIPTION = os.getenv(
38
+ "AGENT_DESCRIPTION",
39
+ meta.get("description", "AI agent for ERPNext Agent operations."),
40
+ )
41
+ DEFAULT_AGENT_SYSTEM_PROMPT = os.getenv(
42
+ "AGENT_SYSTEM_PROMPT",
43
+ meta.get("content") or build_system_prompt_from_workspace(),
44
+ )
45
+
46
+ warnings.filterwarnings("ignore", message=".*urllib3.*")
47
+ warnings.filterwarnings("ignore", category=DeprecationWarning, module="fastmcp")
48
+
49
+ print(f"{DEFAULT_AGENT_NAME} v{__version__}", file=sys.stderr)
50
+ parser = create_agent_parser()
51
+ args = parser.parse_args()
52
+
53
+ create_agent_server(
54
+ mcp_url=args.mcp_url,
55
+ mcp_config=args.mcp_config or "mcp_config.json",
56
+ host=args.host,
57
+ port=args.port,
58
+ provider=args.provider,
59
+ model_id=args.model_id,
60
+ router_model=args.model_id,
61
+ agent_model=args.model_id,
62
+ base_url=args.base_url,
63
+ api_key=args.api_key,
64
+ custom_skills_directory=args.custom_skills_directory,
65
+ enable_web_ui=args.web,
66
+ enable_otel=args.otel,
67
+ otel_endpoint=args.otel_endpoint,
68
+ otel_headers=args.otel_headers,
69
+ otel_public_key=args.otel_public_key,
70
+ otel_secret_key=args.otel_secret_key,
71
+ otel_protocol=args.otel_protocol,
72
+ debug=args.debug,
73
+ )
@@ -0,0 +1,4 @@
1
+ from erpnext_agent.api.api_client_base import ApiClientBase
2
+ from erpnext_agent.api.api_client_resource import Api as ApiResource
3
+
4
+ __all__ = ["ApiClientBase", "ApiResource"]
@@ -0,0 +1,71 @@
1
+ from typing import Any
2
+ from urllib.parse import urljoin
3
+
4
+ import requests
5
+ import urllib3
6
+
7
+
8
+ class ApiClientBase:
9
+ def __init__(
10
+ self,
11
+ base_url: str,
12
+ token: str | None = None,
13
+ username: str | None = None,
14
+ password: str | None = None,
15
+ verify: bool = True,
16
+ ):
17
+ base_url = base_url.rstrip("/")
18
+ if base_url.endswith("/api"):
19
+ base_url = base_url[:-4].rstrip("/")
20
+ self.base_url = base_url
21
+ self.token = token
22
+ self.username = username
23
+ self.password = password
24
+ self._session = requests.Session()
25
+ self._session.verify = verify
26
+
27
+ if not verify:
28
+ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
29
+
30
+ if token:
31
+ if not token.startswith("Bearer ") and not token.startswith("token "):
32
+ if ":" in token:
33
+ self._session.headers.update({"Authorization": f"token {token}"})
34
+ else:
35
+ self._session.headers.update({"Authorization": f"Bearer {token}"})
36
+ else:
37
+ self._session.headers.update({"Authorization": token})
38
+ elif username and password:
39
+ self._session.auth = (username, password)
40
+
41
+ def request(
42
+ self,
43
+ method: str,
44
+ endpoint: str,
45
+ params: dict[str, Any] | None = None,
46
+ data: Any | None = None,
47
+ ) -> Any:
48
+ if endpoint.startswith("http"):
49
+ url = endpoint
50
+ else:
51
+ url = urljoin(self.base_url, endpoint)
52
+
53
+ headers = {"Content-Type": "application/json"}
54
+ response = self._session.request(
55
+ method=method,
56
+ url=url,
57
+ headers=headers,
58
+ params=params,
59
+ json=data,
60
+ )
61
+
62
+ if response.status_code >= 400:
63
+ raise Exception(f"API error: {response.status_code} - {response.text}")
64
+
65
+ if response.status_code == 204 or not response.text.strip():
66
+ return {"status": "success"}
67
+
68
+ try:
69
+ return response.json()
70
+ except Exception:
71
+ return {"status": "success", "text": response.text}