Commit 79dbd57
authored
Narrow a Bot's tools in the query, not after reading every one (#184)
`listForAgent` selected every row in `mcp_tools` and then discarded the ones the
Bot was not granted, with a linear `includes` over the grants per row. It is the
run-time path: it runs on every run of every Bot, before anything else, and it
sits underneath the tool selection added in #178 — so its cost is paid first, on
exactly the large catalogues that change exists to make work. At the thousand
tools #119 names as the target, that is a thousand rows across the wire and a
thousand walks of the grant list to offer a handful.
The query now names the servers the Bot holds something from, which is a
predicate the `(server_id, name)` primary key can use, and the grant list is a
Set rather than an array. `knownToolRefs` in this same file already did it this
way, with the same reasoning written above it; this is the run-time half catching
up with the save-time half.
Narrowing by server rather than by exact pair on purpose. A clause per grant
would be exact, and a server's own tool list is already the bound on what comes
back, so it buys little for a where clause that grows with the grants. The exact
ref is still matched after the read, and that match is now load-bearing in a way
it was not before: narrowing by server alone would offer every tool of any
server the Bot holds anything from. There is a test for that, because every
other test in the file passes without it.
Behaviour is unchanged. Same tools, same order, same refusals.1 parent 0ef5b01 commit 79dbd57
2 files changed
Lines changed: 65 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1050 | 1050 | | |
1051 | 1051 | | |
1052 | 1052 | | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
1053 | 1069 | | |
1054 | | - | |
| 1070 | + | |
1055 | 1071 | | |
1056 | | - | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
1057 | 1079 | | |
1058 | | - | |
| 1080 | + | |
1059 | 1081 | | |
1060 | 1082 | | |
1061 | 1083 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
136 | 138 | | |
137 | 139 | | |
138 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
139 | 157 | | |
140 | 158 | | |
141 | 159 | | |
| |||
157 | 175 | | |
158 | 176 | | |
159 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
160 | 184 | | |
161 | 185 | | |
162 | 186 | | |
| |||
219 | 243 | | |
220 | 244 | | |
221 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
222 | 262 | | |
223 | 263 | | |
224 | 264 | | |
| |||
0 commit comments