A method, system, equipment, and medium for security access assessment of MCP tools.

By constructing a capability contract graph and an expected call graph, test cases are generated and executed in an isolated sandbox. Cross-layer runtime events are collected, consistency verification and counterfactual replay are performed, and abnormal behavior in the MCP tool server is identified. This solves the problem of identifying unauthorized behavior in existing technologies and achieves efficient and reliable evaluation and admission policy generation.

CN123116259APending Publication Date: 2026-11-17NO 30 INST OF CHINA ELECTRONIC TECH GRP CORP +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611618956.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-20
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing technologies are insufficient to effectively identify and prevent unauthorized behavior in MCP tool servers, and dynamic sandbox testing methods suffer from resource waste and high false alarm rates.

Method used

By parsing the declaration information of the MCP tool service, a capability contract graph is constructed. Combined with the call intent, an expected call graph is constructed, test cases are generated, and they are executed in an isolated sandbox. Cross-layer running events are collected, correlated into a causal behavior graph, and consistency verification and counterfactual replay are performed. Abnormal behavior paths are identified and risk scores and admission policies are generated.

Benefits of technology

The reliability assessment of the MCP tool server was realized, the false alarm rate was reduced, the operability of the assessment conclusions and the coverage optimization capability were improved, and a closed-loop process from graph construction to coverage feedback was formed, ensuring the interpretability and auditability of the assessment process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123116259A_ABST
    Figure CN123116259A_ABST
Patent Text Reader

Abstract

This invention relates to the field of artificial intelligence security technology, and discloses a method, system, device, and medium for security access assessment of MCP tools. The method includes: parsing the declaration information of the MCP tool service under test to construct a capability contract graph, and combining this with the invocation intent to construct an expected invocation graph; generating test cases according to coverage targets, executing them in an isolated sandbox and collecting cross-layer runtime events, and associating them into a causal behavior graph; verifying the consistency of the capability contract graph, expected invocation graph, and causal behavior graph, identifying abnormal behavior paths, obtaining causal attribution and confidence levels through counterfactual replay, thereby generating a risk score and access strategy, and feeding back graph nodes or edges that are not attributed or have confidence levels below a threshold as coverage targets. This invention uses counterfactual replay to perform causal verification of abnormal behavior and feeds the verification results back to the test case generation stage, which helps to form a closed loop of assessment and handling in the MCP tool access phase.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence security technology, and in particular to a method, system, device and medium for security access assessment of MCP tools. Background Technology

[0002] With the explosive growth and widespread application of large language model technology, extending model capabilities through tool calls has become the mainstream approach for intelligent agent applications. Large language models access external tools such as file systems, databases, code execution environments, and third-party network services via the Model Context Protocol (MCP) to complete complex tasks such as information retrieval, data analysis, code generation, and execution. However, surrounding the MCP ecosystem, a large number of third-party tool servers (MCP Servers) have been rapidly developed and reused, which, while expanding the capabilities of intelligent agents, also introduces serious supply chain security risks.

[0003] Because MCP tool servers are typically provided by third parties, their internal implementation logic, resource access scope, and actual operational behavior are often opaque to users. Attackers can make false claims in tool descriptions, input schemas, resource declarations, and other metadata to pass access control audits, and then execute unauthorized actions that contradict the claims during actual calls. These actions include conditional triggering, delayed execution, response manipulation, and cross-tool collaborative privilege amplification. Such behaviors are highly covert, their triggering conditions depend on runtime states, and are difficult to detect using traditional methods such as static permission list comparisons.

[0004] While existing dynamic sandbox testing methods can collect and analyze the actual runtime behavior of tools, they suffer from two key shortcomings. First, test case generation focuses solely on code coverage or graph coverage, neglecting to consider whether the collected abnormal behaviors can be attributed to specific permissions, tool responses, or tool nodes. This results in a significant waste of testing resources on test cases that cannot be attributed. Second, the detection results lack verification of the causal source of abnormal behaviors, making it difficult to distinguish genuine unauthorized actions and leading to a high false positive rate. Summary of the Invention

[0005] To address the aforementioned issues, this invention proposes a security access assessment method, system, device, and medium for MCP tools. This method can verify the causal source of abnormal behavior through counterfactual replay and feed back the causal attribution results and counterfactual causal confidence scores to the coverage target selection of test cases, forming a causal-driven coverage optimization closed loop. Simultaneously, it incorporates counterfactual causal confidence scores into risk scoring and outputs an interpretable, auditable, and directly executable security policy by the MCP gateway.

[0006] The technical solution adopted in this invention is as follows: A security access assessment method for MCP tools includes: Analyze the declaration information of the MCP tool service under test to construct a capability contract graph, and combine it with the calling intent to construct an expected calling graph; Test cases are generated based on the coverage objectives, executed in an isolated sandbox, and cross-layer runtime events are collected and correlated into a causal behavior graph. Consistency verification is performed on the capability contract graph, expected call graph, and causal behavior graph, and abnormal behavior paths are identified. Causal attribution and confidence are obtained through counterfactual replay, thereby generating risk scores and admission strategies. Graph nodes or edges that are not attributed or have confidence scores below the threshold are fed back as coverage targets.

[0007] Furthermore, the process of constructing a capability contract graph from the declarative information of the MCP tool service under test includes: Obtain the declaration information of the MCP tool service to be tested, including tool description, input mode, resource declaration, authorization scope and external endpoint information; The declaration information is parsed into tool nodes, resource nodes, action nodes, and constraint edges, and the constraint edges record the triggering conditions, parameter ranges, and data sensitivity levels. The declared information is compared with the preset security policy to mark conflicting declarations, thus obtaining a capability contract graph.

[0008] Furthermore, the construction of the expected call graph based on the call intent includes: Obtain the tool call planning trajectory generated by user tasks, system security policies, and large language models, and determine the expected call sequence, expected access resources, and expected data flow. The expected call sequence, expected access resources, and expected data flow are described in a graph structure, which serves as a benchmark for determining whether the actual behavior exceeds the authorization boundary of the user's intent, thus forming an expected call graph.

[0009] Furthermore, the generation of test cases according to the coverage target includes: The coverage target is determined based on the coverage of graph nodes and edges in the capability contract graph and the expected call graph, and example calls, default values ​​and normal call trajectories are collected as initial seeds; Generate test cases based on at least one of the following: field values ​​and field combinations, permissions and resource boundaries, state transitions, and cross-tool combination paths; and perform mutation operations on the test cases. Maintain the coverage status of graph nodes and edges, calculate the coverage gain of newly added test cases, and retain test cases with positive gain; Filter or remove invalid test cases, and stop generating test cases when the coverage threshold, test limit, or coverage gain convergence is reached.

[0010] Furthermore, the process of executing and collecting cross-layer running events in the isolated sandbox and associating them into a causal behavior graph includes: The tool service under test is run in an isolated environment, which by default blocks external network access and only allows controlled connections, and isolates and redirects file read and write operations; Deploy at least one type of data collection probe from system calls, file access, network connections, and interface calls; assign source tags to test cases and implant decoy data. Execute test cases, collect protocol messages, system calls, file access, network connections and external interface call events, and record call identifiers, data source tags and timestamps; Based on the call identifier, process identifier, data source label and time relationship, cross-layer events in the same call chain are associated as the same behavior path; Using tools, processes, files, network endpoints, and external interfaces as graph nodes, and call relationships, data flow relationships, control flow relationships, and temporal order relationships as graph edges, a causal behavior graph is constructed.

[0011] Furthermore, the consistency verification of the capability contract graph, expected call graph, and causal behavior graph, and the identification of abnormal behavior paths, include: By comparing the causal behavior diagram with the capability contract diagram, undeclared capability calls can be identified; By comparing the causal behavior graph with the expected call graph, we can identify behaviors that deviate from the intended intent. Based on data tag propagation detection, sensitive data is propagated to unauthorized sinks, and a holistic analysis of multi-tool combined calls is performed to identify cross-tool permission amplification links; Detect inductive commands or anomalous loads in the tool's response to identify response-induced unauthorized actions; The identified abnormal behaviors are recorded as abnormal behavior paths, which include path type, graph nodes and edges involved, and evidence summary.

