Skip to content

MCP Server Guide

Model Context Protocol Integration

NetIntel-OCR supports the Model Context Protocol (MCP) for seamless integration with AI assistants and LLM applications.

Starting MCP Server

Basic Setup

# Start MCP server
netintel-ocr server mcp

# With custom configuration
netintel-ocr server mcp --mcp-port 3000

Configuration File

{
  "mcp": {
    "enabled": true,
    "port": 3000,
    "tools": [
      "process_document",
      "search_diagrams",
      "extract_components"
    ],
    "auth": {
      "type": "bearer",
      "token": "mcp-secret-token"
    }
  }
}

Available Tools

process_document

Process PDF documents and extract network/flow diagrams.

{
  "tool": "process_document",
  "parameters": {
    "file_path": "/path/to/document.pdf",
    "start_page": 1,
    "end_page": 10,
    "model": "qwen2.5vl:7b"
  }
}

search_diagrams

Search for specific network components or patterns.

{
  "tool": "search_diagrams", 
  "parameters": {
    "query": "firewall DMZ configuration",
    "limit": 5,
    "filters": {
      "type": "network_diagram"
    }
  }
}

extract_components

Extract specific components from diagrams.

{
  "tool": "extract_components",
  "parameters": {
    "image_path": "/path/to/diagram.png",
    "component_types": ["firewall", "router", "switch"]
  }
}

Claude Desktop Integration

Configuration

Add to Claude Desktop config (~/.config/claude/config.json):

{
  "mcpServers": {
    "netintel-ocr": {
      "command": "netintel-ocr",
      "args": ["--mcp"],
      "env": {
        "OLLAMA_HOST": "http://localhost:11434"
      }
    }
  }
}

Usage in Claude

User: Process the network architecture document and find all firewall configurations.

Claude: I'll process the document using NetIntel-OCR to extract network diagrams and identify firewall configurations.

[Uses process_document tool]
[Uses search_diagrams tool with "firewall" query]

I found 3 network diagrams containing firewall configurations:
1. Page 5: DMZ architecture with dual firewalls
2. Page 12: Internal segmentation firewall
3. Page 18: Cloud gateway firewall setup

VS Code Integration

Extension Setup

{
  "mcp.servers": [
    {
      "name": "netintel-ocr",
      "command": "netintel-ocr server mcp",
      "env": {
        "OLLAMA_HOST": "http://localhost:11434"
      }
    }
  ]
}

Commands

  • MCP: Process Current File - Process open PDF
  • MCP: Search Diagrams - Search across processed documents
  • MCP: Extract Components - Extract from selected image

Programmatic Usage

Python MCP Client

from mcp_client import MCPClient

# Connect to MCP server
client = MCPClient("localhost:3000")

# Use tools
result = await client.call_tool(
    "process_document",
    {
        "file_path": "network.pdf",
        "model": "qwen2.5vl:7b"
    }
)

# Get network diagrams
diagrams = result['diagrams']
for diagram in diagrams:
    print(f"Page {diagram['page']}: {diagram['type']}")
    print(diagram['mermaid'])

Node.js MCP Client

const { MCPClient } = require('@modelcontextprotocol/client');

const client = new MCPClient({
  url: 'http://localhost:3000'
});

// Process document
const result = await client.callTool('process_document', {
  file_path: 'network.pdf'
});

console.log(`Found ${result.diagrams.length} diagrams`);

Tool Responses

Structured Output

All tools return structured JSON responses:

{
  "success": true,
  "data": {
    "diagrams": [
      {
        "page": 5,
        "type": "network_topology",
        "confidence": 0.95,
        "mermaid": "graph TB...",
        "components": [...],
        "context": {
          "summary": "DMZ network architecture",
          "security_zones": ["DMZ", "Internal", "External"]
        }
      }
    ],
    "processing_time": 12.5
  }
}

Error Handling

{
  "success": false,
  "error": {
    "code": "MODEL_NOT_FOUND",
    "message": "Model 'unknown' not available",
    "suggestions": ["qwen2.5vl:7b", "llava:13b"]
  }
}

Advanced Features

Streaming Responses

# Enable streaming for large documents
async for chunk in client.stream_tool(
    "process_document",
    {"file_path": "large.pdf", "stream": True}
):
    print(f"Processing page {chunk['page']}")

Context Management

# Maintain context across calls
context = client.create_context()

# First call
await context.call_tool("process_document", {...})

# Subsequent call uses previous context
await context.call_tool("search_diagrams", {
    "query": "related to previous document"
})

Custom Tools

Register custom tools for specific workflows:

@mcp_server.register_tool
def analyze_security(params):
    """Analyze security aspects of network diagrams."""
    return {
        "vulnerabilities": [...],
        "recommendations": [...],
        "risk_score": 7.5
    }

All-in-One Mode

Start with all services:

# MCP + API + Vector Store
netintel-ocr server all

# Services available:
# - MCP Server: port 3000
# - REST API: port 8000
# - Milvus: port 19530

Security

Authentication

# Token authentication
netintel-ocr server mcp --mcp-token YOUR_SECRET_TOKEN

# mTLS authentication
netintel-ocr server mcp \
  --mcp-cert server.crt \
  --mcp-key server.key \
  --mcp-ca ca.crt

Access Control

{
  "mcp": {
    "acl": {
      "process_document": ["admin", "user"],
      "search_diagrams": ["admin", "user", "readonly"],
      "extract_components": ["admin"]
    }
  }
}

Monitoring

Metrics

GET http://localhost:3000/metrics

mcp_requests_total{tool="process_document"} 156
mcp_request_duration_seconds{tool="process_document",quantile="0.99"} 12.5
mcp_active_connections 3

Logging

# Enable debug logging
netintel-ocr server mcp --mcp-log-level DEBUG

# Log format
2024-01-15 10:30:45 [MCP] Tool called: process_document
2024-01-15 10:30:57 [MCP] Response sent: success=true, time=12.5s

Next Steps