@purplesquirrel/guardrails-mcp-server 1.0.0
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/.github/dependabot.yml +21 -0
- package/.github/workflows/ci.yml +36 -0
- package/LICENSE +21 -0
- package/README.md +257 -0
- package/TROUBLESHOOTING.md +299 -0
- package/package.json +26 -0
- package/src/audit/AuditLogger.js +340 -0
- package/src/engine/GuardrailsEngine.js +305 -0
- package/src/filters/OutputFilter.js +296 -0
- package/src/policies/PolicyEngine.js +337 -0
- package/src/validators/InputValidator.js +291 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: "npm"
|
|
4
|
+
directory: "/"
|
|
5
|
+
schedule:
|
|
6
|
+
interval: "weekly"
|
|
7
|
+
open-pull-requests-limit: 10
|
|
8
|
+
labels:
|
|
9
|
+
- "dependencies"
|
|
10
|
+
commit-message:
|
|
11
|
+
prefix: "chore(deps)"
|
|
12
|
+
|
|
13
|
+
- package-ecosystem: "github-actions"
|
|
14
|
+
directory: "/"
|
|
15
|
+
schedule:
|
|
16
|
+
interval: "weekly"
|
|
17
|
+
labels:
|
|
18
|
+
- "dependencies"
|
|
19
|
+
- "github-actions"
|
|
20
|
+
commit-message:
|
|
21
|
+
prefix: "chore(ci)"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
node-version: [18.x, 20.x]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
21
|
+
uses: actions/setup-node@v4
|
|
22
|
+
with:
|
|
23
|
+
node-version: ${{ matrix.node-version }}
|
|
24
|
+
cache: 'npm'
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: npm ci
|
|
28
|
+
|
|
29
|
+
- name: Run linter
|
|
30
|
+
run: npm run lint --if-present
|
|
31
|
+
|
|
32
|
+
- name: Run tests
|
|
33
|
+
run: npm test --if-present
|
|
34
|
+
|
|
35
|
+
- name: Build
|
|
36
|
+
run: npm run build --if-present
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Purple Squirrel Media
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
[](https://opensource.org/licenses/MIT)
|
|
2
|
+
[](https://modelcontextprotocol.io)
|
|
3
|
+
[](https://github.com/PurpleSquirrelMedia/guardrails-mcp-server)
|
|
4
|
+
[](https://github.com/PurpleSquirrelMedia/guardrails-mcp-server/actions/workflows/ci.yml)
|
|
5
|
+
|
|
6
|
+
# AI Guardrails MCP Server
|
|
7
|
+
|
|
8
|
+
MCP server providing security guardrails for Claude Code and AI agents. Implements input validation, output filtering, policy enforcement, and audit logging.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Input Validation** - Sanitize and validate all inputs before processing
|
|
13
|
+
- **Output Filtering** - Redact sensitive data from responses
|
|
14
|
+
- **Policy Enforcement** - Enforce custom security policies
|
|
15
|
+
- **Audit Logging** - Complete audit trail of all requests
|
|
16
|
+
- **Rate Limiting** - Protect against abuse and overuse
|
|
17
|
+
|
|
18
|
+
## Architecture
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
User Request
|
|
22
|
+
│
|
|
23
|
+
▼
|
|
24
|
+
┌─────────────────────────────────────┐
|
|
25
|
+
│ Guardrails Engine │
|
|
26
|
+
├─────────────────────────────────────┤
|
|
27
|
+
│ ┌─────────┐ ┌──────────────────┐ │
|
|
28
|
+
│ │ Rate │ │ Input │ │
|
|
29
|
+
│ │ Limiter │──▶ Validator │ │
|
|
30
|
+
│ └─────────┘ └────────┬─────────┘ │
|
|
31
|
+
│ │ │
|
|
32
|
+
│ ┌────────▼─────────┐ │
|
|
33
|
+
│ │ Policy │ │
|
|
34
|
+
│ │ Engine │ │
|
|
35
|
+
│ └────────┬─────────┘ │
|
|
36
|
+
│ │ │
|
|
37
|
+
│ ┌────────▼─────────┐ │
|
|
38
|
+
│ │ Output │ │
|
|
39
|
+
│ │ Filter │ │
|
|
40
|
+
│ └────────┬─────────┘ │
|
|
41
|
+
│ │ │
|
|
42
|
+
│ ┌─────────────────────▼─────────┐ │
|
|
43
|
+
│ │ Audit Logger │ │
|
|
44
|
+
│ └───────────────────────────────┘ │
|
|
45
|
+
└─────────────────────────────────────┘
|
|
46
|
+
│
|
|
47
|
+
▼
|
|
48
|
+
Response
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Components
|
|
52
|
+
|
|
53
|
+
### GuardrailsEngine (`src/engine/GuardrailsEngine.js`)
|
|
54
|
+
|
|
55
|
+
Core orchestration engine that coordinates all security components:
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
import { GuardrailsEngine } from './src/engine/GuardrailsEngine.js';
|
|
59
|
+
|
|
60
|
+
const engine = new GuardrailsEngine({
|
|
61
|
+
enableInputValidation: true,
|
|
62
|
+
enableOutputFiltering: true,
|
|
63
|
+
enablePolicyEnforcement: true,
|
|
64
|
+
enableAuditLogging: true,
|
|
65
|
+
enableRateLimiting: true,
|
|
66
|
+
maxRequestsPerMinute: 60,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Process incoming request
|
|
70
|
+
const result = await engine.processInput(request, { userId: 'user123' });
|
|
71
|
+
|
|
72
|
+
// Filter outgoing response
|
|
73
|
+
const filtered = await engine.processOutput(response, context);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### InputValidator (`src/validators/InputValidator.js`)
|
|
77
|
+
|
|
78
|
+
Validates and sanitizes incoming requests:
|
|
79
|
+
|
|
80
|
+
- Pattern matching for blocked content
|
|
81
|
+
- Size and token limits
|
|
82
|
+
- Character encoding validation
|
|
83
|
+
- SQL injection detection
|
|
84
|
+
- XSS prevention
|
|
85
|
+
|
|
86
|
+
### OutputFilter (`src/filters/OutputFilter.js`)
|
|
87
|
+
|
|
88
|
+
Filters and redacts sensitive information from outputs:
|
|
89
|
+
|
|
90
|
+
- PII detection and redaction (SSN, credit cards, emails)
|
|
91
|
+
- API key/secret detection
|
|
92
|
+
- Custom pattern redaction
|
|
93
|
+
- Configurable replacement text
|
|
94
|
+
|
|
95
|
+
### PolicyEngine (`src/policies/PolicyEngine.js`)
|
|
96
|
+
|
|
97
|
+
Enforces custom security policies:
|
|
98
|
+
|
|
99
|
+
- Allow/deny lists for operations
|
|
100
|
+
- Domain restrictions
|
|
101
|
+
- Resource access controls
|
|
102
|
+
- Custom policy rules
|
|
103
|
+
|
|
104
|
+
### AuditLogger (`src/audit/AuditLogger.js`)
|
|
105
|
+
|
|
106
|
+
Comprehensive audit logging:
|
|
107
|
+
|
|
108
|
+
- Request/response logging
|
|
109
|
+
- Policy violation tracking
|
|
110
|
+
- Rate limit events
|
|
111
|
+
- Searchable log queries
|
|
112
|
+
|
|
113
|
+
## Configuration
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
const config = {
|
|
117
|
+
// Feature toggles
|
|
118
|
+
enableInputValidation: true,
|
|
119
|
+
enableOutputFiltering: true,
|
|
120
|
+
enablePolicyEnforcement: true,
|
|
121
|
+
enableAuditLogging: true,
|
|
122
|
+
enableRateLimiting: true,
|
|
123
|
+
|
|
124
|
+
// Rate limiting
|
|
125
|
+
maxRequestsPerMinute: 60,
|
|
126
|
+
maxTokensPerRequest: 100000,
|
|
127
|
+
|
|
128
|
+
// Security patterns
|
|
129
|
+
blockedPatterns: [
|
|
130
|
+
/password\s*[:=]/i,
|
|
131
|
+
/api[_-]?key/i,
|
|
132
|
+
],
|
|
133
|
+
|
|
134
|
+
// Domain restrictions
|
|
135
|
+
allowedDomains: ['api.example.com'],
|
|
136
|
+
|
|
137
|
+
// Sensitive data patterns for redaction
|
|
138
|
+
sensitiveDataPatterns: [
|
|
139
|
+
{ pattern: /\b\d{3}-\d{2}-\d{4}\b/, replacement: '[SSN REDACTED]' },
|
|
140
|
+
{ pattern: /\b\d{16}\b/, replacement: '[CARD REDACTED]' },
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Installation
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
cd ~/guardrails-mcp-server
|
|
149
|
+
npm install
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Usage with Claude Code
|
|
153
|
+
|
|
154
|
+
Add to `~/.claude.json`:
|
|
155
|
+
|
|
156
|
+
```json
|
|
157
|
+
{
|
|
158
|
+
"mcpServers": {
|
|
159
|
+
"guardrails": {
|
|
160
|
+
"type": "stdio",
|
|
161
|
+
"command": "node",
|
|
162
|
+
"args": ["/path/to/guardrails-mcp-server/index.js"]
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Use Cases
|
|
169
|
+
|
|
170
|
+
### Enterprise AI Deployments
|
|
171
|
+
|
|
172
|
+
- Ensure all AI interactions comply with security policies
|
|
173
|
+
- Prevent data leakage through output filtering
|
|
174
|
+
- Maintain audit trails for compliance
|
|
175
|
+
|
|
176
|
+
### Multi-Tenant Systems
|
|
177
|
+
|
|
178
|
+
- Rate limiting per user/tenant
|
|
179
|
+
- Policy isolation between tenants
|
|
180
|
+
- Usage tracking and billing
|
|
181
|
+
|
|
182
|
+
### Regulated Industries
|
|
183
|
+
|
|
184
|
+
- Healthcare: HIPAA compliance with PHI detection
|
|
185
|
+
- Finance: PCI-DSS with card number redaction
|
|
186
|
+
- Government: Data classification enforcement
|
|
187
|
+
|
|
188
|
+
## API
|
|
189
|
+
|
|
190
|
+
### processInput(request, context)
|
|
191
|
+
|
|
192
|
+
Process and validate an incoming request.
|
|
193
|
+
|
|
194
|
+
**Returns:**
|
|
195
|
+
```javascript
|
|
196
|
+
{
|
|
197
|
+
allowed: boolean,
|
|
198
|
+
requestId: string,
|
|
199
|
+
request: object, // Sanitized request
|
|
200
|
+
processingTime: number,
|
|
201
|
+
// If blocked:
|
|
202
|
+
reason: string,
|
|
203
|
+
code: 'RATE_LIMIT' | 'VALIDATION_ERROR' | 'POLICY_VIOLATION',
|
|
204
|
+
violations: array,
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### processOutput(response, context)
|
|
209
|
+
|
|
210
|
+
Filter and redact sensitive data from a response.
|
|
211
|
+
|
|
212
|
+
**Returns:**
|
|
213
|
+
```javascript
|
|
214
|
+
{
|
|
215
|
+
filtered: boolean,
|
|
216
|
+
response: object, // Filtered response
|
|
217
|
+
redactions: array, // List of redactions applied
|
|
218
|
+
processingTime: number,
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### getStats()
|
|
223
|
+
|
|
224
|
+
Get current engine statistics.
|
|
225
|
+
|
|
226
|
+
### getAuditLogs(filter)
|
|
227
|
+
|
|
228
|
+
Query audit logs with optional filtering.
|
|
229
|
+
|
|
230
|
+
## Files
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
guardrails-mcp-server/
|
|
234
|
+
├── package.json
|
|
235
|
+
├── README.md
|
|
236
|
+
├── src/
|
|
237
|
+
│ ├── engine/
|
|
238
|
+
│ │ └── GuardrailsEngine.js # Core engine
|
|
239
|
+
│ ├── validators/
|
|
240
|
+
│ │ └── InputValidator.js # Input validation
|
|
241
|
+
│ ├── filters/
|
|
242
|
+
│ │ └── OutputFilter.js # Output filtering
|
|
243
|
+
│ ├── policies/
|
|
244
|
+
│ │ └── PolicyEngine.js # Policy enforcement
|
|
245
|
+
│ └── audit/
|
|
246
|
+
│ └── AuditLogger.js # Audit logging
|
|
247
|
+
├── tests/
|
|
248
|
+
└── docs/
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Author
|
|
252
|
+
|
|
253
|
+
Matthew Karsten - Purple Squirrel Media
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
MIT
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# Troubleshooting Guide
|
|
2
|
+
|
|
3
|
+
Common issues and solutions for the AI Guardrails MCP Server.
|
|
4
|
+
|
|
5
|
+
## Rate Limiting Issues
|
|
6
|
+
|
|
7
|
+
### `RATE_LIMIT` - Request blocked
|
|
8
|
+
|
|
9
|
+
**Cause**: Too many requests in the time window.
|
|
10
|
+
|
|
11
|
+
**Solutions**:
|
|
12
|
+
1. Increase `maxRequestsPerMinute` in config
|
|
13
|
+
2. Add delays between rapid requests
|
|
14
|
+
3. Check if legitimate usage or potential abuse
|
|
15
|
+
|
|
16
|
+
**Example config adjustment**:
|
|
17
|
+
```javascript
|
|
18
|
+
const engine = new GuardrailsEngine({
|
|
19
|
+
maxRequestsPerMinute: 120, // Increase from default 60
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Rate limits applying to wrong users
|
|
24
|
+
|
|
25
|
+
**Cause**: User context not being passed correctly.
|
|
26
|
+
|
|
27
|
+
**Solution**: Always include `userId` in context:
|
|
28
|
+
```javascript
|
|
29
|
+
const result = await engine.processInput(request, {
|
|
30
|
+
userId: 'unique-user-id',
|
|
31
|
+
tenantId: 'tenant-123' // For multi-tenant setups
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Input Validation Issues
|
|
36
|
+
|
|
37
|
+
### `VALIDATION_ERROR` - Request rejected
|
|
38
|
+
|
|
39
|
+
**Cause**: Input matched a blocked pattern.
|
|
40
|
+
|
|
41
|
+
**Solutions**:
|
|
42
|
+
1. Check which pattern triggered the block
|
|
43
|
+
2. Review `blockedPatterns` configuration
|
|
44
|
+
3. Add exceptions for legitimate use cases
|
|
45
|
+
|
|
46
|
+
**Checking violation details**:
|
|
47
|
+
```javascript
|
|
48
|
+
if (!result.allowed) {
|
|
49
|
+
console.log('Violations:', result.violations);
|
|
50
|
+
// [{pattern: '...', message: '...'}]
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### False positives on valid content
|
|
55
|
+
|
|
56
|
+
**Cause**: Pattern too broad.
|
|
57
|
+
|
|
58
|
+
**Solutions**:
|
|
59
|
+
1. Make patterns more specific
|
|
60
|
+
2. Add word boundaries: `\bpassword\b` instead of `password`
|
|
61
|
+
3. Use negative lookahead for exceptions
|
|
62
|
+
|
|
63
|
+
**Example**:
|
|
64
|
+
```javascript
|
|
65
|
+
blockedPatterns: [
|
|
66
|
+
// Too broad - blocks "password reset"
|
|
67
|
+
/password/i,
|
|
68
|
+
|
|
69
|
+
// Better - only blocks password disclosure
|
|
70
|
+
/password\s*[:=]\s*\S+/i,
|
|
71
|
+
]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Token limit exceeded
|
|
75
|
+
|
|
76
|
+
**Cause**: Request too large.
|
|
77
|
+
|
|
78
|
+
**Solution**: Adjust `maxTokensPerRequest`:
|
|
79
|
+
```javascript
|
|
80
|
+
const engine = new GuardrailsEngine({
|
|
81
|
+
maxTokensPerRequest: 200000, // Increase limit
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Output Filtering Issues
|
|
86
|
+
|
|
87
|
+
### Sensitive data not being redacted
|
|
88
|
+
|
|
89
|
+
**Cause**: Pattern doesn't match the format.
|
|
90
|
+
|
|
91
|
+
**Solutions**:
|
|
92
|
+
1. Check regex pattern syntax
|
|
93
|
+
2. Test patterns with sample data
|
|
94
|
+
3. Add additional patterns for variations
|
|
95
|
+
|
|
96
|
+
**Common patterns**:
|
|
97
|
+
```javascript
|
|
98
|
+
sensitiveDataPatterns: [
|
|
99
|
+
// SSN variations
|
|
100
|
+
{ pattern: /\b\d{3}-\d{2}-\d{4}\b/, replacement: '[SSN]' },
|
|
101
|
+
{ pattern: /\b\d{9}\b/, replacement: '[SSN]' },
|
|
102
|
+
|
|
103
|
+
// Credit cards (13-19 digits)
|
|
104
|
+
{ pattern: /\b\d{13,19}\b/, replacement: '[CARD]' },
|
|
105
|
+
{ pattern: /\b\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/, replacement: '[CARD]' },
|
|
106
|
+
|
|
107
|
+
// Email addresses
|
|
108
|
+
{ pattern: /\b[\w.+-]+@[\w.-]+\.\w{2,}\b/g, replacement: '[EMAIL]' },
|
|
109
|
+
|
|
110
|
+
// API keys (common formats)
|
|
111
|
+
{ pattern: /\b(sk|pk|api)[_-][a-zA-Z0-9]{20,}\b/g, replacement: '[API_KEY]' },
|
|
112
|
+
]
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Over-redaction of content
|
|
116
|
+
|
|
117
|
+
**Cause**: Patterns too aggressive.
|
|
118
|
+
|
|
119
|
+
**Solutions**:
|
|
120
|
+
1. Use more specific patterns
|
|
121
|
+
2. Add context requirements
|
|
122
|
+
3. Use word boundaries
|
|
123
|
+
|
|
124
|
+
### Performance slow on large outputs
|
|
125
|
+
|
|
126
|
+
**Cause**: Many regex patterns or large text.
|
|
127
|
+
|
|
128
|
+
**Solutions**:
|
|
129
|
+
1. Compile regex patterns once (use RegExp objects)
|
|
130
|
+
2. Use simpler patterns where possible
|
|
131
|
+
3. Consider chunking large outputs
|
|
132
|
+
|
|
133
|
+
## Policy Engine Issues
|
|
134
|
+
|
|
135
|
+
### `POLICY_VIOLATION` - Action blocked
|
|
136
|
+
|
|
137
|
+
**Cause**: Request violates a configured policy.
|
|
138
|
+
|
|
139
|
+
**Check policy details**:
|
|
140
|
+
```javascript
|
|
141
|
+
if (!result.allowed && result.code === 'POLICY_VIOLATION') {
|
|
142
|
+
console.log('Policy violated:', result.reason);
|
|
143
|
+
console.log('Violations:', result.violations);
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Domain restrictions not working
|
|
148
|
+
|
|
149
|
+
**Cause**: URL parsing or matching issue.
|
|
150
|
+
|
|
151
|
+
**Solution**: Check domain format:
|
|
152
|
+
```javascript
|
|
153
|
+
// Correct
|
|
154
|
+
allowedDomains: ['api.example.com', 'cdn.example.com']
|
|
155
|
+
|
|
156
|
+
// Wrong - don't include protocol
|
|
157
|
+
allowedDomains: ['https://api.example.com']
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Custom policies not executing
|
|
161
|
+
|
|
162
|
+
**Cause**: Policy syntax or registration issue.
|
|
163
|
+
|
|
164
|
+
**Solution**: Verify policy structure:
|
|
165
|
+
```javascript
|
|
166
|
+
const customPolicy = {
|
|
167
|
+
name: 'my-policy',
|
|
168
|
+
description: 'Custom validation',
|
|
169
|
+
evaluate: (request, context) => {
|
|
170
|
+
if (/* violation condition */) {
|
|
171
|
+
return {
|
|
172
|
+
allowed: false,
|
|
173
|
+
reason: 'Policy violation description',
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return { allowed: true };
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Audit Logging Issues
|
|
182
|
+
|
|
183
|
+
### Logs not being written
|
|
184
|
+
|
|
185
|
+
**Cause**: Audit logging disabled or path issue.
|
|
186
|
+
|
|
187
|
+
**Solutions**:
|
|
188
|
+
1. Verify `enableAuditLogging: true`
|
|
189
|
+
2. Check log file path permissions
|
|
190
|
+
3. Ensure disk has space
|
|
191
|
+
|
|
192
|
+
### Log queries returning empty
|
|
193
|
+
|
|
194
|
+
**Cause**: Filter too restrictive or no matching logs.
|
|
195
|
+
|
|
196
|
+
**Solution**: Broaden filter:
|
|
197
|
+
```javascript
|
|
198
|
+
// Start with no filter
|
|
199
|
+
const logs = await engine.getAuditLogs({});
|
|
200
|
+
|
|
201
|
+
// Then narrow down
|
|
202
|
+
const logs = await engine.getAuditLogs({
|
|
203
|
+
startTime: new Date(Date.now() - 3600000), // Last hour
|
|
204
|
+
userId: 'user123',
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Log file growing too large
|
|
209
|
+
|
|
210
|
+
**Solutions**:
|
|
211
|
+
1. Implement log rotation
|
|
212
|
+
2. Set up external log aggregation
|
|
213
|
+
3. Configure retention policy
|
|
214
|
+
|
|
215
|
+
## Configuration Issues
|
|
216
|
+
|
|
217
|
+
### Engine not initializing
|
|
218
|
+
|
|
219
|
+
**Cause**: Invalid configuration object.
|
|
220
|
+
|
|
221
|
+
**Solution**: Check all required fields:
|
|
222
|
+
```javascript
|
|
223
|
+
const engine = new GuardrailsEngine({
|
|
224
|
+
enableInputValidation: true,
|
|
225
|
+
enableOutputFiltering: true,
|
|
226
|
+
enablePolicyEnforcement: true,
|
|
227
|
+
enableAuditLogging: true,
|
|
228
|
+
enableRateLimiting: true,
|
|
229
|
+
maxRequestsPerMinute: 60,
|
|
230
|
+
});
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Hot reload not working
|
|
234
|
+
|
|
235
|
+
**Cause**: Config changes not detected.
|
|
236
|
+
|
|
237
|
+
**Solution**: Implement reload:
|
|
238
|
+
```javascript
|
|
239
|
+
// Reload configuration
|
|
240
|
+
engine.updateConfig(newConfig);
|
|
241
|
+
|
|
242
|
+
// Or recreate engine
|
|
243
|
+
engine = new GuardrailsEngine(newConfig);
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## MCP Server Issues
|
|
247
|
+
|
|
248
|
+
### Server not appearing in Claude Code
|
|
249
|
+
|
|
250
|
+
**Solutions**:
|
|
251
|
+
1. Verify `~/.claude.json` syntax
|
|
252
|
+
2. Check path to `index.js`
|
|
253
|
+
3. Restart Claude Code
|
|
254
|
+
4. Test: `node /path/to/guardrails-mcp-server/index.js`
|
|
255
|
+
|
|
256
|
+
### Module not found errors
|
|
257
|
+
|
|
258
|
+
**Solution**:
|
|
259
|
+
```bash
|
|
260
|
+
cd ~/guardrails-mcp-server
|
|
261
|
+
npm install
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Debugging
|
|
265
|
+
|
|
266
|
+
### Enable debug mode
|
|
267
|
+
|
|
268
|
+
```javascript
|
|
269
|
+
const engine = new GuardrailsEngine({
|
|
270
|
+
// ... other config
|
|
271
|
+
debug: true, // Verbose logging
|
|
272
|
+
});
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Test individual components
|
|
276
|
+
|
|
277
|
+
```javascript
|
|
278
|
+
// Test input validator
|
|
279
|
+
const validator = new InputValidator(config);
|
|
280
|
+
const result = validator.validate(testInput);
|
|
281
|
+
|
|
282
|
+
// Test output filter
|
|
283
|
+
const filter = new OutputFilter(config);
|
|
284
|
+
const result = filter.filter(testOutput);
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### View engine statistics
|
|
288
|
+
|
|
289
|
+
```javascript
|
|
290
|
+
const stats = engine.getStats();
|
|
291
|
+
console.log('Requests processed:', stats.totalRequests);
|
|
292
|
+
console.log('Requests blocked:', stats.blockedRequests);
|
|
293
|
+
console.log('Rate limit hits:', stats.rateLimitHits);
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Getting Help
|
|
297
|
+
|
|
298
|
+
- [GitHub Issues](https://github.com/PurpleSquirrelMedia/guardrails-mcp-server/issues)
|
|
299
|
+
- [OWASP Input Validation](https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html)
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@purplesquirrel/guardrails-mcp-server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "AI Agent Guardrails MCP Server - Security layer for Claude Code and AI agents",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"start": "node index.js",
|
|
9
|
+
"test": "node --test tests/",
|
|
10
|
+
"dev": "node --watch index.js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"mcp",
|
|
14
|
+
"claude",
|
|
15
|
+
"guardrails",
|
|
16
|
+
"ai-safety",
|
|
17
|
+
"security",
|
|
18
|
+
"validation",
|
|
19
|
+
"filtering"
|
|
20
|
+
],
|
|
21
|
+
"author": "Purple Squirrel Media",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
25
|
+
}
|
|
26
|
+
}
|