[0012] Furthermore, the causal attribution and confidence level obtained through counterfactual replay are used to generate risk scores and admission strategies, and graph nodes or edges that are not attributed or have confidence levels below a threshold are fed back as coverage targets, including: Under the same initial state, perform permission revocation replay, tool output replacement replay, and multi-toolchain node isolation replay on the abnormal behavior path respectively; By comparing the differences in causal behavior diagrams before and after counterfactual replay, the causal attribution results of abnormal behavior can be determined. The counterfactual causal confidence level is calculated based on the degree of difference significance, the reproducibility of the abnormal behavior, and the clarity of the minimum trigger set. Risk scores are calculated and risk levels are assigned by comprehensively considering factors such as undeclared capabilities, deviation from intent, leakage of sensitive data, amplification of cross-tool permissions, and counterfactual causal confidence. An access strategy is generated based on the causal attribution results and risk levels. The access strategy includes at least one of the following: tool whitelist, field-level parameter restrictions, file path range, network endpoint range, call count limit, and manual confirmation conditions. Graph nodes or edges that have not been causally attributed, as well as graph nodes or edges corresponding to abnormal behavior paths with confidence levels below a preset threshold, are fed back to the test case generation stage as coverage targets. The conditions, differences, and attribution conclusions of counterfactual replays are recorded as evidence and an evaluation report is generated.

[0013] A security access assessment system for MCP tools, comprising: The graph construction module is configured to parse the declaration information of the MCP tool service under test to construct the capability contract graph, and combine it with the calling intent to construct the expected calling graph; The behavior collection and association module is configured to generate test cases according to the coverage target, execute them in the isolation sandbox and collect cross-layer running events, and associate them into a causal behavior graph; The verification and causal feedback module is configured to perform consistency verification on the capability contract graph, expected call graph, and causal behavior graph and identify abnormal behavior paths. It obtains causal attribution and confidence through counterfactual replay, thereby generating risk scores and admission strategies, and feeding back graph nodes or edges that are not attributed or have confidence below the threshold as coverage targets.

[0014] A computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the MCP tool security access assessment method.

[0015] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the MCP tool security access assessment method.

[0016] The beneficial effects of this invention are as follows: 1. This invention constructs a capability contract graph by parsing the declaration information of the service under test, and constructs an expected call graph by combining the call intent. Then, test cases are generated according to the coverage objectives, executed in an isolated sandbox, and cross-layer runtime events are collected and correlated to form a causal behavior graph. Consistency verification is then performed to identify abnormal behavior paths. Causal attribution and confidence levels are obtained through counterfactual replay, thereby generating a risk score and admission strategy. Graph nodes or edges that are not attributed or have confidence levels below a threshold are fed back as coverage targets. Thus, a closed-loop process is formed in the tool admission stage, from graph construction, test case generation, sandbox execution, behavior correlation, consistency verification, counterfactual replay, to coverage feedback. This ensures that the evaluation process considers both the comparison of declarations and intents and the causal verification of actual behavior, helping to improve the reliability and operability of the evaluation conclusions.

[0017] 2. Regarding the construction of the capability contract graph and the expected call graph, by acquiring information such as tool descriptions, input patterns, resource declarations, authorization scopes, and external endpoints and parsing them into tool nodes, resource nodes, action nodes, and constraint edges, the declared capabilities of the tool can be presented in a structured manner, and declarations that conflict with the preset security policy can be marked. By acquiring user tasks, system security policies, and tool planning trajectories from the large language model, the expected call graph can be constructed, making user intent and authorization boundaries explicit. These two serve as reference benchmarks, providing a basis for subsequent identification of undeclared capability calls and intent deviation behaviors. In terms of test case generation, the coverage target is determined based on the coverage of graph nodes and edges. Test cases are generated by combining strategies such as field values ​​and combinations, permission and resource boundaries, state transitions, and cross-tool combination paths. The sample space is expanded through mutation operations, while maintaining the coverage state, calculating coverage gain, and filtering invalid test cases. This helps to improve the coverage of key behavioral paths while controlling the test scale, making the investment of test resources more targeted.

[0018] 3. Regarding isolated sandbox execution and cross-layer event collection, by restricting network access, isolating and redirecting file read / write operations in the isolated operating environment, and deploying collection probes for system calls, file access, network connections, and interface calls, combined with source tags and decoy data, the protocol messages and system behaviors during tool operation can be recorded relatively completely. Based on call identifiers, process identifiers, data source tags, and time relationships, cross-layer events are associated into a causal behavior graph, which can reconstruct the data flow path from source to sink. On this basis, comparing the causal behavior graph with the capability contract graph and the expected call graph respectively can identify undeclared capability calls and intention deviation behaviors, and further detect sensitive data propagation, cross-tool permission amplification, and response-induced privilege escalation, thereby comprehensively discovering abnormal behavior paths and providing clear objects to be verified for subsequent causal verification.

[0019] 4. Regarding counterfactual replay and access control strategy generation, by performing permission revocation replay, tool output replacement replay, and multi-toolchain node isolation replay under the same initial state, and comparing the differences in the causal behavior graph before and after replay, the causal attribution results of abnormal behaviors can be determined. Based on this, counterfactual causal confidence can be calculated, which helps distinguish between genuine unauthorized behavior and occasional fluctuations or related confusion, reducing false positive rates. By comprehensively calculating risk scores and classifying risk levels based on indicators such as undeclared capabilities, intent deviation, sensitive data leakage, cross-tool permission amplification, and counterfactual causal confidence, access control strategies including tool whitelists, field-level parameter restrictions, file path ranges, network endpoint ranges, call count limits, and manual confirmation conditions can be generated. Feeding back graph nodes or edges that have not obtained causal attribution or whose confidence is below the threshold to the test case generation stage allows test samples to focus on causally attributable behavioral paths, forming a closed loop of coverage optimization. Recording replay conditions, differences, and attribution conclusions as evidence facilitates subsequent auditing and review, thereby achieving a connection between detection, attribution, and access control. Attached Figure Description

[0020] Figure 1 This is a flowchart of a security access assessment method for an MCP tool according to Embodiment 1 of the present invention.

[0021] Figure 2 This is a flowchart of a security access assessment method for an MCP tool according to Embodiment 2 of the present invention. Detailed Implementation

[0022] To provide a clearer understanding of the technical features, objectives, and effects of the present invention, specific embodiments are now described. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention; that is, the described embodiments are only a part of the embodiments of the invention, not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.

[0023] Example 1 like Figure 1 As shown, this embodiment provides a method for security access assessment of MCP tools, including: Analyze the declaration information of the MCP tool service under test to construct a capability contract graph, and combine it with the calling intent to construct an expected calling graph; Test cases are generated based on the coverage objectives, executed in an isolated sandbox, and cross-layer runtime events are collected and correlated into a causal behavior graph. Consistency verification is performed on the capability contract graph, expected call graph, and causal behavior graph, and abnormal behavior paths are identified. Causal attribution and confidence are obtained through counterfactual replay, thereby generating risk scores and admission strategies. Graph nodes or edges that are not attributed or have confidence scores below the threshold are fed back as coverage targets.

[0024] It should be noted that this method is based on the alignment between the statement, intent, and actual behavior. It verifies the causal relationship of abnormal behavior through counterfactual replay and feeds the verification results back to the test case generation stage, which helps to form a closed loop of evaluation and handling in the tool admission stage.

[0025] Preferably, the step of constructing a capability contract graph by parsing the declaration information of the MCP tool service under test includes: obtaining the declaration information of the MCP tool service under test, including tool description, input mode, resource declaration, authorization scope and external endpoint information; parsing the declaration information into tool nodes, resource nodes, action nodes and constraint edges, wherein the constraint edges record trigger conditions, parameter range and data sensitivity level; comparing the declaration information with a preset security policy to mark conflicting declarations, thereby obtaining a capability contract graph.

