oracle.oci-usage-mcp-server 1.0.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.
@@ -0,0 +1,14 @@
1
+ **/__pycache__/**
2
+
3
+ # Virtual environment
4
+ venv/
5
+ .env/
6
+ .venv/
7
+ ENV/
8
+ env/
9
+ env.bak/
10
+ venv.bak/
11
+
12
+
13
+ # test environments
14
+ .env
@@ -0,0 +1,35 @@
1
+ Copyright (c) 2025 Oracle and/or its affiliates.
2
+
3
+ The Universal Permissive License (UPL), Version 1.0
4
+
5
+ Subject to the condition set forth below, permission is hereby granted to any
6
+ person obtaining a copy of this software, associated documentation and/or data
7
+ (collectively the "Software"), free of charge and under any and all copyright
8
+ rights in the Software, and any and all patent rights owned or freely
9
+ licensable by each licensor hereunder covering either (i) the unmodified
10
+ Software as contributed to or provided by such licensor, or (ii) the Larger
11
+ Works (as defined below), to deal in both
12
+
13
+ (a) the Software, and
14
+ (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15
+ one is included with the Software (each a "Larger Work" to which the Software
16
+ is contributed by such licensors),
17
+
18
+ without restriction, including without limitation the rights to copy, create
19
+ derivative works of, display, perform, and distribute the Software and make,
20
+ use, sell, offer for sale, import, export, have made, and have sold the
21
+ Software and the Larger Work(s), and to sublicense the foregoing rights on
22
+ either these or other terms.
23
+
24
+ This license is subject to the following condition:
25
+ The above copyright notice and either this complete permission notice or at
26
+ a minimum a reference to the UPL must be included in all copies or
27
+ substantial portions of the Software.
28
+
29
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
+ SOFTWARE.
@@ -0,0 +1,51 @@
1
+ Metadata-Version: 2.4
2
+ Name: oracle.oci-usage-mcp-server
3
+ Version: 1.0.0
4
+ Summary: OCI Usage MCP server
5
+ Author-email: Oracle MCP <237432095+oracle-mcp@users.noreply.github.com>
6
+ License-Expression: UPL-1.0
7
+ License-File: LICENSE.txt
8
+ Classifier: License :: OSI Approved :: Universal Permissive License (UPL)
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Requires-Python: >=3.13
13
+ Requires-Dist: fastmcp==2.12.2
14
+ Requires-Dist: oci==2.160.0
15
+ Description-Content-Type: text/markdown
16
+
17
+ # OCI Usage MCP Server
18
+
19
+ ## Overview
20
+
21
+ This server provides tools for interacting with Oracle Cloud Infrastructure (OCI) Usage service.
22
+
23
+ ## Running the server
24
+
25
+ ```sh
26
+ uv run oracle.oci-usage-mcp-server
27
+ ```
28
+
29
+ ## Tools
30
+
31
+ | Tool Name | Description |
32
+ | --- | --- |
33
+ | list_usage_reports | List usage reports in the tenancy |
34
+ | get_usage_report | Get usage report by ID |
35
+
36
+ ⚠️ **NOTE**: All actions are performed with the permissions of the configured OCI CLI profile. We advise least-privilege IAM setup, secure credential management, safe network practices, secure logging, and warn against exposing secrets.
37
+
38
+ ## Third-Party APIs
39
+
40
+ Developers choosing to distribute a binary implementation of this project are responsible for obtaining and providing all required licenses and copyright notices for the third-party code used in order to ensure compliance with their respective open source licenses.
41
+
42
+ ## Disclaimer
43
+
44
+ Users are responsible for their local environment and credential safety. Different language model selections may yield different results and performance.
45
+
46
+ ## License
47
+
48
+ Copyright (c) 2025 Oracle and/or its affiliates.
49
+
50
+ Released under the Universal Permissive License v1.0 as shown at
51
+ <https://oss.oracle.com/licenses/upl/>.
@@ -0,0 +1,35 @@
1
+ # OCI Usage MCP Server
2
+
3
+ ## Overview
4
+
5
+ This server provides tools for interacting with Oracle Cloud Infrastructure (OCI) Usage service.
6
+
7
+ ## Running the server
8
+
9
+ ```sh
10
+ uv run oracle.oci-usage-mcp-server
11
+ ```
12
+
13
+ ## Tools
14
+
15
+ | Tool Name | Description |
16
+ | --- | --- |
17
+ | list_usage_reports | List usage reports in the tenancy |
18
+ | get_usage_report | Get usage report by ID |
19
+
20
+ ⚠️ **NOTE**: All actions are performed with the permissions of the configured OCI CLI profile. We advise least-privilege IAM setup, secure credential management, safe network practices, secure logging, and warn against exposing secrets.
21
+
22
+ ## Third-Party APIs
23
+
24
+ Developers choosing to distribute a binary implementation of this project are responsible for obtaining and providing all required licenses and copyright notices for the third-party code used in order to ensure compliance with their respective open source licenses.
25
+
26
+ ## Disclaimer
27
+
28
+ Users are responsible for their local environment and credential safety. Different language model selections may yield different results and performance.
29
+
30
+ ## License
31
+
32
+ Copyright (c) 2025 Oracle and/or its affiliates.
33
+
34
+ Released under the Universal Permissive License v1.0 as shown at
35
+ <https://oss.oracle.com/licenses/upl/>.
@@ -0,0 +1,5 @@
1
+ """
2
+ Copyright (c) 2025, Oracle and/or its affiliates.
3
+ Licensed under the Universal Permissive License v1.0 as shown at
4
+ https://oss.oracle.com/licenses/upl.
5
+ """
@@ -0,0 +1,8 @@
1
+ """
2
+ Copyright (c) 2025, Oracle and/or its affiliates.
3
+ Licensed under the Universal Permissive License v1.0 as shown at
4
+ https://oss.oracle.com/licenses/upl.
5
+ """
6
+
7
+ __project__ = "oracle.oci-usage-mcp-server"
8
+ __version__ = "1.0.0"
@@ -0,0 +1,102 @@
1
+ """
2
+ Copyright (c) 2025, Oracle and/or its affiliates.
3
+ Licensed under the Universal Permissive License v1.0 as shown at
4
+ https://oss.oracle.com/licenses/upl.
5
+ """
6
+
7
+ import os
8
+ from logging import Logger
9
+ from typing import Annotated
10
+
11
+ import oci
12
+ from fastmcp import FastMCP
13
+ from oci.usage_api.models import RequestSummarizedUsagesDetails
14
+
15
+ from . import __project__, __version__
16
+
17
+ logger = Logger(__name__, level="INFO")
18
+
19
+ mcp = FastMCP(name=__project__)
20
+
21
+
22
+ def get_usage_client():
23
+ logger.info("entering get_monitoring_client")
24
+ config = oci.config.from_file(
25
+ profile_name=os.getenv("OCI_CONFIG_PROFILE", oci.config.DEFAULT_PROFILE)
26
+ )
27
+ user_agent_name = __project__.split("oracle.", 1)[1].split("-server", 1)[0]
28
+ config["additional_user_agent"] = f"{user_agent_name}/{__version__}"
29
+
30
+ private_key = oci.signer.load_private_key_from_file(config["key_file"])
31
+ token_file = config["security_token_file"]
32
+ token = None
33
+ with open(token_file, "r") as f:
34
+ token = f.read()
35
+ signer = oci.auth.signers.SecurityTokenSigner(token, private_key)
36
+ return oci.usage_api.UsageapiClient(config, signer=signer)
37
+
38
+
39
+ @mcp.tool
40
+ def get_summarized_usage(
41
+ tenant_id: Annotated[str, "Tenancy OCID"],
42
+ start_time: Annotated[
43
+ str,
44
+ "The value to assign to the time_usage_started property of this RequestSummarizedUsagesDetails."
45
+ "UTC date must have the right precision: hours, minutes, seconds, and second fractions must be 0",
46
+ ],
47
+ end_time: Annotated[
48
+ str,
49
+ "The value to assign to the time_usage_ended property of this RequestSummarizedUsagesDetails."
50
+ "UTC date must have the right precision: hours, minutes, seconds, and second fractions must be 0",
51
+ ],
52
+ group_by: Annotated[
53
+ list[str],
54
+ "Aggregate the result by."
55
+ "Allows values are “tagNamespace”, “tagKey”, “tagValue”, “service”,"
56
+ "“skuName”, “skuPartNumber”, “unit”, “compartmentName”, “compartmentPath”, “compartmentId”"
57
+ "“platform”, “region”, “logicalAd”, “resourceId”, “tenantId”, “tenantName”",
58
+ ],
59
+ compartment_depth: Annotated[float, "The compartment depth level."],
60
+ granularity: Annotated[
61
+ str,
62
+ 'Allowed values for this property are: "HOURLY", "DAILY", "MONTHLY". Default: "DAILY"',
63
+ ] = "DAILY",
64
+ query_type: Annotated[
65
+ str,
66
+ 'Allowed values are: "USAGE", "COST", "CREDIT", "EXPIREDCREDIT", "ALLCREDIT", "OVERAGE"'
67
+ 'Default: "COST"',
68
+ ] = "COST",
69
+ is_aggregate_by_time: Annotated[
70
+ bool,
71
+ "Specifies whether aggregated by time. If isAggregateByTime is true,"
72
+ "all usage or cost over the query time period will be added up.",
73
+ ] = False,
74
+ ) -> list[dict]:
75
+ usage_client = get_usage_client()
76
+ summarized_details = RequestSummarizedUsagesDetails(
77
+ tenant_id=tenant_id,
78
+ time_usage_started=start_time,
79
+ time_usage_ended=end_time,
80
+ granularity=granularity,
81
+ is_aggregate_by_time=is_aggregate_by_time,
82
+ query_type=query_type,
83
+ group_by=group_by,
84
+ compartment_depth=compartment_depth,
85
+ )
86
+
87
+ response = usage_client.request_summarized_usages(
88
+ request_summarized_usages_details=summarized_details
89
+ )
90
+ # Convert UsageSummary objects to dictionaries for proper serialization
91
+ summarized_usages = [
92
+ oci.util.to_dict(usage_summary) for usage_summary in response.data.items
93
+ ]
94
+ return summarized_usages
95
+
96
+
97
+ def main():
98
+ mcp.run()
99
+
100
+
101
+ if __name__ == "__main__":
102
+ main()
@@ -0,0 +1,56 @@
1
+ """
2
+ Copyright (c) 2025, Oracle and/or its affiliates.
3
+ Licensed under the Universal Permissive License v1.0 as shown at
4
+ https://oss.oracle.com/licenses/upl.
5
+ """
6
+
7
+ from unittest.mock import MagicMock, create_autospec, patch
8
+
9
+ import oci
10
+ import pytest
11
+ from fastmcp import Client
12
+ from oracle.oci_usage_mcp_server.server import mcp
13
+
14
+
15
+ class TestUsageTools:
16
+ @pytest.mark.asyncio
17
+ @patch("oracle.oci_usage_mcp_server.server.get_usage_client")
18
+ async def test_get_summarized_usage(self, mock_get_client):
19
+ mock_client = MagicMock()
20
+ mock_get_client.return_value = mock_client
21
+
22
+ mock_request_summarized_response = create_autospec(oci.response.Response)
23
+ mock_request_summarized_response.data = oci.usage_api.models.QueryCollection(
24
+ items=[
25
+ oci.usage_api.models.UsageSummary(
26
+ compartment_id="test_compartment_id",
27
+ compartment_name="test_compartment_name",
28
+ computed_amount=6.731118997232,
29
+ computed_quantity=69.842410393953,
30
+ service="Database",
31
+ )
32
+ ]
33
+ )
34
+
35
+ mock_client.request_summarized_usages.return_value = (
36
+ mock_request_summarized_response
37
+ )
38
+ print("mock response", mock_request_summarized_response)
39
+ async with Client(mcp) as client:
40
+ result = (
41
+ await client.call_tool(
42
+ "get_summarized_usage",
43
+ {
44
+ "tenant_id": "test_tenant_id",
45
+ "start_time": "2023-01-01T00:00:00Z",
46
+ "end_time": "2023-01-02T00:00:00Z",
47
+ "group_by": ["compartment"],
48
+ "compartment_depth": 1.0,
49
+ },
50
+ )
51
+ ).structured_content["result"]
52
+
53
+ assert len(result) == 1
54
+ assert result[0]["compartment_id"] == "test_compartment_id"
55
+ assert result[0]["service"] == "Database"
56
+ assert result[0]["computed_amount"] == 6.731118997232
@@ -0,0 +1,38 @@
1
+ [project]
2
+ name = "oracle.oci-usage-mcp-server"
3
+ version = "1.0.0"
4
+ description = "OCI Usage MCP server"
5
+ readme = "README.md"
6
+ license = "UPL-1.0"
7
+ license-files = ["LICENSE.txt"]
8
+ authors = [
9
+ {name = "Oracle MCP", email = "237432095+oracle-mcp@users.noreply.github.com"},
10
+ ]
11
+ requires-python = ">=3.13"
12
+ dependencies = [
13
+ "fastmcp==2.12.2",
14
+ "oci==2.160.0",
15
+ ]
16
+
17
+ classifiers = [
18
+ "License :: OSI Approved :: Universal Permissive License (UPL)",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python",
21
+ "Programming Language :: Python :: 3.13",
22
+ ]
23
+
24
+ [project.scripts]
25
+ "oracle.oci-usage-mcp-server" = "oracle.oci_usage_mcp_server.server:main"
26
+
27
+ [build-system]
28
+ requires = ["hatchling"]
29
+ build-backend = "hatchling.build"
30
+
31
+ [tool.hatch.build.targets.wheel]
32
+ packages = ["oracle"]
33
+
34
+ [dependency-groups]
35
+ dev = [
36
+ "pytest>=8.4.2",
37
+ "pytest-asyncio>=1.2.0",
38
+ ]