Conversation
…back GatekeeperLoopback wraps the gatekeeper session RpcStub in a Proxy whose 'get' trap returned Reflect.get(target, prop, target). For method names that are not in workerd's statically-known RPC surface for the stub type (such as dynamically-installed MCP tool methods added at runtime by installToolMethods), Reflect.get(rpcStub, prop) returns a pipeline property sub-stub. Calling that sub-stub as a function dispatches an RPC method named 'apply' to the remote receiver. Since McpSessionImpl does not implement 'apply', the call fails with: TypeError: The RPC receiver does not implement the method "apply" Fix: return a wrapper function for string property accesses that invokes target[prop](...args) directly on the session RpcStub. workerd treats this direct method call as a standard RPC method dispatch, which the remote session handles via its prototype chain where installToolMethods attached the delegates.
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Author
|
recheck |
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.
What does this change?
In
GatekeeperLoopback(packages/workshop-backend/src/overseer.ts), the proxy wrapping the gatekeeper sessionRpcStubusedReflect.get(target, prop, target)in itsgettrap.When an agent in
executeCodecalls a dynamically-installed MCP tool method (e.g.env.MY_MCP.myToolName({...})), that method name was attached at runtime to the session prototype byinstallToolMethods(), but is not inworkerd's statically-known RPC surface for the base stub type.Because the property is not in the static surface,
Reflect.get(rpcStub, prop)returns anRpcPropertypipeline sub-stub. Calling that sub-stub as a function causesworkerdto dispatch an RPC method named"apply"to the remote receiver (McpSessionImpl), which does not implement it, throwing:This patch changes the
gettrap to return a wrapper function for string property accesses:This causes
workerdto dispatchtarget[prop](...args)as a direct named RPC method call to the remote session, where the dynamically-installed method on the prototype chain handles it. Symbols and"then"continue to pass through directly.Why is this obviously correct and trivially verifiable?
gethandler insideGatekeeperLoopback(17 lines changed).Symbol.dispose) and"then"pass through viaReflect.get(target, prop, target), maintaining lifecycle and Promise resolution invariants.target[prop](...args)on the stub dispatches the same RPC call as before. For dynamically-installed prototype methods (which previously threwTypeError), it now dispatches the intended method call.Checklist
Checking every item does not guarantee acceptance. Maintainers determine whether
a pull request meets the contribution policy.