Skip to content

McpServer.toolkit should not hoist tool dependencies into the registration step #9114

Closed

Description

@Avaq

What is the problem this feature would solve?

The fix made in #8842 exposes a problem with the design of McpServer.toolkit that went previously unnoticed in our usage of the function: That we must provide all tool dependencies during layer construction.

Our tools have runtime dependencies that are supplied by the request (a user session, etc) and cannot be met earlier. Previously, these requirements went unmet during layer construction, and were then met without problem during tool execution.

Now, no mechanism exists to mark dependencies as execution dependencies, and so we cannot construct our McpServer layer any more.

What is the feature you are proposing to solve the problem?

MCP registration needs a way to defer dependencies to invocation time. Either through router-style markers such as Request<"Requires", Session>, or an option passed during construction of the toolkit registration layer: McpServer.toolkit(MyToolkit, { executionDependencies: [Session] }). Those dependencies should remain requirements of the request handler rather than of server construction.

What alternatives have you considered?

  • Optional service lookup: hides a mandatory dependency and replaces compile-time safety with a runtime failure.
  • Custom toHttpEffect adapter: works in a prototype, but this needs a type assertion, and relies on registration not actually reading the dependency during construction.
  • Request-local server construction: satisfies dependencies honestly, but requires changing our sessionful protocol choice (McpProtocol.v2025_11_25) and legacy elicitation flow. Generally, constructing a whole MCP server on every request seems like a bad idea, but it's the only non-hacky solution that the current API design pushes us to.
  • Custom RPC/Toolkit integration: preserves explicit execution requirements, but means taking over substantial MCP transport and lifecycle handling.

Activity

  1. added
    enhancement
    on Oct 13, 2026
  2. self-assigned this
    on Oct 13, 2026
  3. changed the title [-]`McpServer.toolkit` should not lift tool dependencies into the registration step[/-] [+]`McpServer.toolkit` should not hoist tool dependencies into the registration step[/+] on Oct 13, 2026
  4. Avaq commented on Oct 13, 2026

    @Avaq
    ContributorAuthor

    A PR linked to #8842 (pingdotgg/t3code#17571) encountered the same problem in another code-base, and worked around it using one of the alternatives I also considered: A type assertion to suppress the requirement at compile time, hope no one reads it during construction, and then supply it at runtime:

    https://github.com/pingdotgg/t3code/blob/75ada22b93c8cad2bdd4c4319840ae5517409901/apps/server/src/mcp/McpHttpServer.ts#L763-L784

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions