๐ค AI Agent Support
Enabling AI Assistants to Generate High-Quality MCP Server Tests
AI Agents โ Generate MCP Tests
MCP Aegis ships with dedicated AGENTS.md guides and proven prompt templates to help AI coding assistants automatically generate high-quality MCP server tests using established patterns and conventions.
๐ AGENTS.md Guide System
MCP Aegis provides dedicated AI agent guides copied directly into your project during initialization. These guides contain comprehensive instructions, examples, and best practices tailored for AI assistants.
๐ฏ Three Specialized Guides
๏ฟฝ Main AGENTS.md
Overview guide with decision matrix
test/mcp/AGENTS.md๐ YAML AGENTS.md
Declarative testing patterns
test/mcp/yaml/AGENTS.md๐ป Node AGENTS.md
Programmatic testing API
test/mcp/node/AGENTS.md๐ Auto-Installation
The guides are automatically copied to your project during initialization:
npx mcp-aegis initThis copies the latest AGENTS.md files from the repository's AGENTS/ directory into your project's test structure for offline reference.
๐ What's Inside AGENTS.md
- โ Project detection heuristics
- โ Configuration templates
- โ Pattern matching examples
- โ Common anti-patterns to avoid
- โ Workflow best practices
- โ Error handling guidance
๐ฏ Target Audience
- ๐ค AI coding assistants (Copilot, Cursor, etc.)
- ๐ง Autonomous testing agents
- โก Code generation tools
- ๐ง LLM-powered development workflows
- ๐ ๏ธ Custom automation scripts
๐ Quick Detection Guide
AI agents should look for these patterns to identify MCP Aegis projects:
๐๏ธ File Indicators
aegis.config.jsonor*.config.json.test.mcp.ymlfiles in test directoriesAGENTS/directory with AI guides
โ๏ธ Code Patterns
- JSON-RPC with
tools/listortools/call - Imports from
mcp-aegis - MCP protocol handshake sequences
๐ AI Agent Workflow Summary
Follow this workflow with the AGENTS.md guides as your primary reference:
๐ Detect MCP patterns โ Run npx mcp-aegis init
Copies AGENTS.md guides into your project
๐ Read test/mcp/AGENTS.md for overview
Understand approach selection and conventions
๐ Reference test/mcp/yaml/AGENTS.md or test/mcp/node/AGENTS.md
Follow specific guide for your chosen testing approach
๐งช Generate tests using patterns from guides
Apply examples, patterns, and anti-patterns from AGENTS.md
โ Validate with npm scripts โ Stop when coverage complete
Handshake + discovery + at least one tool execution
๐ฏ Advanced Pattern Matching
Leverage MCP Aegis's 50+ pattern types for precise validation:
๐ Common Patterns
"match:arrayLength:3" - Exact length"match:contains:MCP" - String contains"match:type:array" - Type validation"match:not:arrayLength:0" - Pattern negation๐ง Advanced Patterns
"match:arrayContains:name:read_file" - Object field matching"match:regex:\\d+ files" - Regex validation"match:extractField:tools.*.name" - Field extraction"match:dateAfter:2023-01-01" - Date comparisonsPro Tip: Use Pattern Matching Guide for complete reference with examples and edge cases.
๐ง Ready-to-Use Prompt Templates
Use these battle-tested prompts to generate consistent, high-quality MCP tests. Each template is designed to work with the AGENTS.md guides and established conventions.
๐ MCP Project Detection
Identify and initialize MCP Aegis projects
You are an AI assistant helping to set up MCP (Model Context Protocol) testing for a project.
**TASK**: Analyze this project and determine if it's an MCP server that needs MCP Aegis testing setup.
**DETECTION CHECKLIST**:
โก Look for aegis.config.json or *.config.json files with MCP server configuration
โก Search for .test.mcp.yml files in test/ or tests/ directories
โก Check for JSON-RPC code patterns with "tools/list" or "tools/call" methods
โก Find imports from 'mcp-aegis' package in existing code
โก Look for AGENTS/ directory in the repository root
**IF MCP PATTERNS FOUND**:
1. Run initialization: `npx mcp-aegis init`
2. Verify the created structure:
- test/mcp/AGENTS.md (main overview guide)
- test/mcp/yaml/AGENTS.md (YAML testing patterns)
- test/mcp/node/AGENTS.md (programmatic API guide)
3. Update aegis.config.json with actual server details:
- Correct command/args for server startup
- Proper working directory if needed
- Environment variables if required
**OUTPUT**:
- Report detection results with specific evidence found
- List next steps based on findings
- If MCP patterns found, proceed with configuration setup
- If no patterns found, explain this is not an MCP project๐ YAML Test Generation
Generate declarative YAML tests with proper patterns
You are an expert at generating MCP Aegis YAML test files. Create a comprehensive test file that validates an MCP server.
**REQUIREMENTS**:
1. **File Location**: Save as test/mcp/yaml/[server-name]-validation.test.mcp.yml
2. **Structure**: Use proper YAML format with description and tests array
3. **Coverage**: Include both tools/list and tools/call validation
**YAML TEMPLATE**:
```yaml
description: "Comprehensive MCP server validation tests"
tests:
# Test 1: Validate server lists available tools
- it: "should successfully list all available tools"
request:
jsonrpc: "2.0"
id: "tools-list-1"
method: "tools/list"
params: {}
expect:
response:
jsonrpc: "2.0"
id: "tools-list-1"
result:
tools: "match:not:arrayLength:0" # Ensure tools array is not empty
stderr: "toBeEmpty" # No errors in stderr
# Test 2: Validate specific tool execution
- it: "should execute [TOOL_NAME] tool successfully"
request:
jsonrpc: "2.0"
id: "tool-call-1"
method: "tools/call"
params:
name: "[TOOL_NAME]" # Replace with actual tool name
arguments:
# Add tool-specific arguments here
expect:
response:
jsonrpc: "2.0"
id: "tool-call-1"
result:
content: "match:type:array" # Validate content structure
isError: false
stderr: "toBeEmpty"
```
**CRITICAL PATTERNS TO USE**:
- "match:not:arrayLength:0" for non-empty arrays
- "match:type:array" for array validation
- "match:contains:text" for string content validation
- "toBeEmpty" for stderr validation
**AVOID THESE ANTI-PATTERNS**:
โ Duplicate YAML keys (overwrites previous values)
โ Hard-coding entire response objects
โ Missing stderr validation
โ Mixing pattern types in same object
**CUSTOMIZATION**: Replace [TOOL_NAME] and arguments with actual values from the server's tools/list response.๐ป Programmatic Test Generation
Create Node.js tests with proper lifecycle management
You are an expert at creating Node.js test files for MCP servers using the MCP Aegis programmatic API.
**TASK**: Create a comprehensive programmatic test file that validates MCP server functionality.
**FILE TEMPLATE**:
```javascript
import { test, before, after, beforeEach, describe } from 'node:test';
import { strict as assert } from 'node:assert';
import { connect } from 'mcp-aegis';
describe('MCP Server Integration Tests', () => {
let client;
// Setup: Connect to MCP server once
before(async () => {
client = await connect('./aegis.config.json');
console.log('โ
Connected to MCP server');
});
// CRITICAL: Clear buffers between tests to prevent interference
beforeEach(() => {
client.clearAllBuffers();
});
// Cleanup: Disconnect after all tests
after(async () => {
if (client) {
await client.disconnect();
console.log('โ
Disconnected from MCP server');
}
});
test('should successfully list available tools', async () => {
const tools = await client.listTools();
// Validate tools array structure
assert.ok(Array.isArray(tools), 'Tools should be an array');
assert.ok(tools.length > 0, 'Should have at least one tool available');
// Validate each tool has required properties
tools.forEach(tool => {
assert.ok(typeof tool.name === 'string', 'Tool should have a name');
assert.ok(typeof tool.description === 'string', 'Tool should have a description');
assert.ok(typeof tool.inputSchema === 'object', 'Tool should have input schema');
});
console.log(`โ
Found ${tools.length} tools: ${tools.map(t => t.name).join(', ')}`);
});
test('should execute [TOOL_NAME] tool successfully', async () => {
const result = await client.callTool('[TOOL_NAME]', {
// Add tool-specific arguments here
});
// Validate response structure
assert.ok(Array.isArray(result.content), 'Result content should be an array');
assert.strictEqual(result.isError, false, 'Tool execution should not have errors');
// Add tool-specific validations here
console.log('โ
Tool executed successfully');
});
test('should handle invalid tool calls gracefully', async () => {
try {
await client.callTool('nonexistent_tool', {});
assert.fail('Should have thrown an error for invalid tool');
} catch (error) {
assert.ok(error.message.includes('tool'), 'Error should mention tool issue');
console.log('โ
Invalid tool call handled correctly');
}
});
});
```
**CRITICAL REQUIREMENTS**:
1. **File Location**: Save as test/mcp/node/[server-name]-integration.programmatic.test.js
2. **Buffer Management**: ALWAYS include `beforeEach(() => client.clearAllBuffers());`
3. **Lifecycle**: Proper before/after hooks for connection management
4. **Error Handling**: Test both success and failure scenarios
**CUSTOMIZATION STEPS**:
1. Replace [TOOL_NAME] with actual tool names from your server
2. Add appropriate arguments for each tool test
3. Include tool-specific validation logic
4. Test edge cases and error conditions
**RUN COMMAND**: `node --test test/mcp/node/**/*.programmatic.test.js`โ๏ธ Configuration Setup
Create proper aegis.config.json
You are setting up MCP Aegis configuration for an MCP server project.
**TASK**: Create or update aegis.config.json with proper MCP server configuration.
**CONFIGURATION TEMPLATE**:
```json
{
"name": "My MCP Server",
"command": "node",
"args": ["./server.js"],
"cwd": "./",
"startupTimeout": 5000,
"env": {
"NODE_ENV": "test"
}
}
```
**FIELD EXPLANATIONS**:
**Required Fields**:
- `name`: Human-readable server name for test reports
- `command`: Executable command (node, python, ./binary, etc.)
- `args`: Array of arguments passed to the command
**Optional Fields**:
- `cwd`: Working directory for server execution (default: "./")
- `env`: Environment variables as key-value object
- `startupTimeout`: Max milliseconds to wait for startup (default: 10000)
- `readyPattern`: Regex pattern in stderr indicating server ready (avoid if possible)
**COMMON CONFIGURATIONS**:
**Node.js Server**:
```json
{
"name": "Node MCP Server",
"command": "node",
"args": ["./src/server.js", "--port", "3000"],
"cwd": "./",
"startupTimeout": 8000
}
```
**Python Server**:
```json
{
"name": "Python MCP Server",
"command": "python",
"args": ["./server.py", "--debug"],
"cwd": "./server",
"env": {
"PYTHONPATH": "./src",
"DEBUG": "true"
},
"startupTimeout": 10000
}
```
**Binary/Executable**:
```json
{
"name": "Go MCP Server",
"command": "./bin/mcp-server",
"args": ["--config", "config.json"],
"cwd": "./",
"startupTimeout": 3000
}
```
**VALIDATION STEPS**:
1. Save configuration as `aegis.config.json` in project root
2. Test configuration: `aegis query --config ./aegis.config.json`
3. Verify server starts and responds to tools/list
4. Adjust timeout/args as needed based on server behavior
**TROUBLESHOOTING**:
- If server takes long to start, increase `startupTimeout`
- If server needs specific working directory, set `cwd`
- If server requires environment variables, add them to `env`
- Avoid `readyPattern` unless server doesn't follow MCP stdio protocol๐ npm Scripts Setup
Add convenient testing commands
You are setting up convenient npm scripts for MCP testing in a project's package.json.
**TASK**: Add comprehensive npm scripts to package.json for MCP Aegis testing workflow.
**RECOMMENDED SCRIPTS**:
```json
{
"scripts": {
// Core Testing Scripts
"test:mcp:yaml": "mcp-aegis 'test*/mcp/yaml/**/*.test.mcp.yml' --config ./aegis.config.json",
"test:mcp:node": "node --test 'test*/mcp/node/**/*.programmatic.test.js'",
"test:mcp:all": "npm run test:mcp:yaml && npm run test:mcp:node",
// Debugging & Development Scripts
"debug:mcp": "mcp-aegis query --config ./aegis.config.json",
"debug:mcp:verbose": "mcp-aegis query --config ./aegis.config.json --verbose --debug",
"debug:mcp:tools": "mcp-aegis query --config ./aegis.config.json --method tools/list",
// CI/CD Scripts
"test:mcp:ci": "mcp-aegis 'test*/mcp/yaml/**/*.test.mcp.yml' --config ./aegis.config.json --json --quiet",
"test:mcp:errors": "mcp-aegis 'test*/mcp/yaml/**/*.test.mcp.yml' --config ./aegis.config.json --errors-only",
// Development Helpers
"mcp:init": "npx mcp-aegis init",
"mcp:validate": "mcp-aegis 'test*/mcp/yaml/**/*.test.mcp.yml' --config ./aegis.config.json --dry-run"
}
}
```
**SCRIPT EXPLANATIONS**:
**Core Testing**:
- `test:mcp:yaml`: Run all YAML-based MCP tests
- `test:mcp:node`: Run all programmatic Node.js tests
- `test:mcp:all`: Run complete MCP test suite
**Interactive Debugging**:
- `debug:mcp`: Interactive tool exploration
- `debug:mcp:verbose`: Detailed debug output with timing
- `debug:mcp:tools`: Quick tools/list validation
**CI/CD Integration**:
- `test:mcp:ci`: JSON output for CI systems
- `test:mcp:errors`: Focus on error reporting
**Development Helpers**:
- `mcp:init`: Initialize MCP testing structure
- `mcp:validate`: Dry-run validation without execution
**USAGE EXAMPLES**:
**Development Workflow**:
```bash
# Run all tests during development
npm run test:mcp:all
# Debug specific tool interactively
npm run debug:mcp
# Quick validation
npm run test:mcp:yaml
```
**CI/CD Pipeline**:
```bash
# In GitHub Actions / CI
npm run test:mcp:ci
# Error-focused output
npm run test:mcp:errors
```
**Tool-Specific Testing**:
```bash
# Call specific tool for testing
mcp-aegis query read_file '{"path": "test.txt"}' --config ./aegis.config.json
# Using npm script with method syntax
npx mcp-aegis query --config ./aegis.config.json --method tools/call --params '{"name":"read_file","arguments":{"path":"test.txt"}}'
```
**INTEGRATION**: Add these scripts to the existing package.json "scripts" section, merging with any existing test scripts.๐ซ Critical Anti-Patterns
Avoid these common mistakes that cause test failures:
โ YAML Structure Issues
- Duplicate YAML keys (overwrites previous values)
- Mixing pattern types in same object
- Hard-coding entire arrays instead of using pattern matchers
โ ๏ธ Programmatic Issues
- Missing
client.clearAllBuffers()in beforeEach - Not properly disconnecting clients after tests
- Ignoring stderr buffer in validation
โ ๏ธ Project Structure Issues
- Creating tests outside
test*/mcp/conventions - Inventing alternative folder structures
- Regenerating duplicate files instead of updating existing
๐ Additional Resources
๐ฏ Primary Resources (Start Here)
test/mcp/AGENTS.md- Main overview guidetest/mcp/yaml/AGENTS.md- YAML testing guidetest/mcp/node/AGENTS.md- Programmatic guide
โก Generated locally by npx mcp-aegis init
๐ Online Documentation
โ Success Criteria for AI Agents
Your AI agent implementation is successful when it generates tests following the AGENTS.md guides and produces these outcomes:
๐ฏ Core Test Coverage
- โ MCP handshake validation
- โ Tools discovery (tools/list)
- โ At least one tool execution
- โ Error handling and stderr validation
๐ Quality Indicators
- โ Follows AGENTS.md conventions exactly
- โ Uses pattern matching vs hard-coding
- โ Proper npm scripts included
- โ Clear, maintainable test descriptions
๐ง AI Agent Best Practices
- ๐ Always reference the copied AGENTS.md files as primary documentation
- ๐ฏ Use the provided prompt templates as starting points
- ๐ Follow the 5-step workflow for consistent results
- โ ๏ธ Avoid the documented anti-patterns to prevent common failures
- โ Validate generated tests run successfully before completion
๐ Ready to Generate MCP Tests?
Use the AGENTS.md guides and prompt templates above to generate consistent, high-quality MCP server tests.