You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "yuqi1129 (via GitHub)" <gi...@apache.org> on 2026/06/12 06:14:26 UTC

[PR] [#11565][#11566] feat(mcp-server): add --token CLI param and inject Bearer token into Gravitino REST calls [gravitino]

yuqi1129 opened a new pull request, #11620:
URL: https://github.com/apache/gravitino/pull/11620

   ### What changes were proposed in this pull request?
   
   - Add a `token` field to `Setting`, masking its value in `__str__` to avoid leaking it into logs.
   - Add a `--token` CLI argument to `main.py`, falling back to the `GRAVITINO_TOKEN` environment variable.
   - `PlainRESTClientOperation` accepts a token and sets the `Authorization: Bearer` header on the httpx client when non-empty.
   - `RESTClientFactory.create_rest_client` passes the token through, and `GravitinoContext` propagates `setting.token` to the factory.
   - Update `MockOperation` to accept the token parameter for test compatibility.
   
   ### Why are the changes needed?
   
   The MCP server currently has no way to pass an authentication token to Gravitino REST calls, so it cannot work against a Gravitino server with auth enabled.
   
   Fix: #11565
   Fix: #11566
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. Adds a new `--token` CLI option (and `GRAVITINO_TOKEN` env var fallback) to the MCP server.
   
   ### How was this patch tested?
   
   Added 7 unit tests in `mcp-server/tests/unit/test_auth_flow.py` covering token injection, masking, and context propagation.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11565][#11566] feat(mcp-server): add --token CLI param and inject Bearer token into Gravitino REST calls [gravitino]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11620:
URL: https://github.com/apache/gravitino/pull/11620#issuecomment-4688955613

   <!-- coverage-report -->
   ### Code Coverage Report
   |Overall Project|66.96% **`+0.01%`**|:green_circle:|
   |:-|:-|:-:|
   |Files changed|67.42%|:green_circle:|
   <br>
   
   |Module|Coverage||
   |:-|:-|:-:|
   |aliyun|1.72%|:red_circle:|
   |api|46.82%|:green_circle:|
   |authorization-common|85.96%|:green_circle:|
   |aws|3.66%|:red_circle:|
   |azure|2.47%|:red_circle:|
   |catalog-common|10.4%|:red_circle:|
   |catalog-fileset|80.23%|:green_circle:|
   |catalog-glue|66.91%|:green_circle:|
   |catalog-hive|79.44%|:green_circle:|
   |catalog-jdbc-clickhouse|80.02%|:green_circle:|
   |catalog-jdbc-common|44.22%|:green_circle:|
   |catalog-jdbc-doris|80.28%|:green_circle:|
   |catalog-jdbc-hologres|54.03%|:green_circle:|
   |catalog-jdbc-mysql|79.23%|:green_circle:|
   |catalog-jdbc-oceanbase|78.38%|:green_circle:|
   |catalog-jdbc-postgresql|82.29%|:green_circle:|
   |catalog-jdbc-starrocks|78.51%|:green_circle:|
   |catalog-kafka|77.01%|:green_circle:|
   |catalog-lakehouse-generic|58.53%|:green_circle:|
   |catalog-lakehouse-hudi|79.1%|:green_circle:|
   |catalog-lakehouse-iceberg|85.79% **`+0.38%`**|:green_circle:|
   |catalog-lakehouse-paimon|79.15% **`-2.4%`**|:green_circle:|
   |catalog-model|77.72%|:green_circle:|
   |cli|44.51%|:green_circle:|
   |client-java|78.01%|:green_circle:|
   |common|49.88%|:green_circle:|
   |core|82.38% **`-0.28%`**|:green_circle:|
   |filesystem-hadoop3|77.27%|:green_circle:|
   |flink|0.0%|:red_circle:|
   |flink-common|45.72%|:green_circle:|
   |flink-runtime|0.0%|:red_circle:|
   |gcp|14.12%|:red_circle:|
   |hadoop-common|10.39% **`-2.83%`**|:red_circle:|
   |hive-metastore-common|53.9% **`+1.56%`**|:green_circle:|
   |iceberg-common|57.41% **`-3.59%`**|:green_circle:|
   |iceberg-rest-server|73.92%|:green_circle:|
   |idp-basic|86.18%|:green_circle:|
   |integration-test-common|0.0%|:red_circle:|
   |jobs|66.17%|:green_circle:|
   |lance-common|20.79%|:red_circle:|
   |lance-rest-server|60.54%|:green_circle:|
   |lineage|53.02%|:green_circle:|
   |optimizer|82.87%|:green_circle:|
   |optimizer-api|21.95%|:red_circle:|
   |server|85.73%|:green_circle:|
   |server-common|73.79%|:green_circle:|
   |spark|28.57%|:red_circle:|
   |spark-common|41.66%|:green_circle:|
   |trino-connector|40.13%|:green_circle:|
   
   <details>
   <summary>Files</summary>
   
   |Module|File|Coverage||
   |:-|:-|:-|:-:|
   |catalog-lakehouse-iceberg|[IcebergCatalogPropertiesMetadata.java](https://github.com/yuqi1129/gravitino/blob/a0db94cd1bf498b5bbf278075c376e03d616629c/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/IcebergCatalogPropertiesMetadata.java)|97.5%|:green_circle:|
   |catalog-lakehouse-paimon|[PaimonCatalogPropertiesMetadata.java](https://github.com/yuqi1129/gravitino/blob/a0db94cd1bf498b5bbf278075c376e03d616629c/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonCatalogPropertiesMetadata.java)|100.0%|:green_circle:|
   ||[FetchFileUtils.java](https://github.com/yuqi1129/gravitino/blob/a0db94cd1bf498b5bbf278075c376e03d616629c/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/kerberos/FetchFileUtils.java)|0.0%|:red_circle:|
   ||[KerberosClient.java](https://github.com/yuqi1129/gravitino/blob/a0db94cd1bf498b5bbf278075c376e03d616629c/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/kerberos/KerberosClient.java)|0.0%|:red_circle:|
   |core|[Configs.java](https://github.com/yuqi1129/gravitino/blob/a0db94cd1bf498b5bbf278075c376e03d616629c/core/src/main/java/org/apache/gravitino/Configs.java)|98.01%|:green_circle:|
   ||[JobManager.java](https://github.com/yuqi1129/gravitino/blob/a0db94cd1bf498b5bbf278075c376e03d616629c/core/src/main/java/org/apache/gravitino/job/JobManager.java)|85.94%|:green_circle:|
   ||[GravitinoEnv.java](https://github.com/yuqi1129/gravitino/blob/a0db94cd1bf498b5bbf278075c376e03d616629c/core/src/main/java/org/apache/gravitino/GravitinoEnv.java)|10.7%|:red_circle:|
   |hadoop-common|[FetchFileUtils.java](https://github.com/yuqi1129/gravitino/blob/a0db94cd1bf498b5bbf278075c376e03d616629c/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/FetchFileUtils.java)|0.0%|:red_circle:|
   ||[KerberosClient.java](https://github.com/yuqi1129/gravitino/blob/a0db94cd1bf498b5bbf278075c376e03d616629c/catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/kerberos/KerberosClient.java)|0.0%|:red_circle:|
   |hive-metastore-common|[KerberosClient.java](https://github.com/yuqi1129/gravitino/blob/a0db94cd1bf498b5bbf278075c376e03d616629c/catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/kerberos/KerberosClient.java)|83.12%|:green_circle:|
   ||[FetchFileUtils.java](https://github.com/yuqi1129/gravitino/blob/a0db94cd1bf498b5bbf278075c376e03d616629c/catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/kerberos/FetchFileUtils.java)|65.52%|:green_circle:|
   |iceberg-common|[FetchFileUtils.java](https://github.com/yuqi1129/gravitino/blob/a0db94cd1bf498b5bbf278075c376e03d616629c/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/authentication/kerberos/FetchFileUtils.java)|0.0%|:red_circle:|
   ||[KerberosClient.java](https://github.com/yuqi1129/gravitino/blob/a0db94cd1bf498b5bbf278075c376e03d616629c/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/authentication/kerberos/KerberosClient.java)|0.0%|:red_circle:|
   
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11565][#11566] feat(mcp-server): add --token CLI param and inject Bearer token into Gravitino REST calls [gravitino]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #11620:
URL: https://github.com/apache/gravitino/pull/11620#discussion_r3401146026


##########
mcp-server/mcp_server/core/setting.py:
##########
@@ -33,3 +33,14 @@ class Setting:
     tags: Set[str] = field(default_factory=set)
     transport: str = DefaultSetting.default_transport
     mcp_url: str = DefaultSetting.default_mcp_url
+    # Bearer token forwarded to Gravitino on every request.
+    # Empty string means anonymous (no Authorization header sent).
+    token: str = ""

Review Comment:
   `Setting` overrides `__str__()` to mask the token, but the dataclass-generated `__repr__()` will still include the raw `token` value (e.g., if the object is logged with `%r` or appears in exception/debug output). This is a real risk of leaking credentials even if `__str__` is safe.



##########
mcp-server/tests/unit/test_auth_flow.py:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+
+from mcp_server.client.plain.plain_rest_client_operation import (
+    PlainRESTClientOperation,
+)
+from mcp_server.core.context import GravitinoContext
+from mcp_server.core.setting import Setting
+
+
+class TestTokenInjection(unittest.TestCase):
+    """Verify Bearer token is correctly injected into the httpx client."""
+
+    def test_token_sets_authorization_header(self):
+        """When a token is provided, the httpx client carries Authorization: Bearer."""
+        client = PlainRESTClientOperation(
+            "my_metalake", "http://localhost:8090", token="my-secret-token"
+        )
+        headers = dict(client._catalog_operation.rest_client.headers)
+        self.assertEqual(headers.get("authorization"), "Bearer my-secret-token")

Review Comment:
   This assertion converts `httpx.Headers` to a `dict` and then looks up a lowercase key. Header casing in the resulting `dict` is not guaranteed across httpx versions; use `Headers.get(...)` (case-insensitive) instead, and close the underlying `AsyncClient` to avoid ResourceWarnings.



##########
mcp-server/tests/unit/test_auth_flow.py:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+
+from mcp_server.client.plain.plain_rest_client_operation import (
+    PlainRESTClientOperation,
+)
+from mcp_server.core.context import GravitinoContext
+from mcp_server.core.setting import Setting
+
+
+class TestTokenInjection(unittest.TestCase):
+    """Verify Bearer token is correctly injected into the httpx client."""
+
+    def test_token_sets_authorization_header(self):
+        """When a token is provided, the httpx client carries Authorization: Bearer."""
+        client = PlainRESTClientOperation(
+            "my_metalake", "http://localhost:8090", token="my-secret-token"
+        )
+        headers = dict(client._catalog_operation.rest_client.headers)
+        self.assertEqual(headers.get("authorization"), "Bearer my-secret-token")
+
+    def test_empty_token_no_authorization_header(self):
+        """When token is empty, no Authorization header is added."""
+        client = PlainRESTClientOperation(
+            "my_metalake", "http://localhost:8090", token=""
+        )
+        headers = dict(client._catalog_operation.rest_client.headers)
+        self.assertNotIn("authorization", headers)
+

Review Comment:
   Same as above: avoid relying on header key casing by using `Headers.get(...)`, and make sure to close the `AsyncClient` created by `PlainRESTClientOperation` to prevent ResourceWarnings.



##########
mcp-server/mcp_server/main.py:
##########
@@ -96,6 +98,15 @@ def _parse_args():
         help=f"The url of MCP server if using http transport. (default: {DefaultSetting.default_mcp_url})",
     )
 
+    parser.add_argument(
+        "--token",
+        type=str,
+        default=os.environ.get("GRAVITINO_TOKEN", ""),
+        help="Bearer token forwarded as Authorization header to Gravitino on every request. "
+        "Can also be set via the GRAVITINO_TOKEN environment variable. "
+        "When omitted, requests are sent without authentication.",
+    )

Review Comment:
   The new `--token` argument has important behavior (CLI value vs `GRAVITINO_TOKEN` fallback) but there’s no unit test covering parsing/precedence. Given the guideline that every change should have a corresponding test, please add a small test to validate: (1) env var is used when `--token` is omitted, and (2) `--token` overrides the env var when both are set.



##########
mcp-server/tests/unit/test_auth_flow.py:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+

Review Comment:
   These unit tests create `httpx.AsyncClient` instances (via `PlainRESTClientOperation`) but never close them, which can produce ResourceWarnings and leak sockets across the test run. Import `asyncio` so the tests can close the client with `aclose()`.



##########
mcp-server/tests/unit/test_auth_flow.py:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+
+from mcp_server.client.plain.plain_rest_client_operation import (
+    PlainRESTClientOperation,
+)
+from mcp_server.core.context import GravitinoContext
+from mcp_server.core.setting import Setting
+
+
+class TestTokenInjection(unittest.TestCase):
+    """Verify Bearer token is correctly injected into the httpx client."""
+
+    def test_token_sets_authorization_header(self):
+        """When a token is provided, the httpx client carries Authorization: Bearer."""
+        client = PlainRESTClientOperation(
+            "my_metalake", "http://localhost:8090", token="my-secret-token"
+        )
+        headers = dict(client._catalog_operation.rest_client.headers)
+        self.assertEqual(headers.get("authorization"), "Bearer my-secret-token")
+
+    def test_empty_token_no_authorization_header(self):
+        """When token is empty, no Authorization header is added."""
+        client = PlainRESTClientOperation(
+            "my_metalake", "http://localhost:8090", token=""
+        )
+        headers = dict(client._catalog_operation.rest_client.headers)
+        self.assertNotIn("authorization", headers)
+
+    def test_no_token_argument_no_authorization_header(self):
+        """When token argument is omitted entirely, no Authorization header is added."""
+        client = PlainRESTClientOperation("my_metalake", "http://localhost:8090")
+        headers = dict(client._catalog_operation.rest_client.headers)
+        self.assertNotIn("authorization", headers)
+
+
+class TestSettingTokenMasking(unittest.TestCase):
+    """Verify that the token is not exposed in Setting string representation."""
+
+    def test_token_masked_in_str(self):
+        """Token value must not appear in Setting.__str__."""
+        setting = Setting(metalake="ml", token="super-secret-token-value")
+        self.assertNotIn("super-secret-token-value", str(setting))
+        self.assertIn("***", str(setting))
+
+    def test_empty_token_shows_empty_in_str(self):
+        """When no token is set, __str__ shows empty placeholder."""
+        setting = Setting(metalake="ml", token="")
+        self.assertNotIn("***", str(setting))
+
+
+class TestGravitinoContextTokenPropagation(unittest.TestCase):
+    """Verify GravitinoContext passes token from Setting to the REST client."""
+
+    def test_context_propagates_token(self):
+        """Token from Setting reaches the httpx client Authorization header."""
+        setting = Setting(
+            metalake="ml",
+            gravitino_uri="http://localhost:8090",
+            token="ctx-token-xyz",
+        )
+        ctx = GravitinoContext(setting)
+        rest_client = ctx.rest_client()
+        headers = dict(rest_client._catalog_operation.rest_client.headers)
+        self.assertEqual(headers.get("authorization"), "Bearer ctx-token-xyz")
+

Review Comment:
   This test also depends on `dict(headers)` key casing and leaves the underlying `httpx.AsyncClient` unclosed (the context creates a client under the hood). Use `Headers.get(...)` and close the client at the end to avoid ResourceWarnings.



##########
mcp-server/tests/unit/test_auth_flow.py:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+
+from mcp_server.client.plain.plain_rest_client_operation import (
+    PlainRESTClientOperation,
+)
+from mcp_server.core.context import GravitinoContext
+from mcp_server.core.setting import Setting
+
+
+class TestTokenInjection(unittest.TestCase):
+    """Verify Bearer token is correctly injected into the httpx client."""
+
+    def test_token_sets_authorization_header(self):
+        """When a token is provided, the httpx client carries Authorization: Bearer."""
+        client = PlainRESTClientOperation(
+            "my_metalake", "http://localhost:8090", token="my-secret-token"
+        )
+        headers = dict(client._catalog_operation.rest_client.headers)
+        self.assertEqual(headers.get("authorization"), "Bearer my-secret-token")
+
+    def test_empty_token_no_authorization_header(self):
+        """When token is empty, no Authorization header is added."""
+        client = PlainRESTClientOperation(
+            "my_metalake", "http://localhost:8090", token=""
+        )
+        headers = dict(client._catalog_operation.rest_client.headers)
+        self.assertNotIn("authorization", headers)
+
+    def test_no_token_argument_no_authorization_header(self):
+        """When token argument is omitted entirely, no Authorization header is added."""
+        client = PlainRESTClientOperation("my_metalake", "http://localhost:8090")
+        headers = dict(client._catalog_operation.rest_client.headers)
+        self.assertNotIn("authorization", headers)
+
+
+class TestSettingTokenMasking(unittest.TestCase):
+    """Verify that the token is not exposed in Setting string representation."""
+
+    def test_token_masked_in_str(self):
+        """Token value must not appear in Setting.__str__."""
+        setting = Setting(metalake="ml", token="super-secret-token-value")
+        self.assertNotIn("super-secret-token-value", str(setting))
+        self.assertIn("***", str(setting))
+
+    def test_empty_token_shows_empty_in_str(self):
+        """When no token is set, __str__ shows empty placeholder."""
+        setting = Setting(metalake="ml", token="")
+        self.assertNotIn("***", str(setting))
+
+
+class TestGravitinoContextTokenPropagation(unittest.TestCase):
+    """Verify GravitinoContext passes token from Setting to the REST client."""
+
+    def test_context_propagates_token(self):
+        """Token from Setting reaches the httpx client Authorization header."""
+        setting = Setting(
+            metalake="ml",
+            gravitino_uri="http://localhost:8090",
+            token="ctx-token-xyz",
+        )
+        ctx = GravitinoContext(setting)
+        rest_client = ctx.rest_client()
+        headers = dict(rest_client._catalog_operation.rest_client.headers)
+        self.assertEqual(headers.get("authorization"), "Bearer ctx-token-xyz")
+
+    def test_context_anonymous_when_no_token(self):
+        """Empty token in Setting → no Authorization header in REST calls."""
+        setting = Setting(
+            metalake="ml",
+            gravitino_uri="http://localhost:8090",
+            token="",
+        )
+        ctx = GravitinoContext(setting)
+        rest_client = ctx.rest_client()
+        headers = dict(rest_client._catalog_operation.rest_client.headers)
+        self.assertNotIn("authorization", headers)

Review Comment:
   This test leaves the underlying `httpx.AsyncClient` unclosed and checks for a lowercase key in a `dict` created from `httpx.Headers` (header key casing isn’t guaranteed). Use `Headers.get(...)` and close the client to keep the unit test suite clean and non-leaky.



##########
mcp-server/tests/unit/test_auth_flow.py:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+
+from mcp_server.client.plain.plain_rest_client_operation import (
+    PlainRESTClientOperation,
+)
+from mcp_server.core.context import GravitinoContext
+from mcp_server.core.setting import Setting
+
+
+class TestTokenInjection(unittest.TestCase):
+    """Verify Bearer token is correctly injected into the httpx client."""
+
+    def test_token_sets_authorization_header(self):
+        """When a token is provided, the httpx client carries Authorization: Bearer."""
+        client = PlainRESTClientOperation(
+            "my_metalake", "http://localhost:8090", token="my-secret-token"
+        )
+        headers = dict(client._catalog_operation.rest_client.headers)
+        self.assertEqual(headers.get("authorization"), "Bearer my-secret-token")
+
+    def test_empty_token_no_authorization_header(self):
+        """When token is empty, no Authorization header is added."""
+        client = PlainRESTClientOperation(
+            "my_metalake", "http://localhost:8090", token=""
+        )
+        headers = dict(client._catalog_operation.rest_client.headers)
+        self.assertNotIn("authorization", headers)
+
+    def test_no_token_argument_no_authorization_header(self):
+        """When token argument is omitted entirely, no Authorization header is added."""
+        client = PlainRESTClientOperation("my_metalake", "http://localhost:8090")
+        headers = dict(client._catalog_operation.rest_client.headers)
+        self.assertNotIn("authorization", headers)

Review Comment:
   Same as above: use `Headers.get(...)` rather than converting to `dict` and checking for a specific key casing, and close the created `AsyncClient` to avoid leaking resources during the test run.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11565][#11566] feat(mcp-server): add --token CLI param and inject Bearer token into Gravitino REST calls [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 closed pull request #11620: [#11565][#11566] feat(mcp-server): add --token CLI param and inject Bearer token into Gravitino REST calls
URL: https://github.com/apache/gravitino/pull/11620


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11565][#11566] feat(mcp-server): add --token CLI param and inject Bearer token into Gravitino REST calls [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11620:
URL: https://github.com/apache/gravitino/pull/11620#issuecomment-4690683264

   Folding this into #11622. The token support here is reworked there to forward the raw `Authorization` header (supporting both OAuth2 `Bearer` and Gravitino simple-auth `Basic`) instead of assuming Bearer, so the MCP auth work now lives as a single foundational PR (#11622) with the write tools stacked on top in #11621. Closing in favor of #11622.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org