Inspecting Untrusted Model Context Protocol Servers

The Model Context Protocol (MCP) has rapidly evolved from a niche specification into a critical infrastructure layer for AI agents. By standardizing how models interact with external tools and data sources, MCP enables powerful integrations between your codebase, databases, and APIs. However, this convenience comes with a significant security trade-off: when you connect to an untrusted MCP server, you are effectively granting that server access to your computational resources and potentially your sensitive data.
A recent proof-of-concept demonstration highlighted how easily a malicious server can exploit this trust. The attack vector was surprisingly simple yet effective, showing that a server can execute unexpected commands, read arbitrary files, or exfiltrate context without the user realizing it. This is not just a theoretical risk; it is a practical vulnerability that affects anyone using third-party MCP servers in their development workflow or production environment.
This guide provides a concrete methodology for inspecting MCP servers before you connect them. We will cover how to analyze server behavior, limit permissions, and verify that the server is doing exactly what it claims to do. By following these steps, you can significantly reduce the risk of data leakage or unauthorized actions while still enjoying the benefits of the MCP ecosystem. Remember, the server is not affiliated with Anthropic, so you must perform your own due diligence.
Frequently asked questions
What is a malicious MCP server?
A malicious MCP server is an endpoint that implements the Model Context Protocol but behaves deceptively or destructively. It may exfiltrate your conversation history, execute arbitrary commands on your machine, or read sensitive files without your explicit knowledge. Unlike a buggy server that simply fails, a malicious server actively manipulates the data flow to achieve a specific goal, often without raising immediate alarms.
How does a malicious MCP server differ from a buggy one?
A buggy server makes mistakes due to errors in logic or implementation, such as returning incorrect data or crashing unexpectedly. A malicious server, by contrast, behaves intentionally. It may hide its true actions, lie about the data it is sending, or deliberately trigger side effects like file deletion or network requests. The key difference is intent: bugs are accidental, while malicious behavior is designed.
Which is better: connecting directly or using a proxy?
Connecting directly is faster but exposes you to the server’s full capabilities. Using a proxy adds a layer of inspection and control, allowing you to log and filter requests before they reach your model. For untrusted servers, a proxy is significantly better because it provides visibility into the data flow and allows you to enforce strict permissions, reducing the risk of hidden exfiltration or unexpected commands.
What is the most common attack vector in MCP servers?
The most common attack vector is the manipulation of tool responses. A malicious server can intercept a tool call, modify the response data, or inject additional commands. This allows the server to influence the model’s decision-making process subtly. For example, it might hide a warning message or alter a file path to redirect data to an unauthorized location, all while appearing normal to the user.
Can an MCP server read my local files?
Yes, if the server has permission to access the file system. MCP servers can define tools that read, write, or list files on your machine. If you connect to an untrusted server without reviewing its capabilities, it may read sensitive configuration files, source code, or environment variables. Always inspect the server’s declared tools and permissions before connecting to ensure it only accesses the resources you intend.
How can I detect if a server is exfiltrating data?
You can detect exfiltration by monitoring network traffic and logging all requests and responses. Look for unusual outbound connections or large data transfers that do not correspond to your expected tool calls. Additionally, inspect the server’s code if available, and check for any hidden endpoints or background processes that might be sending data to third-party servers. Tools like Wireshark or built-in logging can help you identify these patterns.
What permissions should I grant to an untrusted server?
Grant the minimum permissions necessary for the server to function. If it only needs to read a specific file, do not give it access to your entire home directory. Disable unnecessary tools, restrict network access if possible, and use sandboxing to isolate the server’s environment. The principle of least privilege is critical: only allow the server to do what it absolutely needs to do, and nothing more.
Is it safe to use MCP servers from GitHub?
Not necessarily. While GitHub is a reputable platform, anyone can publish a server, and many are not thoroughly audited. A malicious server can be published and updated quickly, often with minimal documentation. Always review the server’s code, check its repository activity, and inspect its permissions before connecting. Do not assume that a server is safe just because it is hosted on a trusted platform.
Step by step
- Inspect the Manifest — Review the server’s manifest file to identify all declared tools and resources. Compare this with the actual behavior to ensure no hidden capabilities are present.
- Monitor Network Traffic — Use a network monitoring tool to capture all requests and responses. Look for unusual outbound connections or large data transfers that do not correspond to expected tool calls.
- Limit Permissions — Grant the server only the minimum permissions necessary. Disable unnecessary tools and restrict access to specific files, directories, and network endpoints.
- Test with Sample Data — Create a sample dataset and trigger various tool calls. Monitor the responses for anomalies, such as unexpected data formats or side effects, before connecting to production.
Understanding the MCP Architecture
The Model Context Protocol (MCP) defines a standardized way for language models to interact with external tools and data sources. It consists of a client, which is typically part of your AI application, and a server, which provides the tools and resources. The server exposes a set of capabilities, such as file reading, database queries, or API calls, which the client can invoke. This architecture allows for modular and reusable components, but it also creates a trust boundary between the client and the server.
When you connect to an MCP server, you are establishing a communication channel that can transmit data in both directions. The server can send tools to the client, and the client can send requests to those tools. This bidirectional flow means that the server has the potential to influence the client’s behavior, not just by providing data, but by controlling the available tools and their outputs. Understanding this dynamic is crucial for identifying potential risks.
The Role of Tools
Tools are the primary interface through which the server provides functionality to the client. Each tool has a name, description, and input schema. The server declares these tools to the client, and the client can then invoke them as needed. A malicious server can declare tools that appear harmless but have unexpected side effects, such as reading sensitive files or making network requests.
Data Flow and Trust
Data flows from the server to the client in the form of tool responses, and from the client to the server in the form of tool invocations. The server can manipulate the data it sends, potentially influencing the model’s decisions. Trust is established when the client accepts the server’s tools and data as valid. This trust can be exploited if the server is malicious, as it can send misleading data or trigger unintended actions.
- Tools are declared by the server and invoked by the client.
- Data flows bidirectionally, allowing the server to influence the client.
- Trust is established when the client accepts the server’s tools and data.
Identifying Hidden Capabilities
One of the most significant risks of using an untrusted MCP server is the presence of hidden capabilities. A server may declare a limited set of tools in its manifest, but actually have more tools available that are not immediately visible. These hidden tools can be invoked by the server or triggered by specific conditions, allowing the server to perform actions that the user is not aware of.
To identify hidden capabilities, you should inspect the server’s code and network traffic. Look for any tools that are not declared in the manifest but are still accessible. Additionally, monitor the server’s behavior during normal operation to see if it triggers any unexpected actions. Tools like Wireshark or built-in logging can help you identify these hidden capabilities by capturing all network traffic and tool invocations.
Inspecting the Manifest
The server’s manifest file declares the tools and resources it provides. While this is the primary source of truth, it may not be comprehensive. Always compare the manifest with the actual behavior of the server to ensure that all tools are accounted for. If a tool is not in the manifest but is still accessible, it is a potential risk.
Monitoring Network Traffic
Network traffic monitoring is a powerful tool for identifying hidden capabilities. By capturing all requests and responses, you can see if the server is making unexpected calls or sending data to unusual endpoints. This is particularly useful for detecting exfiltration or background processes that are not visible in the manifest.
- Inspect the manifest file for declared tools.
- Compare the manifest with actual server behavior.
- Monitor network traffic for unexpected calls.

