File size: 12,056 Bytes
c3de917 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
# π API Reference
Complete API documentation for all 8 MissionControlMCP tools.
---
## 1. PDF Reader
### `read_pdf(file_path: str) -> Dict[str, Any]`
Extract text and metadata from PDF files.
**Parameters:**
- `file_path` (str): Absolute path to PDF file
**Returns:**
```python
{
"text": str, # Full text content from all pages
"pages": int, # Number of pages
"metadata": { # Document metadata
"author": str,
"creator": str,
"producer": str,
"subject": str,
"title": str,
"creation_date": str,
"modification_date": str
}
}
```
**Example:**
```python
from tools.pdf_reader import read_pdf
result = read_pdf("C:/docs/report.pdf")
print(f"Pages: {result['pages']}")
print(f"Author: {result['metadata']['author']}")
print(result['text'][:500]) # First 500 chars
```
**Errors:**
- `FileNotFoundError`: PDF file not found
- `ImportError`: PyPDF2 not installed
- `Exception`: Invalid or corrupted PDF
---
### `get_pdf_info(file_path: str) -> Dict[str, Any]`
Get basic PDF information without extracting text.
**Parameters:**
- `file_path` (str): Path to PDF file
**Returns:**
```python
{
"page_count": int,
"is_encrypted": bool,
"file_size_bytes": int,
"file_name": str
}
```
---
## 2. Text Extractor
### `extract_text(text: str, operation: str, **kwargs) -> Dict[str, Any]`
Process and extract information from text.
**Parameters:**
- `text` (str): Input text to process
- `operation` (str): Operation type
- `"clean"` - Remove extra whitespace
- `"summarize"` - Create summary
- `"chunk"` - Split into chunks
- `"keywords"` - Extract keywords
- `**kwargs`: Operation-specific parameters
**Operation: clean**
```python
extract_text(text, operation="clean")
# Returns: {"result": str, "word_count": int}
```
**Operation: summarize**
```python
extract_text(text, operation="summarize", max_length=500)
# max_length: Maximum summary length (default: 500)
# Returns: {"result": str, "word_count": int, "original_length": int}
```
**Operation: chunk**
```python
extract_text(text, operation="chunk", chunk_size=100, overlap=20)
# chunk_size: Characters per chunk (default: 100)
# overlap: Overlapping characters (default: 20)
# Returns: {"chunks": List[str], "chunk_count": int}
```
**Operation: keywords**
```python
extract_text(text, operation="keywords", top_n=10)
# top_n: Number of keywords (default: 10)
# Returns: {"result": str, "keywords": List[str]}
```
**Example:**
```python
from tools.text_extractor import extract_text
# Get keywords
result = extract_text("Your text here...", operation="keywords")
print(result['result']) # "keyword1, keyword2, keyword3"
# Summarize
summary = extract_text("Long text...", operation="summarize", max_length=200)
print(summary['result'])
```
---
## 3. Web Fetcher
### `fetch_web_content(url: str, timeout: int = 30) -> Dict[str, Any]`
Fetch and parse web page content.
**Parameters:**
- `url` (str): Website URL
- `timeout` (int): Request timeout in seconds (default: 30)
**Returns:**
```python
{
"url": str,
"title": str,
"content": str, # Clean text content
"html": str, # Raw HTML
"links": List[str], # All URLs found
"status_code": int, # HTTP status
"timestamp": str
}
```
**Example:**
```python
from tools.web_fetcher import fetch_web_content
result = fetch_web_content("https://example.com")
print(f"Title: {result['title']}")
print(f"Content: {result['content'][:200]}")
print(f"Links found: {len(result['links'])}")
```
**Errors:**
- `requests.exceptions.Timeout`: Request timed out
- `requests.exceptions.RequestException`: Network error
- `Exception`: Invalid URL or parsing error
---
## 4. RAG Search
### `search_documents(query: str, documents: List[str], top_k: int = 3) -> Dict[str, Any]`
Semantic search using vector embeddings and FAISS.
**Parameters:**
- `query` (str): Search query
- `documents` (List[str]): List of documents to search
- `top_k` (int): Number of results to return (default: 3)
**Returns:**
```python
{
"query": str,
"total_documents": int,
"returned_results": int,
"results": [
{
"rank": int,
"document": str,
"score": float, # 0.0 to 1.0 (higher = more relevant)
"distance": float # L2 distance
}
]
}
```
**Example:**
```python
from tools.rag_search import search_documents
docs = [
"Machine learning is a subset of AI",
"Python is a programming language",
"Data science uses statistics"
]
result = search_documents("artificial intelligence", docs, top_k=2)
for item in result['results']:
print(f"Score: {item['score']:.4f} - {item['document']}")
```
**Features:**
- Semantic matching (understands meaning, not just keywords)
- Uses sentence-transformers (all-MiniLM-L6-v2)
- FAISS for fast vector search
---
### `multi_query_search(queries: List[str], documents: List[str], top_k: int = 3) -> Dict[str, Any]`
Search multiple queries at once.
**Returns:**
```python
{
"queries": List[str],
"results": {
"query1": [results],
"query2": [results]
}
}
```
---
## 5. Data Visualizer
### `visualize_data(data: str, chart_type: str, x_column: str = None, y_column: str = None, title: str = "Data Visualization") -> Dict[str, Any]`
Create charts from CSV or JSON data.
**Parameters:**
- `data` (str): CSV or JSON string
- `chart_type` (str): Chart type
- `"bar"` - Bar chart
- `"line"` - Line chart
- `"pie"` - Pie chart
- `"scatter"` - Scatter plot
- `x_column` (str): X-axis column name
- `y_column` (str): Y-axis column name
- `title` (str): Chart title
**Returns:**
```python
{
"image_base64": str, # Base64-encoded PNG image
"dimensions": {
"width": int,
"height": int
},
"chart_type": str,
"title": str,
"columns_used": {
"x": str,
"y": str
}
}
```
**Example:**
```python
from tools.data_visualizer import visualize_data
import base64
csv_data = """month,revenue
Jan,5000000
Feb,5200000
Mar,5400000"""
result = visualize_data(
data=csv_data,
chart_type="line",
x_column="month",
y_column="revenue",
title="Revenue Trends"
)
# Save chart
with open("chart.png", "wb") as f:
f.write(base64.b64decode(result['image_base64']))
```
---
## 6. File Converter
### `convert_file(input_path: str, output_path: str, conversion_type: str) -> Dict[str, Any]`
Convert between PDF, TXT, and CSV formats.
**Parameters:**
- `input_path` (str): Input file path
- `output_path` (str): Output file path
- `conversion_type` (str): Conversion type
- `"pdf_to_txt"` - PDF β Text
- `"txt_to_pdf"` - Text β PDF
- `"csv_to_txt"` - CSV β Text
- `"txt_to_csv"` - Text β CSV
**Returns:**
```python
{
"success": bool,
"input_file": str,
"output_file": str,
"conversion_type": str,
"file_size_bytes": int
}
```
**Example:**
```python
from tools.file_converter import convert_file
result = convert_file(
input_path="document.pdf",
output_path="document.txt",
conversion_type="pdf_to_txt"
)
print(f"Converted: {result['success']}")
print(f"Output: {result['output_file']}")
```
---
## 7. Email Intent Classifier
### `classify_email_intent(email_text: str) -> Dict[str, Any]`
Classify email intent using NLP pattern matching.
**Parameters:**
- `email_text` (str): Email content (subject + body)
**Returns:**
```python
{
"intent": str, # Primary intent
"confidence": float, # 0.0 to 1.0
"secondary_intents": [
{
"intent": str,
"confidence": float
}
],
"explanation": str
}
```
**Intent Types:**
- `complaint` - Customer complaints
- `inquiry` - Information requests
- `request` - Action requests
- `feedback` - Suggestions/reviews
- `order` - Purchase-related
- `meeting` - Meeting scheduling
- `urgent` - High priority issues
- `application` - Job applications
- `sales` - Sales pitches
- `other` - Unclassified
**Example:**
```python
from tools.email_intent_classifier import classify_email_intent
email = """
Subject: Order Issue
My order #12345 hasn't arrived yet. Can you help?
"""
result = classify_email_intent(email)
print(f"Intent: {result['intent']}") # "complaint"
print(f"Confidence: {result['confidence']}") # 0.85
```
---
### `classify_batch(emails: List[str]) -> Dict[str, Any]`
Classify multiple emails at once.
**Returns:**
```python
{
"results": [
{"email_index": int, "intent": str, "confidence": float},
...
],
"total_processed": int
}
```
---
## 8. KPI Generator
### `generate_kpis(data: str, metrics: List[str] = None) -> Dict[str, Any]`
Calculate business KPIs from financial data.
**Parameters:**
- `data` (str): JSON string with business data
- `metrics` (List[str]): Metric categories (optional)
- `"revenue"` - Revenue-related KPIs
- `"growth"` - Growth rates
- `"efficiency"` - Efficiency metrics
- `"customer"` - Customer metrics
- `"operational"` - Operational metrics
**Input Data Format:**
```json
{
"revenue": 5000000,
"costs": 3000000,
"customers": 2500,
"current_revenue": 5000000,
"previous_revenue": 4500000,
"current_customers": 2500,
"previous_customers": 2300,
"employees": 50,
"marketing_spend": 500000,
"sales": 5000000,
"cogs": 2000000
}
```
**Returns:**
```python
{
"kpis": {
"total_revenue": float,
"profit": float,
"profit_margin_percent": float,
"revenue_growth": float,
"revenue_per_customer": float,
"revenue_per_employee": float,
"customer_growth_rate": float,
...
},
"summary": str, # Executive summary
"trends": List[str], # Identified trends
"metrics_analyzed": List[str],
"data_points": int
}
```
**Example:**
```python
from tools.kpi_generator import generate_kpis
import json
data = {
"revenue": 5000000,
"costs": 3000000,
"customers": 2500,
"employees": 50
}
result = generate_kpis(json.dumps(data), metrics=["revenue", "efficiency"])
print(f"Profit: ${result['kpis']['profit']:,.0f}")
print(f"Margin: {result['kpis']['profit_margin_percent']:.1f}%")
print(f"\nSummary: {result['summary']}")
```
---
## Error Handling
All tools follow consistent error handling:
```python
try:
result = tool_function(params)
except FileNotFoundError as e:
print(f"File not found: {e}")
except ValueError as e:
print(f"Invalid input: {e}")
except ImportError as e:
print(f"Missing dependency: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
```
---
## Type Hints
All functions use Python type hints:
```python
from typing import Dict, Any, List
def function_name(param: str) -> Dict[str, Any]:
...
```
---
## Logging
All tools use Python logging:
```python
import logging
logger = logging.getLogger(__name__)
logger.info("Operation completed")
logger.warning("Warning message")
logger.error("Error occurred")
```
---
## Dependencies
See `requirements.txt` for all dependencies:
```txt
mcp>=1.0.0
pypdf2>=3.0.0
requests>=2.31.0
beautifulsoup4>=4.12.0
pandas>=2.0.0
numpy>=1.24.0
matplotlib>=3.7.0
seaborn>=0.12.0
scikit-learn>=1.3.0
nltk>=3.8.0
pydantic>=2.0.0
faiss-cpu>=1.7.4
sentence-transformers>=2.2.0
```
---
## MCP Integration
All tools are registered in `mcp_server.py`:
```python
server.register_tool(
name="pdf_reader",
description="Extract text and metadata from PDF files",
input_schema={
"type": "object",
"properties": {
"file_path": {"type": "string"}
},
"required": ["file_path"]
}
)
```
---
## Version Information
- **API Version:** 1.0.0
- **Python:** 3.8+
- **MCP Protocol:** 1.0.0
---
## Support
For issues or questions:
- GitHub: AlBaraa-1/CleanEye-Hackathon
- Documentation: README.md
- Examples: EXAMPLES.md
- Testing: TESTING.md
**Complete API reference for MissionControlMCP!** π
|