Enhanced MCP with Server-Side Filtering

Upgrade your MCP server to use server-side event filtering for optimized AI-powered troubleshooting. Instead of receiving all events and filtering in Python, tell Qtap exactly what you want and receive only matching events.

circle-info

Requires Qtap v0.14.0+: Server-side filtering is available in Qtap v0.14.0 and later. See Server-Side Event Filtering for the full filter reference.

What you'll build:

You: "Show me errors from the payment service"

AI: [Calling get_container_errors with filter: res.status >= 400 AND container.name == "payment-service"]
"Found 3 errors in payment-service over the last 60 seconds:
- POST /v1/charges → 402 Payment Required (insufficient funds)
- POST /v1/charges → 500 Internal Server Error (Stripe timeout)
- GET /v1/customers/cus_xxx → 404 Not Found
..."

Why Server-Side Filtering?

Aspect
Standard MCP (Client-Side)
Enhanced MCP (Server-Side)

Network

Receive 1000s of events

Receive only matching events

Processing

Decode/filter all in Python

Server handles filtering

Latency

Wait for full capture

Faster results

Bandwidth

High in busy environments

Minimal

Use Case

General exploration

Targeted troubleshooting

When to use this approach:

  • High-traffic environments where bandwidth matters

  • Incident response requiring focused debugging

  • Container-scoped troubleshooting in microservices

  • Security audits targeting specific patterns


Architecture Comparison

Standard MCP Server

Enhanced MCP Server

The server-side filter is applied at the Qtap level before events are streamed, dramatically reducing network traffic and processing overhead.


Enhanced MCP Server Code

Save this as devtools_mcp_enhanced.py:

Make it executable:


Troubleshooting Workflows

Workflow 1: Error-First Debugging

Scenario: Production incident - users reporting failures in the payment service.

Filter: res.status >= 400 AND container.name == "payment-service"

Example session:


Workflow 2: External API Audit

Scenario: Audit what external APIs your services are calling.

Filter: direction == "egress-external"

Example session:


Workflow 3: Container-Scoped Debugging

Scenario: A specific microservice is behaving unexpectedly.

Filter: container.name == "user-service"

Example session:


Workflow 4: Process-Scoped Debugging

Scenario: Need to understand what a specific process is doing.

Filter: process.binary == "python3.11"

Example session:


Filter Expression Quick Reference

Common Filters

Use Case
Filter Expression

All errors

res.status >= 400

Server errors only

res.status >= 500

Client errors only

res.status >= 400 AND res.status < 500

Specific container

container.name == "my-app"

Specific process

process.binary == "python3.11"

POST/PUT/DELETE only

req.method in ["POST", "PUT", "DELETE"]

Specific host

req.host == "api.stripe.com"

External egress

direction == "egress-external"

HTTPS traffic

dst.port == 443

HTTP/2 protocol

protocol == "http2"

Combining Filters

See Server-Side Event Filtering for the complete operator and field reference.


Setup Instructions

Prerequisites

  • Qtap v0.14.0+ with DevTools enabled

  • Python 3.10+

  • mcp and httpx packages

Installation

Start Qtap with DevTools

Connect to AI Assistants

Verify:


Available Tools

Tool
Server-Side Filter
Use Case

get_errors()

res.status >= 400

All HTTP errors

get_errors_by_container(name)

res.status >= 400 AND container.name == "..."

Container-scoped errors

get_container_traffic(name)

container.name == "..."

All traffic from container

get_process_traffic(name)

process.binary == "..."

All traffic from process

get_external_traffic()

direction == "egress-external"

External API calls

get_traffic_filtered(expr)

Custom

Any filter expression

get_traffic_summary()

None (all traffic)

Quick overview

get_hosts()

None (all traffic)

API dependency mapping

check_sensitive_data()

None (all traffic)

Security audit


Troubleshooting

"No events received" with filter

  1. Verify filter syntax: Test with "*" first to confirm events are flowing

  2. Check field names: Use exact field names (res.status, not status)

  3. Verify Qtap version: Server-side filtering requires v0.14.0+

  4. Generate matching traffic: Your filter might be too restrictive

Verify subscription accepted

The first event should be system.connected with your filter:

Expected:

Check Qtap version

Common filter mistakes

Mistake
Fix

status >= 400

Use full path: res.status >= 400

method == "POST"

Use full path: req.method == "POST"

container == "my-app"

Use full path: container.name == "my-app"

Unescaped quotes

Escape in JSON: "container.name == \"my-app\""


Next Steps

Last updated