|
| 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 uuid import uuid4 |
| 19 | + |
| 20 | +sys.path.insert(0, "/splunklib-deps") |
| 21 | +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "lib")) |
| 22 | + |
| 23 | +from typing import override |
| 24 | + |
| 25 | +from splunklib.ai.agent import ( |
| 26 | + _get_splunk_username, # pyright: ignore[reportPrivateUsage] |
| 27 | +) |
| 28 | +from splunklib.ai.tools import ( |
| 29 | + _list_all_tools, # pyright: ignore[reportPrivateUsage] |
| 30 | + connect_remote_mcp, |
| 31 | +) |
| 32 | +from tests.cre_testlib import CRETestHandler |
| 33 | + |
| 34 | +# BUG: For some reason the CRE process is started with a overridden trust store path, that |
| 35 | +# does not exist on the filesystem. As a workaround in such case if it does not exist, |
| 36 | +# remove the env, this causes the default CAs to be used instead. |
| 37 | +CA_TRUST_STORE = "/opt/splunk/openssl/cert.pem" |
| 38 | +if os.environ.get("SSL_CERT_FILE") == CA_TRUST_STORE and not os.path.exists( |
| 39 | + CA_TRUST_STORE |
| 40 | +): |
| 41 | + os.environ["SSL_CERT_FILE"] = "" |
| 42 | + |
| 43 | +# This handler connects directly to the Splunk MCP Server App and logs the raw |
| 44 | +# MCP tool list response, verifying that tool metadata includes tags. |
| 45 | + |
| 46 | + |
| 47 | +class ToolTagsHandler(CRETestHandler): |
| 48 | + @override |
| 49 | + async def run(self) -> None: |
| 50 | + import asyncio |
| 51 | + |
| 52 | + splunk_username = await asyncio.to_thread( |
| 53 | + lambda: _get_splunk_username(self.service) |
| 54 | + ) |
| 55 | + |
| 56 | + async with connect_remote_mcp( |
| 57 | + service=self.service, |
| 58 | + app_id="ai_agentic_test_app", |
| 59 | + trace_id=str(uuid4()), |
| 60 | + splunk_username=splunk_username, |
| 61 | + ) as session: |
| 62 | + assert session is not None, "MCP Server App not available" |
| 63 | + |
| 64 | + raw_tools = await _list_all_tools(session) |
| 65 | + |
| 66 | + assert len(raw_tools) > 0, "No tools returned by MCP Server App" |
| 67 | + |
| 68 | + tools_with_tags = [ |
| 69 | + t for t in raw_tools if ((t.meta or {}).get("splunk") or {}).get("tags") |
| 70 | + ] |
| 71 | + assert len(tools_with_tags) > 0, ( |
| 72 | + f"No tools have tags. Raw tools: {json.dumps([t.model_dump() for t in raw_tools], indent=2)}" |
| 73 | + ) |
| 74 | + |
| 75 | + self.response.write(json.dumps([t.model_dump() for t in raw_tools], indent=2)) |
0 commit comments