@optimizeoverseas/lacrm-enforcement-wrapper 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +19 -5
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -5,8 +5,9 @@ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
|
5
5
|
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
6
6
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
7
7
|
// --- Configuration ---
|
|
8
|
-
const MAX_UNIQUE_CONTACTS =
|
|
9
|
-
const MAX_TOTAL_OPERATIONS =
|
|
8
|
+
const MAX_UNIQUE_CONTACTS = 20;
|
|
9
|
+
const MAX_TOTAL_OPERATIONS = 80;
|
|
10
|
+
const INACTIVITY_TIMEOUT_MS = 10 * 60 * 1000; // 10 minutes
|
|
10
11
|
const DOWNSTREAM_COMMAND = 'node';
|
|
11
12
|
const DOWNSTREAM_ARGS = ['/usr/local/lib/node_modules/@optimizeoverseas/lacrm-mcp/build/index.js'];
|
|
12
13
|
// Tools whose names start with these prefixes are filtered out entirely
|
|
@@ -21,6 +22,17 @@ const CONTACT_MUTATING_TOOLS = new Set([
|
|
|
21
22
|
// --- Session state ---
|
|
22
23
|
const modifiedContacts = new Set();
|
|
23
24
|
let totalOperations = 0;
|
|
25
|
+
let lastOperationTime = 0;
|
|
26
|
+
// --- Session management ---
|
|
27
|
+
function checkAndResetSessionIfInactive() {
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
if (lastOperationTime > 0 && (now - lastOperationTime) >= INACTIVITY_TIMEOUT_MS) {
|
|
30
|
+
// Reset session
|
|
31
|
+
modifiedContacts.clear();
|
|
32
|
+
totalOperations = 0;
|
|
33
|
+
}
|
|
34
|
+
lastOperationTime = now;
|
|
35
|
+
}
|
|
24
36
|
// --- Helpers ---
|
|
25
37
|
function isBlocked(toolName) {
|
|
26
38
|
return BLOCKED_PREFIXES.some((p) => toolName.startsWith(p));
|
|
@@ -34,17 +46,17 @@ function extractContactId(toolName, args) {
|
|
|
34
46
|
}
|
|
35
47
|
function checkBudgets(toolName, args) {
|
|
36
48
|
if (totalOperations >= MAX_TOTAL_OPERATIONS) {
|
|
37
|
-
return `
|
|
49
|
+
return `CRM operation limit reached (${MAX_TOTAL_OPERATIONS} operations). To continue, please start a new request.`;
|
|
38
50
|
}
|
|
39
51
|
if (CONTACT_MUTATING_TOOLS.has(toolName)) {
|
|
40
52
|
const contactId = extractContactId(toolName, args);
|
|
41
53
|
// For edit_contact, check if adding this contact would exceed the limit
|
|
42
54
|
if (contactId && !modifiedContacts.has(contactId) && modifiedContacts.size >= MAX_UNIQUE_CONTACTS) {
|
|
43
|
-
return `
|
|
55
|
+
return `Contact limit reached (${MAX_UNIQUE_CONTACTS} unique contacts). You can still edit contacts you've already modified: ${[...modifiedContacts].join(', ')}. To modify additional contacts, please start a new request.`;
|
|
44
56
|
}
|
|
45
57
|
// For create_contact (no contactId yet), check if there's room for one more
|
|
46
58
|
if (!contactId && modifiedContacts.size >= MAX_UNIQUE_CONTACTS) {
|
|
47
|
-
return `
|
|
59
|
+
return `Contact limit reached (${MAX_UNIQUE_CONTACTS} unique contacts). No additional contacts can be created or modified in this request. Please start a new request to continue.`;
|
|
48
60
|
}
|
|
49
61
|
}
|
|
50
62
|
return null;
|
|
@@ -91,6 +103,8 @@ async function main() {
|
|
|
91
103
|
// 4. Handle tools/call — enforce policies, then forward
|
|
92
104
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
93
105
|
const { name, arguments: args } = request.params;
|
|
106
|
+
// Reset session if inactive for 10+ minutes
|
|
107
|
+
checkAndResetSessionIfInactive();
|
|
94
108
|
// Block delete tools that somehow slip through
|
|
95
109
|
if (isBlocked(name)) {
|
|
96
110
|
return {
|