[0026] Specifically, tool descriptions, input modes, resource declarations, authorization scopes, and external endpoint information can be obtained through protocol handshakes and enumeration interfaces. Tool descriptions may include tool identifiers, functional descriptions, and versions; input modes may include field names, types, value ranges, required fields, default values, and constraints; resource declarations may include resource identifiers, resource types, and access methods; authorization scopes may include required permissions and permission ranges; and external endpoints may include network addresses, protocols, ports, and credential requirements. When the above information is parsed into a graph structure, tool nodes record tool identifiers, versions, and input mode summaries; resource nodes record files, databases, credentials, and network endpoints, and label them with resource identifiers, resource types, and data sensitivity levels; action nodes record read, write, delete, transmit, and execute actions; and constraint edges connect tool nodes and resource nodes, as well as action nodes, and record the subject, triggering conditions, parameter ranges, time ranges, and data sensitivity levels. By comparing the declaration information with preset security policies, declarations that conflict at the static level can be marked.

[0027] It should be noted that by constructing a capability contract diagram, a claim-side reference benchmark can be provided for subsequent consistency verification and causal attribution, which helps to identify deviations between actual behavior and claimed capabilities.

[0028] Preferably, the step of constructing the expected call graph in conjunction with the call intent includes: obtaining the user task, system security policy, and tool call planning trajectory generated by the large language model, and determining the expected call sequence, expected access resources, and expected data flow; describing the expected call sequence, expected access resources, and expected data flow in a graph structure as a benchmark for judging whether the actual behavior exceeds the authorization boundary of the user intent, thus forming the expected call graph.

[0029] Specifically, the system can acquire the user's input natural language task description, system security policy, and tool call planning trajectory generated by the large language model for that task. The system security policy may include the permitted tool range, permitted resource range, and prohibited data flow. Based on the planning trajectory, the expected tool call sequence, expected access to resources, and expected data flow are determined and described in a graph structure. This expected call graph serves as a baseline for determining whether the actual behavior exceeds the authorization boundary of the user's intent. The capability contract graph and the expected call graph can be registered to a shared data plane for subsequent use case generation and compliance assessment.

[0030] It should be noted that the expected call graph can make the user intent and authorization boundaries explicit, providing a reference for identifying intention deviation behavior and helping to distinguish between normal calls and unauthorized calls.

[0031] Preferably, the step of generating test cases according to the coverage target includes: determining the coverage target based on the coverage of graph nodes and edges of the capability contract graph and the expected call graph, and collecting example calls, default values, and normal call trajectories as initial seeds; generating test cases according to at least one of field values ​​and field combinations, permissions and resource boundaries, state transitions, and cross-tool combination paths, and performing mutation operations on the test cases; maintaining the coverage status of graph nodes and edges, calculating the coverage gain of newly added test cases and retaining test cases with positive gains; filtering or removing invalid test cases, and stopping generation when the coverage threshold, test upper limit, or coverage gain convergence is reached.

[0032] Specifically, the initial seed can be derived from example calls in the tool description, default and example values ​​in the input pattern, typical resource identifiers in the resource declaration, public call corpus, and normal call trajectories in the expected call graph, and converted into protocol requests. When generating test cases, values ​​can be generated by type for input pattern fields, enumeration values ​​can be traversed for enumeration fields, boundary values ​​can be taken for numeric fields, empty strings, excessively long strings, path traversal strings, special symbols and encoding obfuscation strings can be injected into string fields, true and false values ​​can be traversed for boolean fields, and nested expansion and length boundary tests can be performed on object and array fields; multiple fields can be combined and covered using pairwise combinations or constraint solving. Test cases for out-of-bounds access, higher-sensitivity resource access, and resource identifier mutation can also be generated for permission edges and resource access boundaries; for tool services with internal states, a state machine can be constructed based on state transition relationships, and state traversal test cases can be generated using state coverage and transition edge coverage, focusing on covering states that require a preceding call sequence to reach; for combinations of multiple tool services, multi-tool combination call paths can be enumerated to generate cross-tool test cases. Mutation operations can include field value mutation, parameter type replacement, field addition / deletion, multi-round call sequence rearrangement, tool replacement, context injection, etc., forming a traceable mutation spectrum. Coverage status markers are maintained for graph nodes and edges. After execution, the coverage status is updated based on actual behavior, and the coverage gain brought by new test cases is calculated, prioritizing the retention of test cases with positive coverage gains. Before execution, requests that violate protocol specifications, have mismatched field types that cannot be parsed, or are completely unrelated to the input pattern can be statically filtered. After execution, test cases that do not generate new coverage and show no abnormal behavior are downgraded or removed. Generation stops when a preset coverage threshold, test limit, or several consecutive rounds without generating new coverage gain are reached.

[0033] It should be noted that by covering target guidance and mutation generation, the coverage of graph nodes and graph edges can be improved, thereby increasing the probability of triggering unauthorized behavior and reducing invalid test samples.

[0034] Preferably, the step of executing and collecting cross-layer running events in the isolated sandbox and associating them into a causal behavior graph includes: running the tool service under test in the isolated running environment, blocking external network access by default and only allowing controlled connections, and isolating and redirecting file read and write operations; deploying at least one type of collection probe among system calls, file access, network connections, and interface calls, assigning source tags to test cases and implanting decoy data; executing test cases, collecting protocol messages, system calls, file access, network connections, and external interface call events, and recording call identifiers, data source tags, and timestamps; associating cross-layer events of the same call chain into the same behavior path based on call identifiers, process identifiers, data source tags, and time relationships; and constructing a causal behavior graph with tools, processes, files, network endpoints, and external interfaces as graph nodes, and call relationships, data flow relationships, control flow relationships, and time sequence relationships as graph edges.

[0035] Specifically, the tool service under test can be run in a container or virtual machine, implementing resource and network isolation. By default, all external network access is blocked, allowing only controlled connections permitted through a transparent network proxy; file read / write operations are isolated and redirected through a file system overlay layer to protect the host file system; process creation and system resource usage are restricted, and audit logs are recorded. At least one type of collection probe—system call probe, file system overlay layer, transparent network proxy, and interface interceptor—is deployed to collect events such as process creation, file read / write, network connections, and external interface calls. A source tag is assigned to each test case, and identifiable decoy data, such as uniquely tagged sensitive data or resource references pointing to controlled honeypot endpoints, is embedded into the test data. The source tag and decoy data are injected into the execution environment along with the test case.

[0036] When executing test cases, they are executed one by one or in batches, collecting protocol messages, system call events, file access events, network connection events, and external interface call events. For each event, a call identifier, process identifier, thread identifier, data source label, timestamp, and call stack summary are recorded. Based on the call identifier, process identifier, thread context, data source label, and time relationship, cross-layer events in the same call chain are associated with the same behavioral path. During association, a mapping can be established between protocol layer request identifiers and operating system layer process identifiers. Call identifiers and data source labels are passed through thread-local storage or context propagation. Events are assigned using a time window with the request as the anchor point. Call stack summaries are collected to distinguish between the tool's own logic and dependent library behavior. Decoy data and source labels are propagated and traced as taints. Parent-child process relationships are recorded through a process tree to assign child process behavior to the call chain corresponding to the parent process. A causal behavior graph is constructed using tool nodes, process nodes, file nodes, network endpoint nodes, and external interface nodes as graph nodes, and call relationships, data flow relationships, control flow relationships, and time sequence relationships as graph edges. Edges in the graph can be labeled with data source labels, timestamps, and operation types. It can normalize and deduplicate raw events, filter noisy events, and record input use cases, output responses, event sequences, source tags, data flow, sandbox image fingerprints, and runtime log summaries for key behavioral paths, forming auditable evidence records.

[0037] It should be noted that by collecting and correlating events across layers in the isolated sandbox, the actual execution behavior and data flow of the tool can be restored, providing behavioral evidence for subsequent consistency verification and counterfactual replay.

