Remote Code Execution in functype-mcp-server via Unsanitized MCP Tool Input
The set_functype_version MCP tool in functype-mcp-server allows unauthenticated attackers to execute arbitrary code by passing a malicious package alias to pnpm, which the server subsequently executes via dynamic import.
The functype-mcp-server tool set_functype_version (v1.4.3) is vulnerable to Remote Code Execution (RCE) because it fails to sanitize user input before passing it to the pnpm add command. An attacker can supply a specially crafted version string, such as file:/path/to/malicious_package or other npm-supported alias syntaxes, to force the server to install an arbitrary local or remote package as the functype dependency. Immediately following this installation, the server triggers initDocsData(true), which dynamically imports the functype/cli module from the newly created installation path. This process executes any module-level JavaScript contained within the attacker's package with the full privileges of the MCP server process. This vulnerability is particularly dangerous for AI coding agents that automatically invoke MCP tools based on prompts, as it allows for indirect prompt injection to achieve full system compromise.
Attack Chain
- An attacker sends a
tools/callMCP request forset_functype_versionto an exposed MCP server. - The input
versionargument, containing a malicious alias likefile:/tmp/evil, is accepted by the server without validation (line 120,index.ts). - The server constructs a package specifier string
functype@file:/tmp/evil(line 123,index.ts). - The server executes
execFileSync("pnpm", ["add", spec], ...)which installs the malicious directory as thefunctypepackage (line 125,index.ts). - The server process calls the
initDocsData(true)function immediately after the installation finishes. - The server invokes
require.resolve("functype/cli"), which resolves to the path of the newly installed attacker package. - The server calls
import()on the resolved path, causing the Node.js runtime to execute the attacker's module code. - The attacker-controlled script performs malicious actions, such as reading environment variables or exfiltrating data, resulting in RCE.
Impact
Successful exploitation results in full Remote Code Execution with the privileges of the MCP server process. This impacts confidentiality, integrity, and availability. Victims include developers using the server as an AI coding assistant and environments where AI agents connect to this MCP server, enabling potential exploitation via indirect prompt injection from malicious documentation or web content.
Recommendation
- Upgrade
functype-mcp-serverto a patched version that validates theversionargument against an allowlist (e.g., regex for semver or dist-tags) and rejects alias syntaxes likefile:,npm:, or URL paths. - Modify the
pnpm addexecution logic to include the--ignore-scriptsflag to mitigate potential execution of arbitrary pre/post-install scripts, though this does not fix the dynamic import sink. - Restrict access to the MCP server by implementing authentication or by running the server in an isolated, non-privileged container with minimal access to the host filesystem.
Immediate actions
Patch functype-mcp-server to use input validation for the version argument.
Threat Hunt
Search for pnpm processes spawning from functype-mcp-server with unexpected arguments.
Data: Process creation events
Mitigations
Run MCP server in restricted environment.
RCE vulnerability
Detection coverage 1
Detect Suspicious MCP Tool Input for set_functype_version
highDetects exploitation attempts against set_functype_version by monitoring for suspicious package aliases in the version parameter, such as file paths or URI schemes.
Detection queries are available on the platform. Get full rules →