5
5
from pydantic import ValidationError
6
6
7
7
from dive_mcp_host .host .tools .model_types import ClientState
8
+ from dive_mcp_host .httpd .conf .mcp_servers import Config
8
9
from dive_mcp_host .httpd .dependencies import get_app
9
10
from dive_mcp_host .httpd .routers .models import (
10
11
McpTool ,
@@ -42,7 +43,7 @@ async def initialized(
42
43
43
44
44
45
@tools .get ("/" )
45
- async def list_tools (
46
+ async def list_tools ( # noqa: PLR0912, C901
46
47
app : DiveHostAPI = Depends (get_app ),
47
48
) -> ToolsResult :
48
49
"""Lists all available MCP tools.
@@ -54,16 +55,20 @@ async def list_tools(
54
55
55
56
# get full list of servers from config
56
57
if (config := await app .mcp_server_config_manager .get_current_config ()) is not None :
57
- all_servers = set ( config . mcp_servers . keys ())
58
+ all_server_configs = config
58
59
else :
59
- all_servers = set ()
60
+ all_server_configs = Config ()
60
61
61
62
# get tools from dive host
62
63
for server_name , server_info in app .dive_host ["default" ].mcp_server_info .items ():
63
64
result [server_name ] = McpTool (
64
65
name = server_name ,
65
66
tools = [
66
- SimpleToolInfo (name = tool .name , description = tool .description or "" )
67
+ SimpleToolInfo (
68
+ name = tool .name ,
69
+ description = tool .description or "" ,
70
+ enabled = tool .enable ,
71
+ )
67
72
for tool in server_info .tools
68
73
],
69
74
description = "" ,
@@ -73,7 +78,7 @@ async def list_tools(
73
78
)
74
79
logger .debug ("active mcp servers: %s" , result .keys ())
75
80
# find missing servers
76
- missing_servers = all_servers - set (result .keys ())
81
+ missing_servers = set ( all_server_configs . mcp_servers . keys ()) - set (result .keys ())
77
82
logger .debug ("disabled mcp servers: %s" , missing_servers )
78
83
79
84
# get missing from local cache
@@ -90,6 +95,15 @@ async def list_tools(
90
95
for server_name in missing_servers :
91
96
if server_info := cached_tools .root .get (server_name , None ):
92
97
server_info .enabled = False
98
+
99
+ # Sync tool 'enabled' with 'exclude_tools'
100
+ if mcp_config := all_server_configs .mcp_servers .get (server_name ):
101
+ for tool in server_info .tools :
102
+ if tool .name in mcp_config .exclude_tools :
103
+ tool .enabled = False
104
+ else :
105
+ tool .enabled = True
106
+
93
107
result [server_name ] = server_info
94
108
else :
95
109
logger .warning ("Server %s not found in cached tools" , server_name )
0 commit comments