MCP Server Integration
TrendGate's Model Context Protocol (MCP) server enables AI agents and automation tools to interact with quality data programmatically.
🤖 What is MCP?
The Model Context Protocol provides:
- Standardized tool interface for AI agents
- Programmatic access to TrendGate data
- Automated quality analysis capabilities
- Integration with AI-powered development tools
🚀 Setup
Installation
# Install the MCP server
npm install -g @trendgate/mcp-server
# Or use npx
npx @trendgate/mcp-server
Configuration
{
"mcpServers": {
"trendgate": {
"command": "npx",
"args": ["@trendgate/mcp-server"],
"env": {
"TRENDGATE_API_KEY": "tg_live_xxxxx",
"TRENDGATE_API_URL": "https://api.trendgate.ai"
}
}
}
}
📚 Available Tools
query_test_trends
Analyze test trends for specific modules or time periods:
const trends = await mcp.callTool('query_test_trends', {
module: 'src/payments',
timeRange: '30d',
metrics: ['pass_rate', 'coverage', 'duration']
});
// Response
{
"module": "src/payments",
"trends": {
"pass_rate": {
"current": 95.2,
"previous": 93.1,
"trend": "improving"
},
"coverage": {
"current": 82.5,
"previous": 80.0,
"trend": "improving"
}
}
}
evaluate_quality
Trigger quality evaluation between branches:
const evaluation = await mcp.callTool('evaluate_quality', {
sourceBranch: 'feature/new-payment',
targetBranch: 'main',
policies: ['test_pass_rate', 'coverage']
});
// Response
{
"passed": false,
"details": {
"test_pass_rate": {
"passed": true,
"source": 96.0,
"target": 95.0
},
"coverage": {
"passed": false,
"source": 78.0,
"target": 82.0,
"message": "Coverage decreased by 4%"
}
}
}
generate_report
Create formatted quality reports:
const report = await mcp.callTool('generate_report', {
project: 'my-app',
format: 'markdown',
sections: ['summary', 'trends', 'recommendations'],
timeRange: '7d'
});
// Response
{
"report": "# Quality Report\n\n## Summary\n...",
"format": "markdown",
"generated_at": "2024-01-20T10:30:00Z"
}
identify_flaky_tests
Find and analyze flaky tests:
const flakyTests = await mcp.callTool('identify_flaky_tests', {
project: 'my-app',
threshold: 20, // Flakiness score threshold
limit: 10
});
// Response
{
"flaky_tests": [
{
"test": "UserService.login timeout handling",
"flakiness_score": 67,
"failure_rate": "15%",
"pattern": "timeout_related"
}
]
}
🎯 Use Cases
1. Automated PR Analysis
// AI agent analyzing a PR
const analysis = await mcp.callTool('evaluate_quality', {
sourceBranch: `pr-${prNumber}`,
targetBranch: 'main'
});
if (!analysis.passed) {
const report = await mcp.callTool('generate_report', {
branch: `pr-${prNumber}`,
format: 'markdown',
sections: ['failures', 'recommendations']
});
// Post comment on PR
await github.createComment(prNumber, report.report);
}
2. Quality Monitoring Bot
// Daily quality check
const trends = await mcp.callTool('query_test_trends', {
timeRange: '24h',
metrics: ['pass_rate', 'new_failures']
});
if (trends.new_failures.count > 0) {
// Alert team
await slack.postMessage({
channel: '#quality-alerts',
text: `⚠️ ${trends.new_failures.count} new test failures detected`
});
}
3. Sprint Quality Summary
// Generate sprint report
const report = await mcp.callTool('generate_report', {
timeRange: '14d', // Sprint duration
format: 'html',
sections: ['summary', 'achievements', 'issues', 'trends'],
includeCharts: true
});
// Email to stakeholders
await email.send({
to: stakeholders,
subject: 'Sprint Quality Report',
html: report.report
});
🔧 Advanced Configuration
Custom Tool Parameters
// Configure tool behavior
const mcp = new MCPClient({
tools: {
query_test_trends: {
defaultTimeRange: '7d',
cacheResults: true,
cacheTTL: 300 // 5 minutes
},
generate_report: {
defaultFormat: 'markdown',
maxSections: 10
}
}
});
Error Handling
try {
const result = await mcp.callTool('evaluate_quality', params);
} catch (error) {
if (error.code === 'INVALID_BRANCH') {
console.error('Branch not found:', error.branch);
} else if (error.code === 'RATE_LIMITED') {
await sleep(error.retryAfter);
// Retry
}
}
🛡️ Security
Authentication
- API key required for all operations
- Scoped permissions per key
- Audit logging of all tool calls
Rate Limiting
- 100 tool calls per minute
- 1000 tool calls per hour
- Configurable per API key
🚀 Integration Examples
With GitHub Copilot
// In .github/copilot/mcp-config.json
{
"servers": {
"trendgate": {
"command": "@trendgate/mcp-server",
"description": "Query test quality and trends"
}
}
}
With Custom AI Agents
from langchain.tools import MCPTool
trendgate_tool = MCPTool(
name="trendgate",
server_command="@trendgate/mcp-server",
description="Analyze test quality and trends"
)
agent = Agent(tools=[trendgate_tool])
result = agent.run("What's the test coverage trend for the payments module?")
Start automating your quality monitoring with MCP today!