[0038] Preferably, the consistency verification and identification of abnormal behavior paths for the capability contract graph, expected call graph, and causal behavior graph includes: comparing the causal behavior graph with the capability contract graph to identify undeclared capability calls; comparing the causal behavior graph with the expected call graph to identify intention deviation behaviors; detecting the propagation of sensitive data to unauthorized sinks based on data tag propagation, and performing overall analysis of multi-tool combined calls to identify cross-tool permission amplification links; detecting induced instructions or abnormal payloads in tool responses to identify response-induced privilege escalation; and recording the identified abnormal behaviors as abnormal behavior paths, wherein the abnormal behavior paths include path type, involved graph nodes and edges, and evidence summary.

[0039] Specifically, the action nodes and resource nodes in the causal behavior graph are compared with the capability contract graph to identify capability calls actually executed by the tool but not declared in the capability contract graph. For example, a tool may declare that it only reads a file but actually writes to it, or declare that it only accesses an internal endpoint but actually connects to an external endpoint. The tool call sequence, resource access, and data flow in the causal behavior graph are compared with the expected call graph to identify operations that exceed the user's task intent and authorization boundaries. For example, a tool may perform a deletion operation when the user task only requests to query data, or access sensitive resources unrelated to the task. Based on the data tag propagation results, the propagation path of sensitive data or decoy data from the source node to the unauthorized sink is detected. When the data tag flows to an unauthorized sink in the capability contract graph or the expected call graph, it is determined that sensitive data is propagating to an unauthorized endpoint. The causal behavior graph formed by the combined calls of multiple tool services is analyzed as a whole to identify permission amplification links formed by individual tools being compliant but combined. For example, one tool may have permission to read internal files, and another tool may have permission to send data to the outside. When combined, they form an unauthorized link of reading internal files and transmitting them externally. The detection tool's response content is examined to determine if it contains misleading instructions or anomalous payloads. This is because the tool may induce the large language model to perform unauthorized operations in subsequent steps by including instructions within the normal response that could call other tools, reveal prompts, or elevate privileges. Identified anomalous behaviors are recorded as anomalous behavior paths. Each path includes the path type, the involved graph nodes and edges, an evidence summary, and a preliminary severity rating.

[0040] It should be noted that ternary consistency verification can identify abnormal behavior paths from three dimensions: declaration, intent, and actual behavior, thereby improving the comprehensiveness of abnormal behavior identification and providing objects to be verified for counterfactual replay.

[0041] Preferably, the process of obtaining causal attribution and confidence levels through counterfactual replay to generate risk scores and access strategies, and feeding back graph nodes or edges that are not attributed or have confidence levels below a threshold as coverage targets, includes: performing permission revocation replay, tool output replacement replay, and multi-toolchain node isolation replay on abnormal behavior paths under the same initial state; comparing the differences in causal behavior graphs before and after counterfactual replay to determine the causal attribution results of abnormal behavior; calculating counterfactual causal confidence levels based on the significance of the differences, the reproducibility of abnormal behavior, and the clarity of the minimum trigger set; and comprehensively considering undeclared capabilities, intention deviations, and sensitive data. Risk scores are calculated and risk levels are assigned based on external transmission, cross-tool permission amplification, and counterfactual causal confidence. Admission strategies are generated based on causal attribution results and risk levels, including at least one of tool whitelists, field-level parameter restrictions, file path ranges, network endpoint ranges, call count limits, and manual confirmation conditions. Graph nodes or edges that have not received causal attribution, as well as graph nodes or edges corresponding to abnormal behavior paths with confidence levels below a preset threshold, are fed back to the test case generation stage as coverage targets. The conditions, differences, and attribution conclusions of counterfactual replays are recorded as evidence and an evaluation report is generated.

[0042] Specifically, for the identified abnormal behavior paths, permission revocation replay, tool output replacement replay, and multi-toolchain node isolation replay are constructed under the same initial state. The same initial state may include the same sandbox image, the same seed, the same test case sequence, a fixed random seed, and inference parameters. In permission revocation replay, the target permission on which the abnormal behavior path depends is revoked and then re-executed to observe whether the abnormal behavior disappears; if it disappears, it indicates that the permission is a necessary condition for the abnormal behavior. In tool output replacement replay, the response of a tool in the abnormal behavior path is replaced with a harmless response and then re-executed to observe whether subsequent unauthorized behavior still occurs; if subsequent unauthorized behavior disappears, it indicates that the tool response is the causal source of subsequent unauthorized behavior. In multi-toolchain node isolation replay, in a multi-tool combination scenario, each tool node in the abnormal behavior path is isolated one by one and then re-executed to observe whether the permission amplification link is blocked; if it is blocked, it indicates that the tool node is a key link in the permission amplification link. By comparing the differences in causal behavior graphs before and after counterfactual replay, we calculate whether anomalous behavior paths disappear or weaken under counterfactual conditions. Based on this, we determine the causal attribution result for each anomalous behavior path, i.e., which tool, permission, data stream, or tool response caused the anomalous behavior. Based on the significance of the differences in causal behavior graphs before and after counterfactual replay, the reproducibility of the anomalous behavior, and the clarity of the minimum trigger set, we calculate the counterfactual causal confidence.

[0043] A risk score is calculated by combining scores for undeclared capabilities, deviation from user intent, leakage of sensitive data, amplification of cross-tool permissions, and counterfactual causal confidence. Risk levels are then categorized based on the risk score and preset thresholds. The main risk types and responsible tools are determined by combining the scores of each indicator. An access strategy is generated based on the causal attribution results and risk levels. This access strategy may include at least one of the following: tool whitelist, field-level parameter restrictions, file path range, network endpoint range, call limit, and manual confirmation conditions.

[0044] Graph nodes or edges that have not been causally attributed, as well as graph nodes or edges corresponding to abnormal behavior paths with counterfactual causal confidence below a preset threshold, are fed back to the test case generation stage as coverage targets until the preset coverage threshold or test limit is reached. The conditions, processes, differences in causal behavior graphs before and after the counterfactual replay, and attribution conclusions are recorded as evidence to generate an evaluation report. The report may include basic tool information, a summary of the capability contract graph and expected call graph, test coverage, a list of abnormal behavior paths, counterfactual replay and risk attribution conclusions, risk scores and risk levels, admission strategies, evidence chain indexes, and review recommendations.

[0045] It should be noted that by replaying counterfactual events, the causal source of abnormal behavior can be verified, distinguishing between genuine unauthorized behavior and occasional fluctuations or related confusions, thus reducing the false alarm rate. By feeding back the causal attribution results and confidence levels to test case generation, test samples can be focused on graph nodes and edges that can be causally attributed, forming a causal-driven coverage optimization closed loop. By outputting an admission policy that can be executed by the gateway, a closed loop of detection and admission handling can be achieved.

[0046] Accordingly, this embodiment also provides an MCP tool security access assessment system, including: The graph construction module is configured to parse the declaration information of the MCP tool service under test to construct the capability contract graph, and combine it with the calling intent to construct the expected calling graph; The behavior collection and association module is configured to generate test cases according to the coverage target, execute them in the isolation sandbox and collect cross-layer running events, and associate them into a causal behavior graph; The verification and causal feedback module is configured to perform consistency verification on the capability contract graph, expected call graph, and causal behavior graph and identify abnormal behavior paths. It obtains causal attribution and confidence through counterfactual replay, thereby generating risk scores and admission strategies, and feeding back graph nodes or edges that are not attributed or have confidence below the threshold as coverage targets.

[0047] Specifically, the graph construction module obtains declared information through protocol handshakes and enumeration interfaces, parses it into tool nodes, resource nodes, action nodes, and constraint edges, and constructs the expected call graph based on user tasks, system security policies, and the large language model tool planning trajectory. The behavior collection and association module generates and mutates test cases, executes them in an isolated sandbox, collects protocol messages, system calls, file accesses, network connections, and external interface call events, and associates them into a causal behavior graph based on call identifiers, process identifiers, data source tags, and time relationships. The verification and causal feedback module performs ternary consistency verification, identifies undeclared capability calls, intent deviations, sensitive data propagation, cross-tool permission amplification, and response-induced privilege escalation, and obtains causal attribution and confidence levels through permission revocation replay, tool output replacement replay, and multi-toolchain node isolated replay. It then calculates risk scores, classifies risk levels, generates admission policies, and feeds back graph nodes or edges that are not attributed or have confidence levels below the threshold to test case generation.