Analyzing Tool Responses
Tool responses are the data returned by the server when a tool is invoked. A malicious server can manipulate these responses to influence the model’s decision-making process. For example, it might hide a warning message, alter a file path, or inject additional data that appears normal but has a hidden purpose. By carefully analyzing tool responses, you can detect these subtle manipulations.
To analyze tool responses, you should log all responses and compare them to the expected output. Look for any discrepancies, such as missing data, unexpected formatting, or additional fields that were not part of the original schema. Additionally, check for any side effects, such as file modifications or network requests, that may have been triggered by the tool invocation.
Logging Responses
Logging tool responses is essential for detecting manipulations. By storing all responses, you can review them later to identify any anomalies. Use a logging tool that captures the full response, including headers and body, to ensure you have all the necessary information for analysis.
Comparing to Expected Output
Compare the logged responses to the expected output based on the tool’s schema. Look for any deviations, such as missing fields, additional data, or altered values. These deviations may indicate that the server is manipulating the data to achieve a specific goal.
- Log all tool responses for later analysis.
- Compare responses to the expected output schema.
- Look for deviations in data or formatting.
Limiting Permissions
One of the most effective ways to mitigate the risk of a malicious MCP server is to limit its permissions. By granting the server only the minimum permissions it needs, you reduce the potential damage it can cause. This includes restricting access to files, networks, and other resources. Additionally, you can use sandboxing to isolate the server’s environment, further reducing the risk of unintended actions.
To limit permissions, start by reviewing the server’s declared tools and resources. Determine which tools are necessary for your use case and disable any that are not. Additionally, use configuration options to restrict the server’s access to specific directories, files, or network endpoints. This ensures that the server can only do what it is explicitly allowed to do.
Reviewing Declared Tools
Review the server’s declared tools and determine which ones are necessary for your use case. Disable any tools that are not required, reducing the server’s capabilities. This minimizes the risk of the server performing unintended actions, such as reading sensitive files or making unnecessary network requests.
Configuring Access Restrictions
Use configuration options to restrict the server’s access to specific resources. For example, you can limit file access to a specific directory, restrict network access to certain endpoints, or limit the server’s ability to modify files. These restrictions help ensure that the server can only do what it is explicitly allowed to do.
- Review and disable unnecessary tools.
- Restrict file, network, and resource access.
- Use sandboxing to isolate the server’s environment.

