MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / executePassthroughCall

Function executePassthroughCall

packages/hosts/mcp/src/tool-server.ts:1984–2034  ·  view source on GitHub ↗
(
      address: ToolAddress,
      args: unknown,
      extra: McpRequestJoinKeys,
    )

Source from the content-addressed store, hash-verified

1982 // The client approves the generic destructive tool; upstream prompts use
1983 // native elicitation, or fail with an actionable result when unsupported.
1984 const executePassthroughCall = (
1985 address: ToolAddress,
1986 args: unknown,
1987 extra: McpRequestJoinKeys,
1988 ): Effect.Effect<McpToolResult, E> =>
1989 Effect.gen(function* () {
1990 yield* startMarker("mcp.host.tool.execute.start", {
1991 "mcp.tool.id": String(address),
1992 "mcp.tool.mode": "passthrough",
1993 "executor.tool.address": address,
1994 });
1995 const { url: supportsUrl } = getElicitationSupport(server);
1996 const native = makeMcpElicitationHandler(server, extra.requestId, debugLog);
1997 const { form: supportsForm } = getElicitationSupport(server);
1998 // Set when the tool asked the user for something this client cannot
1999 // relay. The handler has no error channel (a non-accept is a decline
2000 // to the executor), so the request is kept here and the whole call is
2001 // reported as unanswerable below — with what was asked, URL included —
2002 // instead of as "declined by the user", which nobody did.
2003 let unanswerable: ElicitationRequest | undefined;
2004 const onElicitation: ElicitationHandler = (ctx) => {
2005 // Every invoke is advertised as destructive, so the client's native
2006 // approval covers the selected ID and arguments, even if policy changed.
2007 // Tool-raised prompts still require their own response below.
2008 if (ctx.source === "policy") {
2009 return Effect.succeed({ action: "accept" as const, content: {} });
2010 }
2011 // Anything the tool itself asked for goes to the client natively
2012 // when it can take it; the native bridge already turns a URL
2013 // request into a form for form-only clients.
2014 if (supportsForm || (supportsUrl && Predicate.isTagged(ctx.request, "UrlElicitation"))) {
2015 return native(ctx);
2016 }
2017 unanswerable = ctx.request;
2018 return Effect.succeed({ action: "decline" as const });
2019 };
2020 const outcome = yield* engine.execute(passthroughCallCode(address, args), {
2021 onElicitation,
2022 });
2023 if (unanswerable) return elicitationUnsupportedResult(String(address), unanswerable);
2024 return toPassthroughResult(outcome);
2025 }).pipe(
2026 Effect.withSpan("mcp.host.tool.execute", {
2027 attributes: {
2028 "mcp.tool.id": String(address),
2029 "mcp.tool.mode": "passthrough",
2030 "executor.integration": parseToolAddress(String(address))?.integration,
2031 },
2032 }),
2033 Effect.annotateSpans(joinKeyAttributes(extra)),
2034 );
2035
2036 // --- tools ---
2037

Callers

nothing calls this directly

Calls 9

passthroughCallCodeFunction · 0.90
parseToolAddressFunction · 0.90
startMarkerFunction · 0.85
getElicitationSupportFunction · 0.85
toPassthroughResultFunction · 0.85
joinKeyAttributesFunction · 0.85
executeMethod · 0.65

Tested by

no test coverage detected