Testing MCP Servers Directly with MCP Inspector
If you test an AI assistant by trying prompt injection strings for hours, you are testing the wrong boundary. An LLM is a non-deterministic routing engine. When the model decides to run a task, it emits a structured req
If you test an AI assistant by trying prompt injection strings for hours, you are testing the wrong boundary.
An LLM is a non-deterministic routing engine. When the model decides to run a task, it emits a structured request to a Model Context Protocol (MCP) server Anthropic's open-source release. That server executes real code on an operating system or database.
To find security vulnerabilities quickly, remove the model entirely. You can interact with the server directly over raw JSON-RPC 2.0 and test its functions like any standard API.
Why prompt injection is the wrong testing tool
Many developers assume their MCP tools will only ever receive clean arguments generated by an AI model. Because the assistant usually behaves politely, developers often forget defensive parameter validation AppSec research on agentic tools.
If you only test tools by arguing with a chatbot interface, you face two hurdles. First, the model's safety guardrails may block your test payloads before they reach the tool. Second, the model might rewrite your strings into valid values.
Real attackers do not need to persuade the model if they can interact with the protocol transport directly. Connecting an evaluation client straight to the server lets you audit the actual application boundaries without token burn or model interference.
Talking directly to JSON-RPC
Anthropic maintains an interactive testing harness called MCP Inspector (@modelcontextprotocol/inspector) that connects directly to servers over standard input and output (stdio) or HTTP transports MCP Inspector documentation.
Instead of opening a web chat interface, you can run the Inspector from your terminal to list all declared capabilities:
# Enumerate declared tools directly without invoking an LLM
npx @modelcontextprotocol/inspector --cli \
python3 server.py -- \
--method tools/list --format json
The target server replies with a list of tools, descriptions, and JSON Schema definitions for every accepted property. The double dash (--) ensures Inspector does not confuse the server's runtime flags with its own options.
Once you have the schema, you can invoke any tool immediately with tools/call. Here is how a tester sends raw payload arguments straight into the target function:
# Send a command injection probe directly to a tool argument
npx @modelcontextprotocol/inspector --cli \
python3 server.py -- \
--method tools/call \
--tool-name git_log \
--tool-args-json '{"branch": "; id"}'
Every parameter travels directly to the backend handler. You get immediate, deterministic feedback.
Spotting the dangerous sink
Consider an MCP server designed to let an agent inspect Git repositories. Below is an illustrative vulnerable implementation written in Python using FastMCP:
# Illustrative vulnerable FastMCP server (server.py)
from mcp.server.fastmcp import FastMCP
import subprocess
mcp = FastMCP("DevOps-Helper")
@mcp.tool()
def git_log(branch: str) -> str:
"""Returns commit logs for a git branch."""
# Dangerous sink: shell=True with concatenated user input
result = subprocess.run(
f"git log --oneline {branch}",
shell=True,
capture_output=True,
text=True
)
return result.stdout or result.stderr
if __name__ == "__main__":
# Runs the stdio JSON-RPC listening loop
mcp.run()
The author expected the LLM to pass clean branch names such as main or feature-login. When you send ; id with MCP Inspector, subprocess.run passes the raw string to the system shell, which executes the appended command with the server process privileges.
Reviewing how data reaches sensitive operations is a fundamental skill in software auditing. To see more practical examples of input tracing in modern applications, take a look at the CodeReviewLab guide to tracing untrusted input to dangerous sinks.
Securing the tool handler
Fixing this flaw requires two defences. First, avoid running system commands through a shell interpreter. Second, enforce a strict allowlist on caller arguments before they reach any operating system API.
Here is an illustrative remediated version of the tool:
# Illustrative secure FastMCP server (server.py)
from mcp.server.fastmcp import FastMCP
import subprocess
import re
mcp = FastMCP("DevOps-Helper")
BRANCH_PATTERN = re.compile(r"^[a-zA-Z0-9_\-\.\/]+$")
@mcp.tool()
def git_log(branch: str) -> str:
"""Returns commit logs for a git branch."""
# Reject unexpected characters and leading command flags
if not BRANCH_PATTERN.match(branch) or branch.startswith("-"):
raise ValueError("Invalid branch name format.")
# Safe sink: direct array arguments with shell=False
result = subprocess.run(
["git", "log", "--oneline", "--", branch],
shell=False,
capture_output=True,
text=True,
timeout=10,
check=False
)
return result.stdout or result.stderr
if __name__ == "__main__":
mcp.run()
This pattern disables shell meta-character parsing entirely. Passing -- ensures Git does not treat a branch name starting with a dash as an option flag.
Parameter validation inside the tool protects the underlying host, but it does not prevent an LLM from misinterpreting poisoned data returned by external tools. For a deeper breakdown of system boundaries in agent environments, check out the CodeReviewLab guide to MCP security.
When the server attacks your inspector
There is an important catch when testing third-party or untrusted MCP servers. Your testing harness is also software, and it can be vulnerable.
Early releases of @modelcontextprotocol/inspector had serious flaws. Versions prior to 0.14.1 ran an unauthenticated local Node proxy binding to 0.0.0.0 on port 6277 CVE-2025-49596 security advisory. This allowed malicious websites to execute commands locally through cross-origin requests or DNS rebinding.
Later, stored cross-site scripting in the OAuth debugging interface allowed rogue servers to trigger local command execution Miggo Security's writeup on CVE-2025-58444. Even in the modern v2 series, versions before 2.12.0 could be exploited by a malicious server returning forged OAuth URLs that injected PowerShell commands on Windows systems Pillar Security advisory for CVE-2026-119025.
When assessing an untrusted server, keep these precautions in mind:
- Always update
@modelcontextprotocol/inspectorto version 2.12.0 or later before connecting to untrusted hosts. - Never start the Inspector with authentication disabled using flags such as
DANGEROUSLY_OMIT_AUTH=true. - Run your assessment inside an isolated container or virtual machine rather than directly on your primary workstation.
Review checks for MCP servers
When auditing or building an MCP server, verify these core areas:
- Input boundaries: Validate every argument against a strict schema. Reject undeclared properties and unexpected types.
-
Process isolation: Never pass tool arguments into
shell=Trueor unescaped terminal strings. Pass isolated argument lists directly to executables. - Transport authentication: If using remote Streamable HTTP transports, ensure the server authenticates callers and checks OAuth token scopes against expected resources.
-
Description integrity: Audit tool descriptions returned by
tools/listto ensure external sources have not embedded prompt injection payloads inside metadata.
Testing tools directly gives you fast, repeatable results without relying on model luck. If you want to practise tracing untrusted inputs across different languages and frameworks, visit CodeReviewLab to work through hands-on review challenges.
Have you tried automating MCP server checks in your CI pipeline yet?
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.