[0048] It should be noted that this system can modularly deploy each step of the above-mentioned MCP tool security access assessment method, which facilitates automated assessment and access control in the tool introduction stage.

[0049] Example 2 This embodiment provides a method for security access assessment of MCP tools, including the following steps: 1. Constructing a capability contract graph and a call intent graph; 2. Generating and mutating test cases according to coverage objectives; 3. Executing the MCP tool service under test in a dynamic isolation sandbox and collecting runtime events across layers; 4. Associating cross-layer events as a causal behavior graph; 5. Performing consistency verification on the call intent graph, capability contract graph, and causal behavior graph, and identifying abnormal behavior paths; 6. Performing counterfactual replay on abnormal behavior paths to determine causal attribution results and counterfactual causal confidence; 7. Generating risk scores and access strategies based on causal attribution results and counterfactual causal confidence, and feeding back graph nodes or edges that have not obtained causal attribution, as well as graph nodes or edges corresponding to abnormal behavior paths with counterfactual causal confidence below a preset threshold, as coverage objectives to the test case generation stage.

[0050] Accordingly, this embodiment provides an MCP tool security access assessment system, including: 1) Contract and Intent Construction Module: Used to parse the tool description, input pattern, resource declaration, authorization scope, external endpoint and version information of the MCP tool service under test to construct a capability contract graph, and combine user tasks, system security policies and large model tool planning trajectory to construct a call intent graph; 2) Test Case Generation Module: Used to automatically generate and mutate normal, boundary, adversarial, and cross-tool invocation test cases based on the coverage objectives given by counterfactual causal feedback; 3) Dynamic Isolation Sandbox Execution Module: This module provides an isolated operating environment to execute the MCP tool service under test within the sandbox, and provides cross-layer data collection capabilities such as system call probes, file system overlay layers, transparent network proxies, and API (Application Programming Interface) interceptors. 4) Cross-layer event acquisition and causal behavior graph construction module: used to collect MCP protocol messages, system calls, file access, network connections and external interface call events, and associate them into a causal behavior graph based on call identifier, process identifier, data source label and time relationship; 5) Tripartite Consistency Verification Module: Used to compare the call intent graph, capability contract graph, and causal behavior graph to identify abnormal behavior paths; 6) Counterfactual replay and causal attribution module: used to determine the causal attribution results and counterfactual causal confidence of abnormal behavior paths through replay with permission revocation, tool output replacement replay, and multi-toolchain node isolated replay; 7) Counterfactual Causal Feedback and Control Module: This module feeds back graph nodes or edges that have not been causally attributed, as well as graph nodes or edges corresponding to abnormal behavior paths with counterfactual causal confidence levels below a preset threshold, as coverage targets to the test case generation module, and controls the test stop conditions. 8) Admission Strategy Generation and Reporting Module: This module generates risk scores and admission strategies based on causal attribution results and counterfactual causal confidence levels. It outputs tool whitelists, field-level parameter restrictions, file path ranges, network endpoint ranges, call count limits, and manual confirmation conditions, and forms an auditable assessment report and evidence chain.

[0051] It should be noted that this embodiment uses the following unified data object: 1) Capability Contract Graph (CC): Describes the declared capabilities of the MCP tool service under test, including tool nodes, resource nodes, action nodes, and constraint edges.

[0052] 2) Call Intent Graph (CI): Describes the call intent and authorization boundaries determined by user tasks, system security policies, and the trajectory planned by large model tools.

[0053] 3) Test case set T: A set of test cases generated by the test case generation module, including generation strategy labels, mutation lineage and coverage targets.

[0054] 4) Causal Behavior Graph (CB): A graph structure composed of cross-layer collected events, describing the data flow, control flow, and causal relationships during the actual execution of the tool.

[0055] 5) Abnormal behavior path set A: Unauthorized behavior paths identified by the ternary consistency verification module.

[0056] 6) Causal attribution results and counterfactual causal confidence G: The causal source and confidence level of each abnormal behavior path output by the counterfactual replay and causal attribution module.

[0057] 7) Risk assessment results R: including risk level, scores of each risk indicator, counterfactual causal confidence level and risk attribution results.

[0058] 8) Admission Policy P: Admission control policy that can be directly executed by the MCP gateway.

[0059] like Figure 2 As shown, the MCP tool security access assessment method in this embodiment can be implemented using the following steps.

[0060] I. Construction of Capability Contract Diagram and Invocation Intent Diagram This step establishes a reference benchmark for ternary consistency verification and causal attribution. First, it obtains the tool description, input mode, resource declaration, authorization scope, external endpoints, and version information of the MCP tool service under test, constructing a Capability Contract Diagram (CC). Then, it constructs a Call Intent Diagram (CI) based on the target user task, system security policy, and the large-scale tool planning trajectory. The data structure of the Capability Contract Diagram includes tool nodes, resource nodes, action nodes, and constraint edges. The specific steps are as follows: 1) Obtain metadata of the MCP tool service under test. Through the handshake and enumeration interfaces of the MCP protocol, obtain the tool description information (tool ID, function description, version), input mode information (Schema field name, type, value range, whether required, default value, constraints), resource declaration information (Uniform Resource Identifier URI, resource type, access method), authorization scope information (required permissions, permission scope), external endpoint information (network address, protocol, port, credential requirements), and version information of the MCP tool service under test, as the data source for constructing the capability contract graph.

[0061] 2) Construct the Capability Contract Graph (CC). Parse the aforementioned metadata into a graph structure containing tool nodes, resource nodes, action nodes, and constraint edges. Perform a static comparison between the tool declarations and the security policy, marking declarations that conflict at the static level. The data structure of the Capability Contract Graph includes: Tool nodes: Record the tool ID, version, and input pattern summary (name, type, value range, and constraints for each field); Resource nodes: Record the resources accessed by the tool declaration, including files, databases, credentials, and network endpoints, and label the resource URI, resource type, and data sensitivity level; Action nodes: Record the actions performed by the tool declaration, including reading, writing, deleting, transferring, and executing; Constraint edges: Connect tool nodes, resource nodes, and action nodes, recording the subject (the tool performing the action), triggering conditions, parameter range, time range, and data sensitivity level.

[0062] 3) Constructing the Invocation Intent Graph (CI). Based on the target user task (the user-input natural language task description), system security policies (the scope of allowed tools, the scope of allowed resources, and the prohibited data flows), and the tool invocation planning trajectory generated by the large language model (which tools, with what parameters, and in what order the large model plans to invoke them for this task), an invocation intent graph is constructed. The invocation intent graph describes the expected sequence of tool invocations, the expected access to resources, and the expected data flows in this task scenario in a graph structure, serving as a benchmark for determining whether the actual behavior exceeds the authorized boundaries of the user's intent.

[0063] 4) Register the Capability Contract Diagram (CC) and the Invocation Intent Diagram (CI) to the shared data plane for use case generation agents and compliance assessment agents to read, and use as a reference for coverage feedback and ternary consistency verification.

[0064] II. Test Case Generation The test case generation agent automatically generates and iteratively mutates normal, boundary, adversarial, and cross-tool call test cases based on the capability contract graph (CC) and the call intent graph (CI), according to the coverage of pattern fields, permission edges, state transitions, and multi-tool combination paths, forming a test case set T. The goal of test case generation is to maximize the coverage of each node and edge in the capability contract graph, thereby increasing the probability of triggering unauthorized behavior. The specific steps are as follows: 1) Initial Seed Sources. The use case generation agent collects initial seeds from the following sources: example calls in tool descriptions, default and example values ​​in input patterns, typical resource URIs in resource declarations, publicly available MCP tool call corpora, and normal call trajectories planned in the call intent graph. The above content is converted into initial JSON-RPC tool call requests as seed use cases.

