jena-mcp 0.3.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.
- jena_mcp-0.3.0/LICENSE +21 -0
- jena_mcp-0.3.0/MANIFEST.in +5 -0
- jena_mcp-0.3.0/PKG-INFO +82 -0
- jena_mcp-0.3.0/README.md +53 -0
- jena_mcp-0.3.0/jena_mcp/__init__.py +64 -0
- jena_mcp-0.3.0/jena_mcp/__main__.py +4 -0
- jena_mcp-0.3.0/jena_mcp/agent_server.py +73 -0
- jena_mcp-0.3.0/jena_mcp/api/__init__.py +0 -0
- jena_mcp-0.3.0/jena_mcp/api/api_client_base.py +93 -0
- jena_mcp-0.3.0/jena_mcp/api/api_client_jena.py +171 -0
- jena_mcp-0.3.0/jena_mcp/api_client.py +11 -0
- jena_mcp-0.3.0/jena_mcp/auth.py +35 -0
- jena_mcp-0.3.0/jena_mcp/mcp/__init__.py +0 -0
- jena_mcp-0.3.0/jena_mcp/mcp/mcp_jena.py +134 -0
- jena_mcp-0.3.0/jena_mcp/mcp_config.json +1 -0
- jena_mcp-0.3.0/jena_mcp/mcp_server.py +57 -0
- jena_mcp-0.3.0/jena_mcp/models.py +23 -0
- jena_mcp-0.3.0/jena_mcp.egg-info/PKG-INFO +82 -0
- jena_mcp-0.3.0/jena_mcp.egg-info/SOURCES.txt +32 -0
- jena_mcp-0.3.0/jena_mcp.egg-info/dependency_links.txt +1 -0
- jena_mcp-0.3.0/jena_mcp.egg-info/entry_points.txt +3 -0
- jena_mcp-0.3.0/jena_mcp.egg-info/requires.txt +17 -0
- jena_mcp-0.3.0/jena_mcp.egg-info/top_level.txt +7 -0
- jena_mcp-0.3.0/pyproject.toml +53 -0
- jena_mcp-0.3.0/requirements.txt +2 -0
- jena_mcp-0.3.0/scripts/security_sanitizer.py +160 -0
- jena_mcp-0.3.0/scripts/validate_a2a_agent.py +139 -0
- jena_mcp-0.3.0/scripts/validate_agent.py +62 -0
- jena_mcp-0.3.0/scripts/verify_api_integration.py +279 -0
- jena_mcp-0.3.0/setup.cfg +4 -0
- jena_mcp-0.3.0/tests/conftest.py +0 -0
- jena_mcp-0.3.0/tests/test_concept_parity.py +1 -0
- jena_mcp-0.3.0/tests/test_init_dynamics.py +1 -0
- jena_mcp-0.3.0/tests/test_startup.py +1 -0
jena_mcp-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Knuckles-Team
|
|
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.
|
jena_mcp-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: jena-mcp
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Apache Jena (Fuseki) API + MCP Server + A2A 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.41.0
|
|
16
|
+
Requires-Dist: requests>=2.31.0
|
|
17
|
+
Provides-Extra: mcp
|
|
18
|
+
Requires-Dist: agent-utilities[mcp]>=0.41.0; extra == "mcp"
|
|
19
|
+
Provides-Extra: agent
|
|
20
|
+
Requires-Dist: agent-utilities[agent,logfire]>=0.41.0; extra == "agent"
|
|
21
|
+
Provides-Extra: all
|
|
22
|
+
Requires-Dist: agent-utilities[agent,logfire,mcp]>=0.41.0; extra == "all"
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest-xdist>=3.6.0; extra == "test"
|
|
25
|
+
Requires-Dist: pytest; extra == "test"
|
|
26
|
+
Requires-Dist: pytest-asyncio; extra == "test"
|
|
27
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# jena-mcp
|
|
31
|
+
|
|
32
|
+
A Model Context Protocol (MCP) server for Jena integration.
|
|
33
|
+
|
|
34
|
+
## Table of Contents
|
|
35
|
+
- [Overview](#overview)
|
|
36
|
+
- [Installation](#installation)
|
|
37
|
+
- [Usage](#usage)
|
|
38
|
+
- [Architecture](#architecture)
|
|
39
|
+
- [Deployment](#deployment)
|
|
40
|
+
- [Environment Variables](#environment-variables)
|
|
41
|
+
- [MCP Tools](#mcp-tools)
|
|
42
|
+
|
|
43
|
+
## Overview
|
|
44
|
+
jena-mcp exposes a standardized interface to interact with Jena using the Model Context Protocol.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
```bash
|
|
48
|
+
pip install -e .
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
Run the MCP server directly:
|
|
53
|
+
```bash
|
|
54
|
+
python -m jena_mcp
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Architecture
|
|
58
|
+
See `/docs` for architectural diagrams and further documentation.
|
|
59
|
+
|
|
60
|
+
## Deployment
|
|
61
|
+
### Bare-metal
|
|
62
|
+
```bash
|
|
63
|
+
python -m jena_mcp.agent_server
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Docker
|
|
67
|
+
```bash
|
|
68
|
+
docker compose -f docker/agent.compose.yml up -d
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Environment Variables
|
|
72
|
+
| Variable | Description |
|
|
73
|
+
|----------|-------------|
|
|
74
|
+
| `JENA_FUSEKI_URL` | Fuseki server URL |
|
|
75
|
+
| `JENA_USER` | Admin user |
|
|
76
|
+
| `JENA_PASSWORD` | Admin password |
|
|
77
|
+
|
|
78
|
+
## MCP Tools
|
|
79
|
+
| Tool | Description |
|
|
80
|
+
|------|-------------|
|
|
81
|
+
| `get_jena_info` | Retrieve basic information from Jena |
|
|
82
|
+
| `query_jena` | Run a query against the Jena instance |
|
jena_mcp-0.3.0/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# jena-mcp
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol (MCP) server for Jena integration.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
- [Overview](#overview)
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Usage](#usage)
|
|
9
|
+
- [Architecture](#architecture)
|
|
10
|
+
- [Deployment](#deployment)
|
|
11
|
+
- [Environment Variables](#environment-variables)
|
|
12
|
+
- [MCP Tools](#mcp-tools)
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
jena-mcp exposes a standardized interface to interact with Jena using the Model Context Protocol.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
```bash
|
|
19
|
+
pip install -e .
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
Run the MCP server directly:
|
|
24
|
+
```bash
|
|
25
|
+
python -m jena_mcp
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Architecture
|
|
29
|
+
See `/docs` for architectural diagrams and further documentation.
|
|
30
|
+
|
|
31
|
+
## Deployment
|
|
32
|
+
### Bare-metal
|
|
33
|
+
```bash
|
|
34
|
+
python -m jena_mcp.agent_server
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Docker
|
|
38
|
+
```bash
|
|
39
|
+
docker compose -f docker/agent.compose.yml up -d
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Environment Variables
|
|
43
|
+
| Variable | Description |
|
|
44
|
+
|----------|-------------|
|
|
45
|
+
| `JENA_FUSEKI_URL` | Fuseki server URL |
|
|
46
|
+
| `JENA_USER` | Admin user |
|
|
47
|
+
| `JENA_PASSWORD` | Admin password |
|
|
48
|
+
|
|
49
|
+
## MCP Tools
|
|
50
|
+
| Tool | Description |
|
|
51
|
+
|------|-------------|
|
|
52
|
+
| `get_jena_info` | Retrieve basic information from Jena |
|
|
53
|
+
| `query_jena` | Run a query against the Jena instance |
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""jena-mcp: Apache Jena (Fuseki) API + MCP Server + A2A Server."""
|
|
2
|
+
|
|
3
|
+
import importlib
|
|
4
|
+
import inspect
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
__version__ = "0.2.0"
|
|
8
|
+
__all__: list[str] = []
|
|
9
|
+
|
|
10
|
+
CORE_MODULES = ["jena_mcp.api_client"]
|
|
11
|
+
OPTIONAL_MODULES = {
|
|
12
|
+
"jena_mcp.agent_server": "agent",
|
|
13
|
+
"jena_mcp.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,73 @@
|
|
|
1
|
+
"""Graph-based Pydantic AI agent server entry point for jena-mcp."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
import warnings
|
|
7
|
+
|
|
8
|
+
__version__ = "0.2.0"
|
|
9
|
+
|
|
10
|
+
logging.basicConfig(
|
|
11
|
+
level=logging.INFO,
|
|
12
|
+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
13
|
+
)
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
DEFAULT_AGENT_NAME = None
|
|
17
|
+
DEFAULT_AGENT_DESCRIPTION = None
|
|
18
|
+
DEFAULT_AGENT_SYSTEM_PROMPT = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def agent_server():
|
|
22
|
+
"""Start the graph-based Pydantic AI agent server for Apache Jena."""
|
|
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", "Apache Jena Agent")
|
|
36
|
+
)
|
|
37
|
+
DEFAULT_AGENT_DESCRIPTION = os.getenv(
|
|
38
|
+
"AGENT_DESCRIPTION",
|
|
39
|
+
meta.get("description", "AI agent for Apache Jena (Fuseki) 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
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Shared HTTP base client for the Apache Jena (Fuseki) API wrapper."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
from urllib.parse import urljoin
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
import urllib3
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ApiClientBase:
|
|
11
|
+
"""Thin requests.Session wrapper with token / basic-auth support.
|
|
12
|
+
|
|
13
|
+
Apache Jena Fuseki speaks several content types (SPARQL query/update,
|
|
14
|
+
SPARQL results JSON/XML, RDF serializations). Callers pass an explicit
|
|
15
|
+
``content_type``/``accept`` so this base never forces JSON on a SPARQL
|
|
16
|
+
payload.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
base_url: str,
|
|
22
|
+
token: str | None = None,
|
|
23
|
+
username: str | None = None,
|
|
24
|
+
password: str | None = None,
|
|
25
|
+
verify: bool = True,
|
|
26
|
+
):
|
|
27
|
+
self.base_url = base_url.rstrip("/") + "/"
|
|
28
|
+
self.token = token
|
|
29
|
+
self.username = username
|
|
30
|
+
self.password = password
|
|
31
|
+
self.last_etag: str | None = None
|
|
32
|
+
self._session = requests.Session()
|
|
33
|
+
self._session.verify = verify
|
|
34
|
+
|
|
35
|
+
if not verify:
|
|
36
|
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
37
|
+
|
|
38
|
+
if token:
|
|
39
|
+
self._session.headers.update({"Authorization": f"Bearer {token}"})
|
|
40
|
+
elif username and password:
|
|
41
|
+
self._session.auth = (username, password)
|
|
42
|
+
|
|
43
|
+
def request(
|
|
44
|
+
self,
|
|
45
|
+
method: str,
|
|
46
|
+
endpoint: str,
|
|
47
|
+
params: dict[str, Any] | None = None,
|
|
48
|
+
data: Any | None = None,
|
|
49
|
+
content_type: str | None = None,
|
|
50
|
+
accept: str | None = None,
|
|
51
|
+
headers: dict[str, str] | None = None,
|
|
52
|
+
) -> Any:
|
|
53
|
+
"""Perform an HTTP request and return parsed JSON, or raw text.
|
|
54
|
+
|
|
55
|
+
Returns a dict when the response is JSON, otherwise
|
|
56
|
+
``{"status": "success", "text": <body>}``. Raises on HTTP >= 400.
|
|
57
|
+
"""
|
|
58
|
+
if endpoint.startswith("http"):
|
|
59
|
+
url = endpoint
|
|
60
|
+
else:
|
|
61
|
+
url = urljoin(self.base_url, endpoint.lstrip("/"))
|
|
62
|
+
|
|
63
|
+
req_headers: dict[str, str] = {}
|
|
64
|
+
if content_type:
|
|
65
|
+
req_headers["Content-Type"] = content_type
|
|
66
|
+
if accept:
|
|
67
|
+
req_headers["Accept"] = accept
|
|
68
|
+
if headers:
|
|
69
|
+
req_headers.update(headers)
|
|
70
|
+
|
|
71
|
+
response = self._session.request(
|
|
72
|
+
method=method,
|
|
73
|
+
url=url,
|
|
74
|
+
headers=req_headers or None,
|
|
75
|
+
params=params,
|
|
76
|
+
data=data,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
self.last_etag = response.headers.get("ETag")
|
|
80
|
+
|
|
81
|
+
if response.status_code >= 400:
|
|
82
|
+
raise Exception(f"API error: {response.status_code} - {response.text}")
|
|
83
|
+
|
|
84
|
+
if response.status_code == 204 or not response.text.strip():
|
|
85
|
+
return {"status": "success"}
|
|
86
|
+
|
|
87
|
+
ctype = response.headers.get("Content-Type", "")
|
|
88
|
+
if "json" in ctype:
|
|
89
|
+
try:
|
|
90
|
+
return response.json()
|
|
91
|
+
except Exception:
|
|
92
|
+
pass
|
|
93
|
+
return {"status": "success", "text": response.text}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""Apache Jena Fuseki API wrapper.
|
|
2
|
+
|
|
3
|
+
Covers the three HTTP surfaces Fuseki exposes:
|
|
4
|
+
|
|
5
|
+
* **SPARQL Protocol** — query (SELECT/ASK/CONSTRUCT/DESCRIBE) and update
|
|
6
|
+
(INSERT/DELETE) per dataset.
|
|
7
|
+
* **Graph Store Protocol (GSP)** — read/replace/merge/drop RDF graphs.
|
|
8
|
+
* **Admin API** (``/$/``) — ping, server info, statistics, dataset
|
|
9
|
+
lifecycle (create/list/delete/state), async tasks, backup, compact, metrics.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from jena_mcp.api.api_client_base import ApiClientBase
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class JenaApi(ApiClientBase):
|
|
18
|
+
"""Full client for an Apache Jena Fuseki server."""
|
|
19
|
+
|
|
20
|
+
# ------------------------------------------------------------------ #
|
|
21
|
+
# SPARQL Protocol
|
|
22
|
+
# ------------------------------------------------------------------ #
|
|
23
|
+
def query(
|
|
24
|
+
self,
|
|
25
|
+
dataset: str,
|
|
26
|
+
sparql: str,
|
|
27
|
+
accept: str = "application/sparql-results+json",
|
|
28
|
+
) -> Any:
|
|
29
|
+
"""Run a SPARQL read query (SELECT/ASK/CONSTRUCT/DESCRIBE)."""
|
|
30
|
+
return self.request(
|
|
31
|
+
"POST",
|
|
32
|
+
f"{dataset.strip('/')}/sparql",
|
|
33
|
+
data=sparql,
|
|
34
|
+
content_type="application/sparql-query",
|
|
35
|
+
accept=accept,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def update(self, dataset: str, sparql: str) -> Any:
|
|
39
|
+
"""Run a SPARQL update (INSERT/DELETE/LOAD/CLEAR)."""
|
|
40
|
+
return self.request(
|
|
41
|
+
"POST",
|
|
42
|
+
f"{dataset.strip('/')}/update",
|
|
43
|
+
data=sparql,
|
|
44
|
+
content_type="application/sparql-update",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# ------------------------------------------------------------------ #
|
|
48
|
+
# Graph Store Protocol (GSP)
|
|
49
|
+
# ------------------------------------------------------------------ #
|
|
50
|
+
def _gsp_params(self, graph: str | None) -> dict[str, str]:
|
|
51
|
+
return {"graph": graph} if graph and graph != "default" else {"default": ""}
|
|
52
|
+
|
|
53
|
+
def get_graph(
|
|
54
|
+
self, dataset: str, graph: str | None = None, accept: str = "text/turtle"
|
|
55
|
+
) -> Any:
|
|
56
|
+
"""Fetch an RDF graph (named or default) as text."""
|
|
57
|
+
return self.request(
|
|
58
|
+
"GET",
|
|
59
|
+
f"{dataset.strip('/')}/data",
|
|
60
|
+
params=self._gsp_params(graph),
|
|
61
|
+
accept=accept,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
def put_graph(
|
|
65
|
+
self,
|
|
66
|
+
dataset: str,
|
|
67
|
+
rdf_data: str,
|
|
68
|
+
graph: str | None = None,
|
|
69
|
+
content_type: str = "text/turtle",
|
|
70
|
+
) -> Any:
|
|
71
|
+
"""Replace a graph with the supplied RDF."""
|
|
72
|
+
return self.request(
|
|
73
|
+
"PUT",
|
|
74
|
+
f"{dataset.strip('/')}/data",
|
|
75
|
+
params=self._gsp_params(graph),
|
|
76
|
+
data=rdf_data,
|
|
77
|
+
content_type=content_type,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
def post_graph(
|
|
81
|
+
self,
|
|
82
|
+
dataset: str,
|
|
83
|
+
rdf_data: str,
|
|
84
|
+
graph: str | None = None,
|
|
85
|
+
content_type: str = "text/turtle",
|
|
86
|
+
) -> Any:
|
|
87
|
+
"""Merge the supplied RDF into a graph."""
|
|
88
|
+
return self.request(
|
|
89
|
+
"POST",
|
|
90
|
+
f"{dataset.strip('/')}/data",
|
|
91
|
+
params=self._gsp_params(graph),
|
|
92
|
+
data=rdf_data,
|
|
93
|
+
content_type=content_type,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
def delete_graph(self, dataset: str, graph: str | None = None) -> Any:
|
|
97
|
+
"""Drop a graph (named or default)."""
|
|
98
|
+
return self.request(
|
|
99
|
+
"DELETE",
|
|
100
|
+
f"{dataset.strip('/')}/data",
|
|
101
|
+
params=self._gsp_params(graph),
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# ------------------------------------------------------------------ #
|
|
105
|
+
# Admin API (/$/)
|
|
106
|
+
# ------------------------------------------------------------------ #
|
|
107
|
+
def ping(self) -> Any:
|
|
108
|
+
"""Server liveness check."""
|
|
109
|
+
return self.request("GET", "$/ping", accept="text/plain")
|
|
110
|
+
|
|
111
|
+
def server_info(self) -> Any:
|
|
112
|
+
"""Server build info and the list of mounted datasets/services."""
|
|
113
|
+
return self.request("GET", "$/server", accept="application/json")
|
|
114
|
+
|
|
115
|
+
def stats(self, dataset: str | None = None) -> Any:
|
|
116
|
+
"""Server-wide or per-dataset request statistics."""
|
|
117
|
+
endpoint = "$/stats" + (f"/{dataset.strip('/')}" if dataset else "")
|
|
118
|
+
return self.request("GET", endpoint, accept="application/json")
|
|
119
|
+
|
|
120
|
+
def metrics(self) -> Any:
|
|
121
|
+
"""Prometheus metrics exposition."""
|
|
122
|
+
return self.request("GET", "$/metrics", accept="text/plain")
|
|
123
|
+
|
|
124
|
+
def list_datasets(self) -> Any:
|
|
125
|
+
"""List datasets and their state."""
|
|
126
|
+
return self.request("GET", "$/datasets", accept="application/json")
|
|
127
|
+
|
|
128
|
+
def dataset_info(self, name: str) -> Any:
|
|
129
|
+
"""Detail for a single dataset."""
|
|
130
|
+
return self.request(
|
|
131
|
+
"GET", f"$/datasets/{name.strip('/')}", accept="application/json"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
def create_dataset(self, name: str, db_type: str = "tdb2") -> Any:
|
|
135
|
+
"""Create a dataset. ``db_type`` is one of ``tdb2``, ``tdb``, ``mem``."""
|
|
136
|
+
return self.request(
|
|
137
|
+
"POST",
|
|
138
|
+
"$/datasets",
|
|
139
|
+
params={"dbName": name, "dbType": db_type},
|
|
140
|
+
content_type="application/x-www-form-urlencoded",
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
def delete_dataset(self, name: str) -> Any:
|
|
144
|
+
"""Remove a dataset (and its configuration)."""
|
|
145
|
+
return self.request("DELETE", f"$/datasets/{name.strip('/')}")
|
|
146
|
+
|
|
147
|
+
def set_dataset_state(self, name: str, state: str) -> Any:
|
|
148
|
+
"""Set a dataset ``active`` (online) or ``offline``."""
|
|
149
|
+
return self.request(
|
|
150
|
+
"POST",
|
|
151
|
+
f"$/datasets/{name.strip('/')}",
|
|
152
|
+
params={"state": state},
|
|
153
|
+
content_type="application/x-www-form-urlencoded",
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
def list_tasks(self) -> Any:
|
|
157
|
+
"""List async admin tasks (backup/compact)."""
|
|
158
|
+
return self.request("GET", "$/tasks", accept="application/json")
|
|
159
|
+
|
|
160
|
+
def task_info(self, task_id: str) -> Any:
|
|
161
|
+
"""Detail for a single async task."""
|
|
162
|
+
return self.request("GET", f"$/tasks/{task_id}", accept="application/json")
|
|
163
|
+
|
|
164
|
+
def backup(self, dataset: str) -> Any:
|
|
165
|
+
"""Trigger an async backup of a dataset; returns a task handle."""
|
|
166
|
+
return self.request("POST", f"$/backup/{dataset.strip('/')}")
|
|
167
|
+
|
|
168
|
+
def compact(self, dataset: str, delete_old: bool = False) -> Any:
|
|
169
|
+
"""Trigger an async TDB2 compaction; returns a task handle."""
|
|
170
|
+
params = {"deleteOld": "true"} if delete_old else None
|
|
171
|
+
return self.request("POST", f"$/compact/{dataset.strip('/')}", params=params)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Identity credentials loader for the Apache Jena Fuseki client."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from agent_utilities.base_utilities import get_logger, to_boolean
|
|
6
|
+
|
|
7
|
+
from jena_mcp.api_client import Api
|
|
8
|
+
|
|
9
|
+
logger = get_logger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_client() -> Api:
|
|
13
|
+
"""Build an authenticated Apache Jena Fuseki client from the environment.
|
|
14
|
+
|
|
15
|
+
Honors ``JENA_FUSEKI_URL`` (preferred) or ``JENA_URL``; bearer token via
|
|
16
|
+
``JENA_TOKEN``; optional basic auth via ``JENA_USERNAME``/``JENA_PASSWORD``;
|
|
17
|
+
TLS verification via ``JENA_SSL_VERIFY``.
|
|
18
|
+
"""
|
|
19
|
+
base_url = (
|
|
20
|
+
os.getenv("JENA_FUSEKI_URL")
|
|
21
|
+
or os.getenv("JENA_URL")
|
|
22
|
+
or "http://localhost:3030"
|
|
23
|
+
)
|
|
24
|
+
token = os.getenv("JENA_TOKEN", "")
|
|
25
|
+
username = os.getenv("JENA_USERNAME", "")
|
|
26
|
+
password = os.getenv("JENA_PASSWORD", "")
|
|
27
|
+
verify = to_boolean(os.getenv("JENA_SSL_VERIFY", "True"))
|
|
28
|
+
|
|
29
|
+
return Api(
|
|
30
|
+
base_url=base_url,
|
|
31
|
+
token=token or None,
|
|
32
|
+
username=username or None,
|
|
33
|
+
password=password or None,
|
|
34
|
+
verify=verify,
|
|
35
|
+
)
|
|
File without changes
|