|
1 | | -import type { RpcFunctionAgentOptions, RpcFunctionDefinitionAnyWithContext, RpcFunctionsCollector, RpcFunctionType } from 'devframe/rpc' |
| 1 | +import type { RpcFunctionAgentOptions, RpcFunctionDefinitionAnyWithContext, RpcFunctionsCollector } from 'devframe/rpc' |
2 | 2 | import { getRpcHandler } from 'devframe/rpc' |
3 | 3 | import { toAgentToolName } from 'devframe/utils/agent-tool-name' |
4 | 4 | // Pure, browser-safe projections shared with the node-side MCP adapter |
5 | 5 | // (`@devframes/agentic/mcp`, via `devframe/internal`), so the WebMCP surface |
6 | 6 | // cannot drift from the MCP one. |
| 7 | +import { resolveAgentSafety } from '../agent/safety' |
7 | 8 | import { argsToJsonSchema } from '../agent/to-json-schema' |
8 | 9 | import { toolInputToRpcArgs } from '../tool-input' |
9 | 10 |
|
@@ -132,14 +133,15 @@ export function registerWebMcpTools<LocalFunctions, SetupContext>( |
132 | 133 | } |
133 | 134 |
|
134 | 135 | const controller = new AbortController() |
| 136 | + const safety = resolveAgentSafety(def.type, agent) |
135 | 137 | const result = modelContext.registerTool({ |
136 | 138 | name, |
137 | 139 | description: agent.description, |
138 | 140 | inputSchema: argsToJsonSchema(def.args), |
139 | 141 | annotations: { |
140 | 142 | title: agent.title ?? def.name, |
141 | | - readOnlyHint: resolveSafety(def, agent) === 'read', |
142 | | - destructiveHint: resolveSafety(def, agent) === 'destructive', |
| 143 | + readOnlyHint: safety === 'read', |
| 144 | + destructiveHint: safety === 'destructive', |
143 | 145 | }, |
144 | 146 | execute: args => executeRpcTool(def, clientRpc.context, args), |
145 | 147 | }, { signal: controller.signal }) |
@@ -180,16 +182,6 @@ export function registerWebMcpTools<LocalFunctions, SetupContext>( |
180 | 182 | } |
181 | 183 | } |
182 | 184 |
|
183 | | -function resolveSafety( |
184 | | - def: RpcFunctionDefinitionAnyWithContext<any>, |
185 | | - agent: RpcFunctionAgentOptions, |
186 | | -): 'read' | 'action' | 'destructive' { |
187 | | - if (agent.safety) |
188 | | - return agent.safety |
189 | | - const type: RpcFunctionType = def.type ?? 'query' |
190 | | - return type === 'static' || type === 'query' ? 'read' : 'action' |
191 | | -} |
192 | | - |
193 | 185 | async function executeRpcTool<SetupContext>( |
194 | 186 | def: RpcFunctionDefinitionAnyWithContext<SetupContext>, |
195 | 187 | context: SetupContext, |
|
0 commit comments