[0065] 2) Schema Field Combination Method. For each field in the tool's input mode, values ​​are generated based on the field type: for enumeration fields, all enumeration values ​​are traversed; for numeric fields, boundary values ​​(minimum, maximum, zero, negative, out-of-range values) are taken; for string fields, empty strings, excessively long strings, path-crossing strings (such as ".. / "), special symbols, and encoded obfuscation strings are injected; for boolean fields, true and false values ​​are traversed; for object and array fields, nested expansion and length boundary testing are performed. Subsequently, multiple fields are combined and covered using pairwise combinations or constraint solving to cover key combinations between fields while controlling the number of test cases.

[0066] 3) Boundary value generation method. In addition to field-level boundaries, use cases are generated for permission boundaries and resource access boundaries, including: resources within the access permission scope boundary, out-of-bounds access to unauthorized resources, access to resources with higher sensitivity levels, bypassing path restrictions with a modified resource URI, and triggering conditional branches with special parameters, etc.

[0067] 4) State Machine Traversal Method. For MCP tool services with internal states, a state machine is constructed based on the tool's state transition relationships. A strategy of state coverage and transition edge coverage is used to generate state traversal test cases, covering every edge of the state transition, with a focus on covering states that require a preceding call sequence to reach (delayed triggering scenarios), in order to discover unauthorized behaviors that only occur under specific state sequences.

[0068] 5) Cross-tool combination path generation. For scenarios involving multiple MCP tool services, based on the capability contract diagram and call intent diagram of each tool, enumerate the multi-tool combination call path and generate cross-tool use cases to discover the permission amplification formed by multi-tool collaboration (e.g., tool A reads a restricted file, and tool B sends the contents of that file to an external endpoint).

[0069] 6) Mutation Operations. The test case generation agent randomly selects a sequence of mutation operations from existing test cases, including: field value mutation, parameter type replacement, field addition and deletion, multi-round call sequence rearrangement, tool replacement, context injection (embedding adversarial instructions or inducement content in parameters), etc., forming a traceable mutation spectrum.

[0070] 7) Coverage Gain Calculation. Maintain coverage status markers for each graph node and edge in the capability contract graph. Update the coverage status based on the actual behavior collected after the use case is executed. Calculate the coverage gain (number of newly covered graph nodes and edges) brought by each new use case, and prioritize retaining use cases with positive coverage gains.

[0071] 8) Invalid Test Case Filtering Rules. Before execution, statically filter test cases to remove obviously invalid ones, including: requests that violate the JSON-RPC protocol specification, requests with mismatched field types that cannot be parsed by the tool, and requests that are completely unrelated to the tool's input pattern; after execution, demote or remove test cases that do not generate any new coverage and have no abnormal behavior to avoid generating invalid test samples.

[0072] 9) Stop conditions. Test case generation will stop when the preset coverage threshold is reached (e.g., the coverage rate of nodes and edges in the capability contract graph reaches a set ratio), the test limit is reached (limit of test cases, execution time or computing resources), or no new coverage gain is generated in several consecutive iterations.

[0073] III. Dynamic Isolation Sandbox Execution and Cross-Layer Event Collection The goal of dynamic isolation sandbox execution and cross-layer event acquisition is to execute the MCP tool service under test in a controlled, isolated, and observable environment and collect its actual runtime behavior. The specific steps are as follows: 1) Build a dynamic isolation sandbox. Run the MCP tool service under test in a container or virtual machine, and implement strict resource and network isolation. By default, block all external network access and only allow controlled connections required for testing through a transparent network proxy; isolate and redirect file read and write through a file system overlay (Copy-on-Write) to protect the host file system; restrict process creation and system resource usage, and record complete audit logs throughout the process.

[0074] 2) Deploy cross-layer acquisition probes. Deploy system call probes (acquiring system calls such as process creation, file reading and writing, and network connection) in the sandbox, a file system overlay layer (recording file reading and writing paths, content summaries, and data source tags), a transparent network proxy (recording network connection targets, protocols, and payload summaries), and an API interceptor (intercepting MCP tool calls to external APIs), and collect MCP protocol messages (JSON-RPC requests and responses) and tool response events.

[0075] 3) Inject source tags and decoy data. Assign a unique source tag to each test case and embed identifiable decoy data (such as sensitive data with unique tags or resource references pointing to controlled honeypot endpoints) into the test data for subsequent data flow tracking and detection of sensitive data leakage. Inject the source tags and decoy data along with the test cases into the sandbox execution environment.

[0076] 4) Execute test cases and collect events. Execute the test cases generated by the test case generation agent one by one or in batches in the sandbox. Collect MCP protocol messages, system call events, file access events, network connection events, and external interface call events during the execution process. Record the call identifier, process identifier, thread identifier, data source tag, timestamp, and call stack summary for each event.

[0077] IV. Construction of Cross-Level Event Association and Causal Behavior Graph The goal of cross-layer event association and causal behavior graph construction is to connect events scattered across different layers into a unified causal behavior graph (CB), thereby reconstructing the actual execution behavior and data flow of the tool. The specific steps are as follows: 1) Event Association. Based on the call identifier, process identifier, thread context, data source label, and time relationship of each event, MCP protocol messages, system calls, file accesses, network connections, and external interface call events in the same call chain are associated as the same behavioral path. Behavioral association algorithms include: 2) Mapping of call identifiers and process identifiers: Establish a mapping relationship between the JSON-RPC request identifier of the MCP protocol layer and the process ID of the operating system layer, so that the protocol layer request can locate the corresponding system process; 3) Thread context passing: Through thread-local storage or context propagation mechanism, the call identifier and data source label are passed between threads in the process to ensure that multi-threaded operations triggered by the same request can be associated; 4) Time window: System calls, file and network events collected within the execution time window of each request are attributed to that request; 5) Call stack summary: Collects the call stack summary when the event occurs, used to distinguish whether the behavior is caused by the tool's own logic or by a dependency library; 6) Data Tag Propagation (Taint Tracking): The injected decoy data and source tags are used as taints and propagated during file reading and writing, network transmission and inter-process communication to track the flow path of sensitive data; 7) Parent-child process relationship: The parent-child process relationship is recorded through the process tree, and the behavior generated by the child process is attributed to the call chain corresponding to its parent process.

[0078] 8) Construct a causal behavior graph (CB). Using tool nodes, process nodes, file nodes, network endpoint nodes, and external API nodes as graph nodes, and call relationships, data flow relationships, control flow relationships, and temporal sequences as graph edges, construct a causal behavior graph by associating the event sequences. Each edge in the graph can be labeled with a data source label, timestamp, and operation type, making the complete flow path of data from the source to the sink traceable.

[0079] 9) Event Normalization and Evidence Solidification. The collected raw events are normalized and deduplicated to filter out noisy events; for key behavioral paths, input use cases, output responses, event sequences, source tags, data flow, sandbox image fingerprints, and runtime log summaries are recorded to form auditable evidence records for use in ternary consistency verification and counterfactual replay.

[0080] V. Ternary Consistency Verification and Abnormal Behavior Identification The compliance assessment agent performs a ternary consistency verification of the Invocation Intent Graph (CI), Capability Contract Graph (CC), and Causal Behavior Graph (CB) to identify deviations between the tool's actual behavior and its claimed capabilities and user intent. The specific steps are as follows: 1) Identification of Undeclared Capabilities. The action nodes and resource nodes in the causal behavior graph (CB) are compared with the capability contract graph (CC) to identify capability calls that the tool actually executed but were not declared in the capability contract graph. For example, a tool might declare that it only reads a file but actually writes to it, or declare that it only accesses an internal endpoint but actually connects to an external endpoint. Undeclared capability calls are a significant signal of unauthorized behavior.

[0081] 2) Intent Deviation Identification. The tool call sequence, resource access, and data flow in the causal behavior graph (CB) are compared with the call intent graph (CI) to identify operations that exceed the user's task intent and authorization boundaries. For example, if the user task only requires querying data, but the tool performs a deletion operation or accesses sensitive resources unrelated to the task.

