Skip to content

executeToolCall and model dispatch resolve nested MCPL tool prefixes differently #230

Closed

Description

@Anarchid

Found while reviewing #220 (second-reviewer probe, re-checked by reading). Present on main (e457abd).

What happens. The two dispatch entry points resolve an MCPL-prefixed tool name differently:

  • model dispatch uses resolveMcplTool — the server that listed the tool, else the longest matching prefix:

    agent-framework/src/framework.ts

    Lines 11956 to 11966 in e457abd

    private resolveMcplTool(toolName: string): [string, string] | null {
    const listedBy = this.mcplToolServers?.get(toolName);
    let best: [string, string] | null = null;
    for (const [prefix, serverId] of this.mcplPrefixMap ?? []) {
    if (!toolName.startsWith(prefix + '--')) continue;
    if (serverId === listedBy) return [serverId, prefix];
    if (!best || prefix.length > best[1].length) best = [serverId, prefix];
    }
    return best;
    }
  • executeToolCallFrom (public executeToolCall, ModuleContext.callTool) takes the first configured server whose prefix matches:

    agent-framework/src/framework.ts

    Lines 10904 to 10913 in e457abd

    if (this.mcplServerRegistry) {
    // Check if this is an MCPL-prefixed tool
    const prefix = call.name.split('--').slice(0, -1).join('--');
    const serverConfigs = this.mcplServerConfigs;
    for (const [, config] of serverConfigs) {
    const toolPrefix = config.toolPrefix ?? `mcpl--${config.id}`;
    if (call.name.startsWith(toolPrefix + '--')) {
    return this.executeMcplToolCall(call, config);
    }
    }

With nested prefixes (foo and foo--bar), foo--bar--x reaches server foo--bar as x from the model, but server foo as bar--x from a programmatic caller, depending on config insertion order. Any name-based permission check (per-agent allowedTools, #220) is evaluated against the declared name and so passes for both.

Direction. Route executeToolCallFrom through resolveMcplTool so both entries agree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions