11import configparser
2- import os
3- from dataclasses import asdict , dataclass , field
4- from typing import Any , Literal
2+ from dataclasses import asdict
3+ from typing import Literal
54
65from fastmcp .client import Client
7- from fastmcp .client .transports import PythonStdioTransport
8- from mcp .types import Tool
9-
10-
11- @dataclass
12- class SplunkMeta :
13- permissions : list [str ] = field ()
14- tool_type : str = field (default = "" )
15- schema_version : str = field (default = "" )
16- execution_mode : str = field (default = "" )
17- execution_endpoint : str = field (default = "" )
18-
19-
20- @dataclass
21- class McpInputOutputSchema :
22- type : Literal ["object" ] = "object"
23- properties : dict [str , Any ] = field (default_factory = lambda : {}) # pyright: ignore[reportExplicitAny]
24- required : list [str ] = field (default_factory = lambda : [])
6+ from mcp .types import Tool as MCPTool
257
8+ from splunklib .mcp .tools .models import (
9+ McpInputOutputSchema ,
10+ SplunkMeta ,
11+ )
2612
2713tool_reg_prefix = "app:mcp_tool"
2814
@@ -48,7 +34,7 @@ def match_input_schema(input: Literal["query_string"] | Literal["other"]):
4834 raise NotImplementedError ("We don't know what to put here lol" )
4935
5036
51- def parse_ai_conf (file_path : str ) -> list [Tool ]:
37+ def parse_ai_conf (file_path : str ) -> list [MCPTool ]:
5238 config = configparser .ConfigParser ()
5339 all_sections_len = config .read (file_path )
5440 if len (all_sections_len ) == 0 :
@@ -88,23 +74,12 @@ def parse_ai_conf(file_path: str) -> list[Tool]:
8874 return ini_tools
8975
9076
91- async def get_tools (server_path : str ):
77+ async def get_mcp_tools (server_path : str ) -> list [MCPTool ]:
78+ """Connects to local MCP server to get tools registered with a @tool decorator"""
9279 mcp_client = Client (server_path )
9380
94- tools = []
81+ tools : list [ MCPTool ] = []
9582 async with mcp_client :
9683 tools = await mcp_client .list_tools ()
9784
98- # TODO: Get registrations from ai.conf
99- # curr_path = os.path.join(os.getcwd(), "..", "default", "app.conf")
100- # yaml_tool_registrations: list[Tool] = parse_ai_conf(curr_path)
101-
10285 return tools
103-
104-
105- async def register_tools_from (file_paths : list [str ]) -> None :
106- """TODO
107- 1. `POST /tools` with MCP payload
108- 2.
109- """
110- print (file_paths )
0 commit comments