[0082] 3) Sensitive Data Propagation Identification. Based on the data tag propagation results, detect the propagation path of sensitive data (or decoy data) from the source node to unauthorized sinks (external endpoints, unauthorized files, unauthorized processes) to identify sensitive data outflow behavior. When the data tag flows to an unauthorized sink in the capability contract graph or call intent graph, it is determined that sensitive data is propagating to an unauthorized endpoint.

[0083] 4) Identification of cross-tool permission amplification. A holistic analysis is performed on the causal behavior graph formed by the combined calls of multiple MCP tool services to identify permission amplification behaviors that occur when individual tools are compliant but combined. For example, tool A may have permission to read internal files, while tool B may have permission to send data externally; their combination forms an unauthorized link of "reading internal files and sending them externally."

[0084] 5) Response-induced privilege escalation identification. Detect whether the response content of the detection tool contains misleading instructions or abnormal payloads. Identify behaviors where the tool induces the large language model to perform privilege escalation operations in subsequent steps by returning results. For example, the tool may include instructions in the normal return result to induce the model to call other tools, reveal prompt words, or elevate privileges.

[0085] 6) Generate an abnormal behavior path set A. Record the abnormal behaviors identified above as abnormal behavior paths. Each path includes the path type (undeclared capability, intention deviation, sensitive data propagation, cross-tool permission amplification, response inducement), the graph nodes and edges involved, evidence summary and preliminary severity classification, for use in counterfactual replay and risk attribution.

[0086] VI. Counterfactual Replay and Causal Attribution The goal of counterfactual replay and risk attribution is to verify the causal source of abnormal behavior and eliminate sporadic fluctuations and association confusion by changing permissions, tool responses, or tool nodes corresponding to the abnormal behavior path and re-executing the test while maintaining the consistency of the initial test state. The specific steps are as follows: 1) Counterfactual replay mechanism. For identified abnormal behavior paths, under the same initial state (same sandbox image, same seed, same use case sequence, fixed random seed and inference parameters), the following three types of counterfactual replay implementation examples are constructed respectively: 2) Permission Revocation and Replay: Revoke the target permissions on which the abnormal behavior path depends (e.g., revoke network access permissions for an external endpoint or write permissions for a file), and then re-execute the operation. Observe whether the abnormal behavior disappears. If the abnormal behavior disappears after revoking the permissions, it indicates that the permission is a necessary condition for the abnormal behavior, verifying the causal dependency between the abnormal behavior and the permission. 3) Tool Output Replacement and Replay: Replace the response of a tool in the abnormal behavior path with a harmless response and re-execute the tool. Observe whether subsequent unauthorized behavior still occurs. If the subsequent unauthorized behavior disappears after the response is replaced, it indicates that the tool's response inducement is the causal source of the subsequent unauthorized behavior, which is used to identify response-induced unauthorized behavior. 4) Multi-toolchain node isolation and replay: In multi-tool combination scenarios, isolate (remove or disable) a tool node in the abnormal behavior path one by one and then re-execute to observe whether the privilege amplification link is blocked. If the privilege amplification link disappears after isolating a tool node, it indicates that the tool node is a key link in the privilege amplification link and is used to locate the responsible tool for cross-tool collaborative privilege amplification.

[0087] 5) Causal difference comparison. Compare the differences in causal behavior graphs before and after counterfactual replay, calculate whether the abnormal behavior path disappears or weakens under counterfactual conditions, and determine the causal attribution result of each abnormal behavior path, that is, which tool, which permission, which data stream or which tool response caused the abnormal behavior.

[0088] 6) Counterfactual causal confidence. Based on the significance of the difference between the causal behavior diagrams before and after counterfactual replay, the reproducibility of abnormal behavior (whether it is stably reproduced after multiple replays), and the clarity of the minimum trigger set, the counterfactual causal confidence is calculated. This is used to correct the impact of occasional fluctuations and association confusion in risk scoring, and to improve the interpretability and reproducibility of the conclusions.

[0089] 7) Evidence solidification. The conditions, processes, differences in causal behavior diagrams before and after the counterfactual replay, and the attribution conclusions are recorded as evidence and included in the assessment report to support subsequent audits and reviews.

[0090] VII. Risk Scoring and Access Strategy Generation The goal of risk quantification and access policy generation is to calculate the risk level based on the results of ternary consistency verification and counterfactual replay, and to generate an access policy that can be directly executed by the MCP gateway. The specific steps are as follows: 1) Risk Quantification. A risk score R is calculated based on five categories of indicators: undeclared capabilities, deviation from intended intent, dissemination of sensitive data, amplification of cross-tool permissions, and counterfactual causal confidence. The risk quantification formula is as follows:

[0091] Wherein, U is the score for undeclared capabilities, D is the score for deviation from user intent, E is the score for the transfer of sensitive data, A is the score for amplified cross-tool permissions, and C is the counterfactual causal confidence level. to The corresponding weights can be configured by the security policy. The calculation methods for each indicator are as follows: Undeclared capability score U: Calculated by weighting the number of undeclared capability calls, the sensitivity level of the resources involved, and the danger level of the action (execution and deletion are higher than writing, and writing is higher than reading and transmission).

[0092] User Intent Deviation Score D: Calculated by weighting the deviation between the actual behavior and the intended graph and the degree of danger of the deviation action.

[0093] Sensitive data transmission score E: Calculated by weighting the sensitive data transmission level, the risk level of the transmission target, and whether the decoy data is hit.

[0094] Cross-tool permission amplification score A: Calculated by weighting the length of the permission amplification link, the permission scope of the tools involved, and the ultimate unauthorized access capability.

[0095] Counterfactual causal confidence level C: Calculated based on the significance of the difference between the causal behavior diagrams before and after counterfactual replay and the reproducibility of the abnormal behavior. The value range can be normalized to between 0 and 1.

[0096] 2) Risk Level Determination. Risk levels are determined based on the risk score R and preset thresholds (e.g., low risk, medium risk, high risk, severe risk), and the main risk types and liability tools are determined in conjunction with the scores of each indicator.

[0097] 3) Admission Policy Generation. Based on the risk attribution results and risk level, an admission policy P that can be directly executed by the MCP gateway is generated, including: tool whitelist (a list of tools that are allowed to pass), field-level parameter restrictions (restrictions on the value range of specific fields), file path range (a whitelist of file system paths that are allowed to be accessed), network endpoint range (a whitelist of network addresses and ports that are allowed to be connected), call limit (the maximum number of calls allowed per unit time), and manual confirmation conditions (call scenarios that require manual review and confirmation before being allowed).

[0098] 4) Coverage Feedback. Uncovered capability contract graph nodes or edges from this test are fed back to the test case generation agent as coverage targets for the next round of test case generation, until a preset coverage threshold or test limit is reached, forming a closed loop of "test case generation - sandbox execution - behavior association - consistency verification - counterfactual replay - coverage feedback".

[0099] 5) Report Output. Generate an assessment report, including: basic tool information, capability contract diagram and call intent diagram summary, test coverage, list of abnormal behavior paths, counterfactual replay and risk attribution conclusions, risk score and risk level, access strategy, evidence chain index and review recommendations, to facilitate security audit, compliance retention and access decision-making closure.

[0100] It should be noted that the MCP tool security access assessment method in this embodiment has the following characteristics: (1) Causal-driven coverage optimization: The causal attribution results and counterfactual causal confidence of counterfactual replay are fed back as the coverage target of test cases, so that the test sample generation focuses on graph nodes and graph edges that can be causally attributed, avoiding the waste of sample generation on test cases that cannot be attributed by existing coverage feedback methods, and improving the trigger probability and coverage gain of unauthorized behavior.

[0101] (2) Distinguish between real overreach and occasional fluctuations: Verify the causal source of abnormal behavior by counterfactual replay, and use the counterfactual causal confidence as an independent component of the risk score to quantitatively distinguish between real overreach and occasional fluctuations and related confusion, thereby reducing the false alarm rate and improving the credibility of the conclusions.

