|
| 1 | +# Copyright © 2011-2026 Splunk, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"): you may |
| 4 | +# not use this file except in compliance with the License. You may obtain |
| 5 | +# a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | + |
| 15 | +import json |
| 16 | +import os |
| 17 | +import sys |
| 18 | +from typing import override |
| 19 | + |
| 20 | +sys.path.insert(0, "/splunklib-deps") |
| 21 | +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "lib")) |
| 22 | + |
| 23 | + |
| 24 | +from splunklib.ai.agent import Agent |
| 25 | +from splunklib.ai.tool_settings import RemoteToolSettings, ToolAllowlist, ToolSettings |
| 26 | +from tests.cre_testlib import CRETestHandler |
| 27 | + |
| 28 | +# BUG: For some reason the CRE process is started with a overridden trust store path, that |
| 29 | +# does not exist on the filesystem. As a workaround in such case if it does not exist, |
| 30 | +# remove the env, this causes the default CAs to be used instead. |
| 31 | +CA_TRUST_STORE = "/opt/splunk/openssl/cert.pem" |
| 32 | +if os.environ.get("SSL_CERT_FILE") == CA_TRUST_STORE and not os.path.exists( |
| 33 | + CA_TRUST_STORE |
| 34 | +): |
| 35 | + os.environ["SSL_CERT_FILE"] = "" |
| 36 | + |
| 37 | +# This app uses the splunk_get_indexes remote tool (from Splunk MCP Server App). |
| 38 | +# Requires that the MCP Server App is installed. |
| 39 | + |
| 40 | + |
| 41 | +class ToolTagsHandler(CRETestHandler): |
| 42 | + @override |
| 43 | + async def run(self) -> None: |
| 44 | + async with Agent( |
| 45 | + model=await self.model(), |
| 46 | + system_prompt="You are a helpful Splunk assistant", |
| 47 | + tool_settings=ToolSettings( |
| 48 | + local=False, |
| 49 | + remote=RemoteToolSettings( |
| 50 | + allowlist=ToolAllowlist(names=["splunk_get_indexes"]) |
| 51 | + ), |
| 52 | + ), |
| 53 | + service=self.service, |
| 54 | + ) as agent: |
| 55 | + assert len(agent.tools) > 0, "No remote tools loaded" |
| 56 | + |
| 57 | + assert len([t for t in agent.tools if len(t.tags) > 0]) > 0, ( |
| 58 | + f"No tools have tags. Tools: {[t.name for t in agent.tools]}" |
| 59 | + ) |
| 60 | + |
| 61 | + self.response.write( |
| 62 | + json.dumps( |
| 63 | + {"tools": [{"name": t.name, "tags": t.tags} for t in agent.tools]} |
| 64 | + ) |
| 65 | + ) |
0 commit comments