Add MCP tool execution middleware - #801
Merged
Merged
Conversation
|
I hit an error while handling your request (Model unavailable on AI Gateway free tier: Free tier users do not have access to this model. Upgrade to paid credits at https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%3Fmodal%3Dtop-up for unrestricted…). Please try again, rephrase, or reach out if it keeps failing. Error id: 68189220-f4b6-459f-9ddd-821219f104ea |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Expose a server-level
executeToolhook so stateful MCP hosts can wrap every registered tool for session-local ordering or other execution controls. The callback receives the registered tool name and anexecutefunction, while resources, prompts, and protocol notifications remain unaffected.This is the public-package prerequisite for serializing hosted Pascal tool calls without blocking MCP cancellation or SSE traffic.
Validation
bun test packages/mcp/src— 357 tests passed, 1,356 assertions.bunx biome check packages/mcp/src/server.ts packages/mcp/src/server.test.tsgit diff --checkanydiagnostics inpackages/mcp/src/tools/scene-query.ts.Note
Low Risk
Optional, additive server factory API; behavior is unchanged when
executeToolis omitted, with scope limited to tool registration wrapping.Overview
Adds an optional
executeToolhook oncreatePascalMcpServerso hosts can wrap every registered tool handler (e.g. to serialize access to a stateful bridge) without touching resources, prompts, or other MCP traffic.When provided,
installToolExecutortemporarily wrapsserver.registerToolso each tool callback runs through{ name, execute }before the real handler runs. A new integration test drivesget_sceneover in-memory transport and asserts the wrapper’s before/after ordering.Reviewed by Cursor Bugbot for commit ff953a1. Bugbot is set up for automated code reviews on this repo. Configure here.