mcp: import-by-entrypoint tool execution and injected workspace param#55
Merged
Conversation
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
3ef3ba1 to
fa4038f
Compare
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.
Summary
inspect.getsource+ f-string source-paste inMcpSandbox._call_localwith a stdlib-only worker (_worker.py) that imports each tool's module and calls the function in place. Same per-call isolation (Landlock + seccomp,clean_env, deny-by-default), but tools can now use normal module-level imports, helpers, constants, and state. Lambdas, methods, and nested functions are rejected atadd_toolwith a clear error instead of failing cryptically in a subprocess. The worker is invoked by absolute path so it never drags the sandlock package (or its FFI cdylib) into the jail.workspaceparameter. A tool that declares a parameter namedworkspacereceives the sandbox workspace path automatically (injected at call time, hidden from the LLM schema, and not overridable by the model). Removes theSANDLOCK_WORKSPACEmagic string and all manual{"env": {...}}wiring; theenvcapability stays for real vars.sandlock/mcp/_builtins.pyand makecreate_serverlazy, so the per-call worker no longer re-imports themcpframework. Measured per-call import cost forsandlock-mcpdrops from ~450ms to ~60ms.Test Plan
cd python && pytest tests/ -q(294 passing locally)mcp;create_serverlazily importable.Notes
target/(unreadable inside the sandbox). Wheel installs are unaffected; fully removing it would require lazy-loading the cdylib in sandlock core.🤖 Generated with Claude Code