feat(mcp): add run and run_stop tools to the MCP server - #3998
Conversation
lkingland
left a comment
There was a problem hiding this comment.
Love that this one is starting to show why an MCP server helps do things a simple skill cannot do as elegantly.
Small suggestions around error and exit code handling below:
|
/retest |
|
Confirmed the follow-up against the earlier review — this landed cleanly:
Non-blocking: instructions tell agents to read /lgtm |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Ankitsinghsisodya, lkingland The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Just needs a rebase, then can re-approve |
d3782d0 to
3682d40
Compare
I have rebased it |
- Introduced 'run' tool for executing Functions locally, including detailed usage instructions. - Added 'run_stop' tool to stop Functions that were started with 'run'. - Updated documentation to reflect these new tools and their parameters. - Enhanced server structure to track active local runs. This update enhances the local development experience by allowing users to run and manage Functions directly from the MCP server.
- Updated formatting in mcp.go for better readability. - Replaced b.WriteString with fmt.Fprintf in process_test.go for consistency in string formatting. - Added missing newline at the end of tools_run_test.go to adhere to file formatting standards. These changes enhance code clarity and maintainability across the MCP package.
- Updated documentation to clarify that local operations (run/stop) are allowed even in read-only mode. - Improved the handling of function runs, ensuring that stopping a function with no active run is idempotent and succeeds without error. - Refactored the run registry to support reserving and activating function paths, preventing concurrent run conflicts. - Adjusted the run and run_stop tools to reflect the new behavior and requirements for absolute paths. These changes improve the usability of the MCP server for local function management while maintaining safety in read-only environments.
- Replaced hardcoded temporary paths with a new utility function `testAbsPath` to ensure platform-native absolute paths are used in tests for the 'run' and 'run_stop' tools. - This change enhances compatibility across different operating systems and improves the reliability of function execution in tests. These updates contribute to better path management in the MCP server's local function tools.
3682d40 to
0e56393
Compare
Can you approve it |
|
/lgtm |
Summary
Adds two new MCP tools that let clients start and stop a Function locally through the MCP server, mirroring
func run:run— builds the Function if needed, starts it in the background, and returns once it's ready with itspidandurl. Accepts optionalpath,registry,build, andportparameters. Only one run is allowed per Function path at a time.run_stop— gracefully stops a Function previously started withrun(SIGTERM, then SIGKILL after a grace period), matched by the same absolutepath.Both tools are disabled when the server is running in read-only mode, consistent with
deploy/delete.Implementation details
pkg/mcp/process.go: newprocessStarterabstraction that spawnsfunc run --jsonas a subprocess, parses its stdout for a JSON readiness line (host/port), and returns astopfunc to terminate it. Also introduces arunRegistryto track active runs keyed by function path.pkg/mcp/tools_run.go/pkg/mcp/tools_run_stop.go: tool definitions, input/output schemas, and handlers forrunandrun_stop.pkg/mcp/mock/process_starter.go: mockprocessStarterfor tests, injected via newWithProcessStarterserver option.pkg/mcp/mcp.go: wires up the new tools and default process starter/run registry on the server.pkg/mcp/instructions.md/pkg/mcp/instructions_warning.md: document the new tools' usage/path requirements and note them as disabled in read-only mode.Test plan
make test— new unit tests inpkg/mcp/process_test.go,pkg/mcp/tools_run_test.go, andpkg/mcp/tools_run_stop_test.gocover readonly rejection, duplicate-run rejection, start errors, and stop success/failure paths using the mock process starter.make check