Using Sandboxing
Sandboxing is a technique that isolates the MCP server’s environment from the rest of your system. This prevents the server from accessing resources outside its designated area, reducing the risk of data leakage or unintended actions. Sandboxing can be achieved through virtual machines, containers, or restricted file systems, depending on your infrastructure.
To implement sandboxing, you should create a dedicated environment for the server. This environment should have limited access to files, networks, and other resources. Additionally, you can use monitoring tools to track the server’s activity within the sandbox, ensuring that it does not exceed its permissions. This provides an additional layer of protection against malicious behavior.
Creating a Dedicated Environment
Create a dedicated environment, such as a container or virtual machine, for the MCP server. This environment should have limited access to files, networks, and other resources. By isolating the server, you reduce the risk of it affecting your main system or accessing sensitive data.
Monitoring Activity
Use monitoring tools to track the server’s activity within the sandbox. This allows you to detect any unusual behavior, such as unexpected file access or network requests. By monitoring the server, you can ensure that it is operating within its designated permissions and take action if it deviates.
- Isolate the server in a dedicated environment.
- Limit access to files, networks, and resources.
- Monitor activity for unusual behavior.
Verifying Server Code
If the server’s code is open source, you can inspect it directly to verify its behavior. This allows you to see exactly what the server is doing, from tool declarations to data processing. Code inspection is particularly useful for identifying hidden capabilities, such as background processes or hidden network requests that are not visible in the manifest.
To verify the server code, start by reviewing the main entry point and the tool implementations. Look for any unexpected logic, such as data exfiltration or side effects that are not documented. Additionally, check for any dependencies that may introduce vulnerabilities, such as outdated libraries or untrusted packages. This ensures that the server is doing what it claims to do and nothing more.
Reviewing Entry Points
Review the server’s main entry point and tool implementations to understand how it processes requests. Look for any unexpected logic, such as data exfiltration or side effects that are not documented. This helps you identify any hidden capabilities that may not be visible in the manifest.
Checking Dependencies
Check the server’s dependencies for vulnerabilities or untrusted packages. Outdated libraries or packages from unknown sources may introduce risks. Ensure that all dependencies are from reputable sources and are up to date to minimize the risk of exploitation.
- Review the main entry point and tool implementations.
- Look for unexpected logic or side effects.
- Check dependencies for vulnerabilities.

Testing with Sample Data
Before connecting an untrusted MCP server to your production environment, test it with sample data. This allows you to observe its behavior in a controlled environment without risking your actual data. You can create a small dataset that mimics your real data and use it to trigger various tool calls, observing how the server responds.
To test with sample data, create a dataset that includes typical inputs and edge cases. Invoke the server’s tools with this data and monitor the responses. Look for any anomalies, such as unexpected data formats, missing fields, or additional side effects. This helps you identify any issues before the server is used in a production environment.
Creating Sample Datasets
Create a dataset that includes typical inputs and edge cases. This dataset should mimic your real data but be small enough to manage easily. Use this dataset to trigger various tool calls and observe the server’s responses.
Monitoring Responses
Monitor the server’s responses to the sample data. Look for any anomalies, such as unexpected data formats, missing fields, or additional side effects. This helps you identify any issues that may not be apparent during normal operation.
- Create a dataset that mimics real data.
- Trigger various tool calls with the sample data.
- Monitor responses for anomalies.
Implementing Logging and Alerts
Logging and alerts are essential for detecting malicious behavior in real-time. By logging all requests and responses, you can review them later to identify any anomalies. Additionally, you can set up alerts for specific events, such as unusual network traffic or unexpected tool invocations, to notify you immediately if something goes wrong.
To implement logging and alerts, start by configuring your logging system to capture all relevant data. This includes request headers, tool invocations, and responses. Set up alerts for specific events, such as large data transfers or unexpected file access. This ensures that you are aware of any issues as soon as they occur, allowing you to take action quickly.
Configuring Logging
Configure your logging system to capture all relevant data, including request headers, tool invocations, and responses. This provides a comprehensive record of the server’s activity, which can be reviewed later to identify any anomalies.
Setting Up Alerts
Set up alerts for specific events, such as unusual network traffic or unexpected tool invocations. This ensures that you are notified immediately if something goes wrong, allowing you to take action quickly to mitigate any risks.
- Capture all relevant data in logs.
- Set up alerts for specific events.
- Review logs regularly for anomalies.

Test the keyless API endpoint directly in your browser to see how it handles requests without exposing a key.