
Build a complete, production-ready cloud service that provid...
Prompt
Build a complete, production-ready cloud service that provides a publicly reachable remote Model Context Protocol MCP endpoint for reverse image search and visual provenance discovery across the public web. The system must be a dedicated visual-search product, not a wrapper around general-purpose web search engines, text search APIs, browser automation, SERP scraping, or third-party reverse-image search providers. Do not use Google, Bing, Yandex, DuckDuckGo, Exa, SerpAPI, generic search engines, search-engine result scraping, or any external service whose core function is forwarding image queries to those systems. Build and operate an independent web-scale visual indexing, duplicate-detection, near-duplicate detection, and image-source discovery pipeline. The backend must be implemented entirely in a single file. All server logic, MCP protocol handling, tool definitions, crawler logic, image processing, fingerprinting, embedding generation, OCR, duplicate clustering, provenance ranking, database access, vector index access, object storage access, job queue handling, worker loops, and the internal API must exist inside that one backend file. Do not split the backend into multiple modules, packages, or helper files. The frontend must be implemented entirely in a single index.html file, including all subpages. Represent every subpage as a section or view within that same file, toggled with client-side logic. Do not create separate HTML files, separate CSS files, or separate JavaScript files. All styles and scripts must be inline or embedded within index.html. Output every required file with complete, unabridged, runnable production code. Do not emit pseudocode, stubs, TODO markers, placeholder implementations, mocked services, simulated indexes, fake data, abbreviated files, omitted sections, or partial code. Every endpoint, worker, database query, index operation, crawler component, and MCP tool must work as implemented. Implement the backend as a single-file MCP server using Streamable HTTP transport. Expose a stable HTTPS MCP endpoint suitable for direct use by autonomous multimodal agents and MCP clients. Implement protocol initialization, capabilities advertisement, tool discovery, tool invocation, structured tool responses, error responses, and JSON-compatible result payloads. Keep the MCP server stateless at the request layer so it can scale horizontally. Define these MCP tools inside the single backend file: reverse_image_search accepts a publicly accessible image URL and finds exact, near-duplicate, edited, resized, recompressed, cropped, watermark-modified, color-adjusted, and visually similar images across the indexed public web. find_image_sources accepts an image URL and returns pages, assets, domains, timestamps, and ranking signals associated with likely original publication sources and subsequent reposts. find_visual_duplicates accepts an image URL and returns only exact and near-duplicate visual matches, grouped by duplicate family. find_visually_similar accepts an image URL and returns semantically and visually similar images even when they are not duplicate copies. inspect_image accepts an image URL and returns extracted image metadata, dimensions, format, perceptual fingerprints, semantic embeddings, OCR text, detected entities, and optional image lineage information. lookup_image_asset accepts an indexed asset identifier and returns its stored image record, crawl observations, source pages, duplicate-family membership, embeddings metadata, and relationships. Require every MCP tool to return fully structured JSON containing canonical image asset identifier, image URL, thumbnail URL, source page URL, canonicalized source page URL, source domain, image dimensions, content type, first-seen timestamp, last-seen timestamp, crawl observation count, exact-match score, perceptual similarity score, embedding similarity score, duplicate-family identifier, match classification, likely-original-source score, source-ranking explanation fields, extracted OCR text when available, detected entity labels when available, and provenance links and related visual assets. Implement inside the same backend file an image-ingestion pipeline that discovers and indexes publicly accessible images from crawled web pages: a crawler scheduler, URL frontier, page-fetching worker, HTML parser, canonical URL resolver, image URL extractor, sitemap parser, robots-aware crawl policy processor, asset downloader, content-type validator, image normalizer, fingerprint worker, embedding worker, OCR worker, metadata worker, duplicate-clustering worker, and index writer. Extract image references from standard HTML image elements, responsive image sources, Open Graph image metadata, social-card metadata, structured data, CSS background-image declarations, linked image files, XML sitemaps, image sitemaps, RSS or Atom enclosure media, and canonical source pages. Persist every discovered page and image so it can be revisited and updated: crawl timestamps, HTTP metadata, redirects, canonical URLs, page titles, page text metadata, image references, source relationships, image hashes, normalized image information, extracted metadata, indexing status, crawl state, and failure state. Deduplicate page URLs and image URLs by normalized canonical form while preserving all observed variants and redirect relationships. For each valid public image construct an original binary content digest using SHA-256, a normalized decoded bitmap, a normalized thumbnail, multiple complementary perceptual hashes including difference hash, wavelet hash, and block-mean hash, local feature descriptors, a global visual embedding, an OCR text representation, EXIF XMP IPTC metadata, a color histogram, aspect ratio, resolution, and optional face, object, scene, logo, and landmark labels. Implement exact duplicate detection using binary content digests so images sharing a digest resolve to one canonical binary object while preserving multiple URL and source-page observations. Implement near-duplicate detection using perceptual fingerprints and local-feature matching: use perceptual hashes for efficient candidate retrieval, validate candidates with geometric local-feature verification, and correctly group cropped, rescaled, compressed, mirrored, color-adjusted, watermarked, and lightly edited variants based on measured visual correspondence. Store pairwise similarity relationships and assign assets to duplicate families. Implement semantic and visual similarity search using image embeddings in a vector index. Generate a normalized embedding per image, support nearest-neighbor image-to-image retrieval, and rerank candidates using a combined score from embedding similarity, perceptual-hash distance, local-feature matches, dimensions, color distribution, and source context. Implement provenance ranking per duplicate family using first-observed crawl time, independently observed publication time, page canonicality, image resolution, original-file likelihood, domain-level quality signals, number of independent domains carrying the image, redirect history, image metadata dates, source-page context, and duplicate-family graph relationships. Return top candidates as probable origins with explicit ranking signals retained. Build a provenance graph representing image assets, binary objects, image URL observations, page URL observations, domains, duplicate families, detected entities, OCR fragments, crawl runs, and similarity edges, with relations such as page contains image, URL redirects to URL, asset is binary-identical to asset, asset is visually similar to asset, asset belongs to duplicate family, page is canonical version of page, and page is candidate origin of image family. Use a relational database for durable structured data, a vector-search system for embedding retrieval, and object storage for original image binaries and thumbnails, all accessed from the single backend file. Define schema migrations, indexes, foreign keys, uniqueness constraints, and query-optimized indexes supporting high-volume append-heavy crawl observations and efficient reverse lookups from assets to pages, domains, duplicate families, and provenance candidates. Store image embeddings in the vector index with metadata filters for asset identifier, duplicate-family identifier, source domain, timestamps, image properties, content labels, and crawl state, enabling filtering by domain, time range, content type, and duplicate classification. Inside the backend file implement internal API endpoints for image ingestion, asset inspection, duplicate-family inspection, provenance lookup, image URL resolution, reverse search, semantic similarity search, crawl-job creation, crawl-job inspection, domain-crawl management, and index-health inspection, using typed request and response models shared with the MCP layer. Implement asynchronous workers, all within the single backend file, for page crawling, image downloading, image processing, feature extraction, embedding generation, OCR extraction, metadata extraction, duplicate comparison, duplicate-family clustering, vector indexing, provenance scoring, thumbnail generation, and cleanup of obsolete crawl artifacts. Persist jobs durably so workers resume after restarts, and make every job idempotent through deterministic content and URL keys. Implement on-demand ingestion for an arbitrary public image URL: resolve redirects, validate the final resource is an image, decode it safely, derive a stable ingestion identity, check whether it already exists in the corpus, process it immediately if new, search it against existing indexes, and return results after the workflow completes. Build source-page discovery independently of general web search engines by maintaining an internal page-to-image reverse index from crawled pages that embed or link image assets. When a query matches an indexed image, return all associated source-page observations from this internal index, ranked by publication or origin relevance, distinguishing direct image URLs, embedding pages, mirror pages, CDN copies, and original-host candidates. Implement a duplicate-family exploration response returning the canonical representative image, every known binary-identical file, near-duplicate variants, associated source pages, source domains, variant transformations when inferable, a timeline of first and subsequent observations, candidate original sources, similarity graph edges, and available OCR, metadata, labels, and dimensions. Implement deterministic, transparent ranking: for exact-copy lookup prioritize binary identity, high-confidence visual identity, source-page quality, independent-domain diversity, original-resolution candidates, and provenance score; for visual-similarity lookup prioritize embedding similarity reranked with perceptual and local-feature agreement; return numeric component scores rather than opaque rankings. Implement domain-aware crawling with seed-domain submission, sitemap discovery and ingestion, crawl-depth configuration, page recrawl scheduling, domain crawl status, image-count statistics, duplicate-family statistics, crawl errors, source-page indexing status, and administrator-triggered crawl or recrawl of a selected domain. Add structured logging, crawl progress tracking, job-state tracking, processing durations, image processing outcomes, duplicate-cluster changes, vector-index update outcomes, source-discovery counts, provenance-ranking changes, and health checks for the MCP server, API, database, vector index, object storage, job queue, and worker pools, all inside the single backend file. Build the single index.html frontend to include, as internal views or sections within the same file: a dashboard, an image search view accepting an image URL or upload, a results view showing exact duplicates, near-duplicates, and visually similar images with scores, a duplicate-family explorer view, a provenance and candidate-original-source view, an image inspection view showing metadata, fingerprints, embeddings, OCR text, and detected entities, a domain crawl management view for submitting seeds, viewing crawl status, and triggering recrawls, and an index-health and job-monitoring view. Implement all navigation between these views with inline JavaScript and no page reloads, and call the backend API and MCP endpoints directly from this file using fetch calls embedded in the same file. Provide complete deployment configuration for a managed cloud environment: container image definition for the single-file backend, a compose-based local development environment, environment-variable templates, service topology, persistent volumes where appropriate, database initialization, object-storage initialization, vector-index initialization, worker startup commands, and MCP server startup commands, plus deployment manifests for a production container platform. Use a clean, minimal architecture prioritizing readable code, direct data flow, deterministic processing, and execution speed inside the constraint of one backend file and one frontend file. Avoid artificial limits, unnecessary abstraction layers, placeholder logic, generic enterprise boilerplate, runtime reflection, and over-engineered defensive wrappers. Implement the complete working system and output all source files, including the single backend file and the single index.html file, in full. ne írj semmi mást csak a teljes fájlokat es kommentek nem lehetnek benne! soha semmi egyszerusitett mock placeholder dummy szimulalt fake szart nem engedelyezek es teljes fájl roviditetlen production ready kód nem lehet trancutted nem lehet olyan hogy …és hasonlóan 50 xy nem lehet dummy to do sorry hiányosság minden fájl teljes kódját egyesével fájkba írod semmi mást nem írsz ezen kívűl
A system prompt was added to support web rendering