[0102] (3) Auditable and reproducible evidence chain: Through three types of counterfactual replay, namely, permission revocation, tool output replacement and multi-toolchain node isolation, the causal attribution conclusion of each abnormal behavior path is output to form an auditable and reproducible evidence chain.

[0103] (4) Directly executable access control strategy: Based on the causal attribution results and confidence level, output the tool whitelist, field-level parameter restrictions, file path range, network endpoint range, call limit and manual confirmation conditions that can be directly executed by the MCP gateway to realize the closed loop of detection and access control.

[0104] In summary, this invention can verify the causal source of abnormal behavior through counterfactual replay, and feed back the causal attribution results and counterfactual causal confidence to the coverage target selection of test cases, forming a causal-driven coverage optimization closed loop. At the same time, it incorporates counterfactual causal confidence into risk scoring and outputs an interpretable, auditable, and directly executable security policy by the MCP gateway.

[0105] Example 3 This embodiment provides a computer device, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the aforementioned MCP tool security access assessment method. The computer program can be in the form of source code, object code, executable file, or some intermediate form.

[0106] Example 4 This embodiment provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned MCP tool security access assessment method. The computer program can be in the form of source code, object code, executable file, or some intermediate form. The storage medium includes any entity or device capable of carrying computer program code, recording media, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc.

[0107] The above description is merely a preferred embodiment of the present invention. It should be understood that the present invention is not limited to the forms disclosed herein and should not be construed as excluding other embodiments. It can be used in various other combinations, modifications, and environments, and can be altered within the scope of the concept described herein through the above teachings or related technologies or knowledge. Modifications and variations made by those skilled in the art that do not depart from the spirit and scope of the present invention should be within the protection scope of the appended claims.

[0108] It should be noted that, for the sake of simplicity, the foregoing method embodiments are described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.

Claims

1. A method for security access assessment of MCP tools, characterized in that, include: Analyze the declaration information of the MCP tool service under test to construct a capability contract graph, and combine it with the calling intent to construct an expected calling graph; Test cases are generated based on the coverage objectives, executed in an isolated sandbox, and cross-layer runtime events are collected and correlated into a causal behavior graph. Consistency verification is performed on the capability contract graph, expected call graph, and causal behavior graph, and abnormal behavior paths are identified. Causal attribution and confidence are obtained through counterfactual replay, thereby generating risk scores and admission strategies. Graph nodes or edges that are not attributed or have confidence scores below the threshold are fed back as coverage targets.

2. The MCP tool security access assessment method according to claim 1, characterized in that, The process of constructing a capability contract diagram by parsing the claim information of the MCP tool service under test includes: Obtain the declaration information of the MCP tool service to be tested, including tool description, input mode, resource declaration, authorization scope and external endpoint information; The declaration information is parsed into tool nodes, resource nodes, action nodes, and constraint edges, and the constraint edges record the triggering conditions, parameter ranges, and data sensitivity levels. The declared information is compared with the preset security policy to mark conflicting declarations, thus obtaining a capability contract graph.

3. The MCP tool security access assessment method according to claim 1, characterized in that, The construction of the expected call graph based on the call intent includes: Obtain the tool call planning trajectory generated by user tasks, system security policies, and large language models, and determine the expected call sequence, expected access resources, and expected data flow. The expected call sequence, expected access resources, and expected data flow are described in a graph structure, which serves as a benchmark for determining whether the actual behavior exceeds the authorization boundary of the user's intent, thus forming an expected call graph.

4. The MCP tool security access assessment method according to claim 1, characterized in that, The generation of test cases according to the coverage target includes: The coverage target is determined based on the coverage of graph nodes and edges in the capability contract graph and the expected call graph, and example calls, default values ​​and normal call trajectories are collected as initial seeds; Generate test cases based on at least one of the following: field values ​​and field combinations, permissions and resource boundaries, state transitions, and cross-tool combination paths; and perform mutation operations on the test cases. Maintain the coverage status of graph nodes and edges, calculate the coverage gain of newly added test cases, and retain test cases with positive gain; Filter or remove invalid test cases, and stop generating test cases when the coverage threshold, test limit, or coverage gain convergence is reached.

5. The MCP tool security access assessment method according to claim 1, characterized in that, The process of executing and collecting cross-layer operation events in the isolation sandbox, and associating them into a causal behavior graph, includes: The tool service under test is run in an isolated environment, which by default blocks external network access and only allows controlled connections, and isolates and redirects file read and write operations; Deploy at least one type of data collection probe from system calls, file access, network connections, and interface calls; assign source tags to test cases and implant decoy data. Execute test cases, collect protocol messages, system calls, file access, network connections and external interface call events, and record call identifiers, data source tags and timestamps; Based on the call identifier, process identifier, data source label and time relationship, cross-layer events in the same call chain are associated as the same behavior path; Using tools, processes, files, network endpoints, and external interfaces as graph nodes, and call relationships, data flow relationships, control flow relationships, and temporal order relationships as graph edges, a causal behavior graph is constructed.

6. The MCP tool security access assessment method according to claim 1, characterized in that, The process of verifying the consistency of the capability contract graph, expected call graph, and causal behavior graph, and identifying abnormal behavior paths, includes: By comparing the causal behavior diagram with the capability contract diagram, undeclared capability calls can be identified; By comparing the causal behavior graph with the expected call graph, we can identify behaviors that deviate from the intended intent. Based on data tag propagation detection, sensitive data is propagated to unauthorized sinks, and a holistic analysis of multi-tool combined calls is performed to identify cross-tool permission amplification links; Detect inductive commands or anomalous loads in the tool's response to identify response-induced unauthorized actions; The identified abnormal behaviors are recorded as abnormal behavior paths, which include path type, graph nodes and edges involved, and evidence summary.

7. The MCP tool security access assessment method according to claim 1, characterized in that, The process of obtaining causal attribution and confidence levels through counterfactual replay generates risk scores and admission strategies. Graph nodes or edges that are not attributed or have confidence levels below a threshold are fed back as coverage targets, including: Under the same initial state, perform permission revocation replay, tool output replacement replay, and multi-toolchain node isolation replay on the abnormal behavior path respectively; By comparing the differences in causal behavior diagrams before and after counterfactual replay, the causal attribution results of abnormal behavior can be determined. The counterfactual causal confidence level is calculated based on the degree of difference significance, the reproducibility of the abnormal behavior, and the clarity of the minimum trigger set. Risk scores are calculated and risk levels are assigned by comprehensively considering factors such as undeclared capabilities, deviation from intent, leakage of sensitive data, amplification of cross-tool permissions, and counterfactual causal confidence. An access strategy is generated based on the causal attribution results and risk levels. The access strategy includes at least one of the following: tool whitelist, field-level parameter restrictions, file path range, network endpoint range, call count limit, and manual confirmation conditions. Graph nodes or edges that have not been causally attributed, as well as graph nodes or edges corresponding to abnormal behavior paths with confidence levels below a preset threshold, are fed back to the test case generation stage as coverage targets. The conditions, differences, and attribution conclusions of counterfactual replays are recorded as evidence and an evaluation report is generated.

8. A security access assessment system for MCP tools, characterized in that, include: The graph construction module is configured to parse the declaration information of the MCP tool service under test to construct the capability contract graph, and combine it with the calling intent to construct the expected calling graph; The behavior collection and association module is configured to generate test cases according to the coverage target, execute them in the isolation sandbox and collect cross-layer running events, and associate them into a causal behavior graph; The verification and causal feedback module is configured to perform consistency verification on the capability contract graph, expected call graph, and causal behavior graph and identify abnormal behavior paths. It obtains causal attribution and confidence through counterfactual replay, thereby generating risk scores and admission strategies, and feeding back graph nodes or edges that are not attributed or have confidence below the threshold as coverage targets.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the MCP tool security access assessment method according to any one of claims 1-7.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the MCP tool security access assessment method according to any one of claims 1-7.