techlib_mcpserver/AGENTS.md

56 KiB

TechDoc Library MCP Server v1 — Codex Prompt Pack

This file contains one standalone prompt per Step.
Use them sequentially in Codex: Step 0.1, then Step 0.2, then Step 0.3, and so on.

Global project context for all steps:

  • Project: MCP server "Библиотека технической документации"
  • Target OS: Linux
  • Language: Python 3.12+
  • Database: PostgreSQL 15+
  • Architecture:
    • MCP Facade
    • Processing Orchestrator
    • Document Library Engine
    • Provider Layer
  • v1 rules:
    • document extraction providers are optional and disabled by default
    • metadata enrichment providers are optional and disabled by default
    • supplied enriched metadata may be passed during ingestion
    • provider payloads are treated as opaque by the core system
    • providers must not write directly to the library database
    • Document Library Engine is the only component that persists state
    • version-aware retrieval is required in v1
  • Python stack:
    • FastAPI
    • SQLAlchemy 2.x
    • Alembic
    • Pydantic v2
    • psycopg
    • pytest
  • Testing rule:
    • tests must fail hard if they attempt to connect to a non-test PostgreSQL database
    • test DB naming convention: test_ + main DB name
    • test env vars must be prefixed with TEST_
  • Commit rule:
    • each Step must be implemented as a separate commit
  • Response rule for Codex in every step:
    • show changed files
    • summarize what was implemented
    • mention any assumptions
    • run relevant tests when possible

Step 0.1 — Initialize repository and Python project

Implement Step 0.1 for the project “TechDoc Library MCP Server v1”.

Goal:
Initialize the repository and Python project skeleton for a Linux-hosted MCP server.

Architecture context:
- MCP Facade
- Processing Orchestrator
- Document Library Engine
- Provider Layer

Tech stack constraints:
- Linux
- Python 3.12+
- PostgreSQL 15+
- pyproject-based project layout

Tasks:
1. Create the initial repository skeleton.
2. Add `pyproject.toml` with reasonable baseline dependencies and project metadata.
3. Create the top-level package structure under `src/techlib_mcpserver/`.
4. Create the following directories and placeholder modules where appropriate:
   - `app/`
   - `mcp_facade/`
   - `orchestrator/`
   - `engine/`
   - `providers/`
   - `persistence/`
   - `search/`
   - `files/`
   - `contracts/`
   - `utils/`
5. Create top-level files:
   - `README.md`
   - `.env.example`
   - `.env.test.example`
6. Add a minimal package entrypoint so imports work.
7. Keep implementation intentionally minimal but clean.

Constraints:
- Do not implement business logic yet.
- Do not implement DB models yet.
- Do not add provider-specific logic yet.
- Keep structure future-ready for the target architecture.

Definition of done:
- The project installs as a Python package.
- Imports from `techlib_mcpserver` work.
- The repository has a clear initial structure aligned with the architecture.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `chore: initialize project skeleton for techdoc library server`

Step 0.2 — Add configuration and runtime model

Implement Step 0.2 for the project “TechDoc Library MCP Server v1”.

Goal:
Add centralized application configuration for the Linux/Python/PostgreSQL runtime.

Context:
The repository skeleton already exists. Extend it without restructuring it unnecessarily.

Tasks:
1. Create centralized configuration in `src/techlib_mcpserver/app/config.py`.
2. Use Pydantic v2 / pydantic-settings for configuration management.
3. Add configuration sections for at least:
   - application environment
   - bind host / port
   - PostgreSQL connection settings
   - object storage path / local document storage path
   - search backend settings
   - provider layer flags
   - document extraction provider config stubs
   - metadata enrichment provider config stubs
4. Ensure optional provider layers are disabled by default.
5. Make `.env.example` and `.env.test.example` match the configuration model.
6. Add clear separation between runtime settings and test settings.
7. Keep configuration names explicit and future-proof.

Important constraints:
- `TEST_` prefixed variables must be reserved for tests.
- Do not implement DB connectivity yet.
- Do not implement provider execution yet.
- Keep the config compatible with Linux deployment and systemd usage.

Definition of done:
- App configuration loads from environment variables.
- Default values are sensible for local Linux development.
- Provider layers are configurable but off by default.
- Test env examples exist and align with future pytest usage.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add centralized application configuration`

Step 0.3 — Add logging and app bootstrap

Implement Step 0.3 for the project “TechDoc Library MCP Server v1”.

Goal:
Add application bootstrap and structured logging.

Context:
The project skeleton and centralized config already exist.

Tasks:
1. Implement structured logging setup.
2. Add application bootstrap code under `src/techlib_mcpserver/app/`.
3. Create a minimal runtime entrypoint in `src/techlib_mcpserver/app/main.py`.
4. Add a lightweight application object or startup scaffold suitable for future FastAPI/MCP integration.
5. Add startup/shutdown hooks or clear placeholders for them.
6. Add a simple health endpoint or equivalent stub if appropriate.
7. Ensure bootstrap uses centralized configuration.

Constraints:
- Do not implement MCP tools yet.
- Do not implement DB operations yet.
- Do not add business workflows yet.
- Logging should be structured and production-friendly for Linux service execution.

Definition of done:
- The app starts successfully.
- Configuration is wired into runtime startup.
- Logging is initialized in a consistent way.
- The bootstrap is ready for later MCP facade integration.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add application bootstrap and structured logging`

Step 0.4 — Add PostgreSQL connectivity baseline

Implement Step 0.4 for the project “TechDoc Library MCP Server v1”.

Goal:
Add PostgreSQL connectivity baseline using SQLAlchemy 2.x.

Context:
Project skeleton, config, and runtime bootstrap already exist.

Tasks:
1. Add DB connectivity module(s) under `src/techlib_mcpserver/persistence/`.
2. Configure SQLAlchemy engine/session management for PostgreSQL.
3. Use psycopg-compatible SQLAlchemy integration.
4. Add startup-safe DB connectivity helpers.
5. Add clear separation between runtime DB config and future test DB config.
6. Prepare the code for later Alembic integration.
7. Add minimal validation to ensure required DB config is present.

Important safety rule:
- Prepare the codebase so tests can later fail hard if they attempt to connect to a non-test DB.
- Preserve the convention that test DB name must be `test_` + main DB name.

Constraints:
- Do not add ORM models yet.
- Do not run schema creation in application code.
- Do not implement repositories yet.

Definition of done:
- PostgreSQL connectivity is centralized and reusable.
- Session/engine lifecycle is cleanly defined.
- The persistence package is ready for models and migrations.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add postgresql connectivity and session management`

Step 0.5 — Add migration baseline

Implement Step 0.5 for the project “TechDoc Library MCP Server v1”.

Goal:
Introduce Alembic migration baseline for PostgreSQL schema management.

Context:
The project already has SQLAlchemy database connectivity.

Tasks:
1. Initialize Alembic in the repository.
2. Configure `alembic.ini` and migration environment.
3. Wire Alembic to the project’s SQLAlchemy metadata location, even if models are still minimal or incomplete.
4. Establish migration conventions and a migration-ready layout.
5. Keep the setup compatible with Linux CLI usage.
6. Make sure environment loading works consistently with project config.

Constraints:
- Do not add full schema migrations yet if the model layer is not ready.
- Do not use automatic schema creation in application startup.
- Keep the setup future-ready for PostgreSQL-backed CI and local development.

Definition of done:
- Alembic is initialized and usable.
- Migration environment is connected to the project.
- The repository is ready for initial schema migrations in later steps.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add alembic migration baseline`

Step 0.6 — Add pytest baseline and DB safety guard

Implement Step 0.6 for the project “TechDoc Library MCP Server v1”.

Goal:
Add pytest baseline and strong database safety guardrails.

Context:
Project config, PostgreSQL connectivity, and Alembic baseline already exist.

Tasks:
1. Add pytest configuration.
2. Add initial test directory structure and fixtures.
3. Add `.env.test.example` adjustments if needed.
4. Implement a guard that makes tests fail hard if they attempt to connect to a non-test PostgreSQL database.
5. Enforce the convention:
   - test DB name = `test_` + main DB name
   - test env vars are prefixed with `TEST_`
6. Add minimal smoke tests for configuration/bootstrap.
7. Document test execution expectations if needed.

Critical safety rule:
- Under no circumstances should test code be able to connect silently to the production or development main DB.
- The guard must be explicit and strict.

Constraints:
- Do not write full integration test suites yet.
- Do not depend on future ORM models yet.

Definition of done:
- pytest runs.
- There is a strict DB safety guard.
- Basic smoke tests exist.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `test: add pytest baseline and production database guard`

Step 1.1 — Implement persistence enums and statuses

Implement Step 1.1 for the project “TechDoc Library MCP Server v1”.

Goal:
Define centralized enums and status models for persistent state.

Context:
Bootstrap, PostgreSQL connectivity, migrations baseline, and pytest baseline already exist.

Tasks:
1. Add enums and status definitions under `src/techlib_mcpserver/persistence/` and/or `src/techlib_mcpserver/contracts/`.
2. Define at least:
   - ingest statuses
   - version statuses
   - search index statuses
   - document extraction statuses
   - metadata enrichment statuses
   - delete modes
3. Keep naming explicit and aligned with the architecture.
4. Make them reusable across persistence models, orchestrator, and MCP facade.
5. Avoid premature overengineering; keep the set minimal but complete for v1.

Constraints:
- Do not add DB models in this step.
- Do not implement workflows yet.
- Keep the design consistent with optional provider layers being disabled by default.

Definition of done:
- Statuses and enums are centralized.
- Future modules can import them without duplication.
- The status vocabulary matches the architecture.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add persistence enums and processing statuses`

Step 1.2 — Implement core DB models

Implement Step 1.2 for the project “TechDoc Library MCP Server v1”.

Goal:
Add the core PostgreSQL persistence models for the Document Library Engine.

Context:
Enums/statuses already exist. The target architecture is:
- MCP Facade
- Processing Orchestrator
- Document Library Engine
- Provider Layer

Tasks:
1. Implement SQLAlchemy models for at least:
   - Document
   - DocumentVersion
   - DocumentModelLink
   - SuppliedExtendedMetadata
   - SuppliedEnrichedMetadata
   - DocumentRepresentation
   - MetadataEnrichmentResult
   - SearchableRepresentation
   - AuditEvent
2. Model relationships clearly.
3. Keep provider payload fields opaque (e.g. JSON/JSONB) and do not impose domain validation.
4. Reflect the rule that Document Library Engine is the source of persisted state.
5. Include fields necessary for version-aware retrieval and processing statuses.
6. Keep the schema PostgreSQL-friendly.

Constraints:
- Do not implement repositories yet.
- Do not implement migrations in this step.
- Do not bake provider-specific assumptions into the schema.

Definition of done:
- SQLAlchemy model layer exists and matches the architecture.
- Models are ready for initial migrations.
- Opaque provider payload storage is supported.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add core document library persistence models`

Step 1.3 — Create initial migrations

Implement Step 1.3 for the project “TechDoc Library MCP Server v1”.

Goal:
Create the initial Alembic migration for the core PostgreSQL schema.

Context:
SQLAlchemy persistence models already exist.

Tasks:
1. Generate and refine the initial migration.
2. Ensure the migration creates the core schema for the Document Library Engine.
3. Add sensible indexes and constraints.
4. Add foreign keys where appropriate.
5. Add uniqueness constraints where clearly needed.
6. Keep the migration readable and maintainable.

Constraints:
- Do not add speculative tables that are not used in v1.
- Do not encode provider-domain contracts in DB constraints.
- Keep PostgreSQL compatibility explicit.

Definition of done:
- A clean initial migration exists.
- The schema can be applied to an empty PostgreSQL database.
- The migration matches the model layer.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add initial database migration for library engine`

Step 1.4 — Implement repositories

Implement Step 1.4 for the project “TechDoc Library MCP Server v1”.

Goal:
Add repository abstractions for PostgreSQL persistence access.

Context:
Core DB models and initial migrations already exist.

Tasks:
1. Implement repositories for at least:
   - documents
   - versions
   - supplied metadata
   - provider payloads
   - audit events
   - retrieval-oriented reads
2. Keep repositories aligned with the Document Library Engine role.
3. Avoid leaking raw ORM queries throughout the codebase.
4. Keep repository methods explicit and use-case-oriented.
5. Maintain clear separation between write and read responsibilities where reasonable.

Constraints:
- Do not implement higher-level business workflows yet.
- Do not put orchestration policy into repositories.
- Keep repositories persistence-focused.

Definition of done:
- Persistence access is encapsulated.
- Future Engine services can use repositories instead of raw session logic.
- Repository layout is ready for core engine services.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add repositories for document library persistence`

Step 2.1 — Implement object storage abstraction

Implement Step 2.1 for the project “TechDoc Library MCP Server v1”.

Goal:
Add object storage abstraction for original document files.

Context:
This is a Linux-first v1. Use a local filesystem backend initially, behind an abstraction.

Tasks:
1. Define an object storage interface.
2. Implement a local filesystem backend suitable for Linux deployment.
3. Support save/load/delete operations.
4. Support checksum calculation or checksum-related workflow needs.
5. Keep file path handling safe and explicit.
6. Make the abstraction future-ready for other backends.

Constraints:
- Do not hardcode storage paths outside config.
- Do not couple file storage directly to orchestration logic.
- Keep the implementation usable by the Document Library Engine.

Definition of done:
- Original files are handled through a clean abstraction.
- Linux local storage backend works.
- The code is ready for Engine integration.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add object storage abstraction and local linux backend`

Step 2.2 — Implement document persistence service

Implement Step 2.2 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement the Document Library Engine service responsible for persisting documents and versions.

Context:
Repositories and object storage abstraction already exist.

Tasks:
1. Create the engine service(s) responsible for:
   - creating/updating logical documents
   - creating document versions
   - persisting file references and checksums
   - persisting base metadata
   - persisting supplied extended metadata
   - persisting supplied enriched metadata
2. Keep all persistent effects inside the Document Library Engine.
3. Ensure the service is orchestration-friendly.
4. Keep provider payload handling opaque.

Constraints:
- Do not implement version resolution logic yet.
- Do not implement search corpus building yet.
- Do not add provider execution logic.

Definition of done:
- The Engine can persist the core ingestion state for a document.
- Supplied metadata payloads are stored correctly.
- The service boundaries are clear.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: implement document persistence service in library engine`

Step 2.3 — Implement versioning service

Implement Step 2.3 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement version resolution and latest/superseded handling in the Document Library Engine.

Context:
Document persistence service already exists.

Tasks:
1. Implement a versioning service inside the Engine.
2. Support latest/superseded resolution using fields such as:
   - document_date
   - version_label
   - revision
   - effective_from
3. Ensure version-aware state updates are persisted correctly.
4. Keep the design explicit and deterministic.
5. Treat `ingested_at` as non-primary for actual document freshness.

Constraints:
- Do not implement retrieval yet.
- Do not couple versioning to MCP-facing code.
- Avoid heuristic complexity beyond what v1 needs.

Definition of done:
- The Engine can determine and persist current version status.
- Latest version preference is represented in state.
- The logic is testable and isolated.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: implement document version resolution service`

Step 2.4 — Implement audit persistence service

Implement Step 2.4 for the project “TechDoc Library MCP Server v1”.

Goal:
Add audit persistence for write operations.

Context:
The Document Library Engine is the authoritative persistence layer and must record key write actions.

Tasks:
1. Implement audit persistence service(s).
2. Support standard audit event recording with fields like:
   - actor
   - action
   - target type
   - target id
   - timestamp
   - payload
3. Keep the API simple and reusable from the Orchestrator and Engine.
4. Ensure the design works with PostgreSQL.

Constraints:
- Do not overdesign audit querying in this step.
- Focus on writing audit events first.

Definition of done:
- Audit events can be recorded consistently.
- The service is ready to be called from ingest, delete, and reindex workflows.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: implement audit persistence service`

Step 2.5 — Implement metadata retrieval service

Implement Step 2.5 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement read-oriented metadata services in the Document Library Engine.

Context:
Core persistence and versioning already exist.

Tasks:
1. Implement Engine read services for:
   - get document metadata
   - get document versions
   - get processing status
   - list vendors
   - list document types
   - list models
2. Keep these reads independent from orchestration workflows where appropriate.
3. Make the outputs suitable for later MCP facade use.

Constraints:
- Do not implement search/retrieval yet.
- Do not implement MCP routing yet.
- Keep the services read-oriented and engine-local.

Definition of done:
- Basic metadata and status reads are supported by the Engine.
- The read APIs are stable enough for use by MCP tools later.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: implement metadata retrieval services`

Step 3.1 — Implement searchable representation builder

Implement Step 3.1 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement the search corpus / searchable representation builder inside the Document Library Engine.

Context:
The architecture requires retrieval to use all available indexable sources.

Tasks:
1. Implement logic to build:
   - `base_metadata_text`
   - `native_text_text` when available
   - `document_representation_text` when available
   - `supplied_enriched_text` when available
   - `provider_enrichment_text` when available
   - `merged_search_text`
2. Keep provider payload treatment opaque.
3. Build explicit provenance/source tags where useful.
4. Make the builder reusable for ingest and reindex flows.

Constraints:
- Do not implement embeddings yet.
- Do not implement full retrieval yet.
- Do not add provider-specific semantic parsing.

Definition of done:
- The Engine can materialize a merged searchable representation.
- The builder handles optional inputs gracefully.
- The output is ready for indexing.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: implement searchable representation builder`

Step 3.2 — Implement indexing abstraction

Implement Step 3.2 for the project “TechDoc Library MCP Server v1”.

Goal:
Add indexing abstraction for full-text and embedding-related indexing operations.

Context:
The searchable representation builder already exists.

Tasks:
1. Define an indexing abstraction with responsibilities like:
   - index searchable representation
   - reindex document version
   - delete indexed document version
   - retrieve matching items
2. Keep the abstraction backend-agnostic.
3. Add a minimal v1 stub/backend path suitable for PostgreSQL-oriented evolution.
4. Keep the indexing abstraction inside or adjacent to the Engine/search layer.

Constraints:
- Do not fully commit to a final vector backend in this step.
- Do not implement provider execution logic.
- Keep the interface explicit and testable.

Definition of done:
- Indexing is abstracted cleanly.
- The Engine has a stable seam for indexing/retrieval integration.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add indexing abstraction for library engine`

Step 3.3 — Implement embedding service abstraction

Implement Step 3.3 for the project “TechDoc Library MCP Server v1”.

Goal:
Add embedding service abstraction for future embedding search support.

Context:
The Engine needs a stable embedding seam, but v1 should not be overcommitted to a specific provider in this step.

Tasks:
1. Define an embedding adapter/service interface.
2. Define text-to-vector contract(s).
3. Add a stub/default implementation suitable for local development and testing.
4. Optionally prepare a PostgreSQL/pgvector-oriented extension seam, but do not force it.
5. Keep the design aligned with the searchable representation builder.

Constraints:
- Do not implement final retrieval ranking logic here.
- Do not hardwire the app to an external model provider.
- Keep the abstraction lightweight and explicit.

Definition of done:
- Embedding generation is abstracted.
- The codebase is ready for later vector-capable search wiring.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add embedding service abstraction`

Step 3.4 — Implement retrieval service

Implement Step 3.4 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement version-aware retrieval in the Document Library Engine.

Context:
Searchable representation, indexing abstraction, and embedding abstraction already exist.

Tasks:
1. Implement retrieval service(s) supporting:
   - metadata search
   - embedding search
   - hybrid search orchestration
2. Add version-aware result handling:
   - prefer latest version
   - collapse duplicate logical-document hits when appropriate
   - include information about other available versions
3. Include optional match context / provenance support.
4. Keep the retrieval logic inside the Engine, not the Orchestrator.

Constraints:
- Do not implement MCP facade here.
- Do not make providers mandatory.
- Avoid overcomplicated ranking logic beyond v1 needs.

Definition of done:
- The Engine exposes usable retrieval APIs.
- Retrieval honors version-awareness.
- Optional indexed sources can influence search results.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: implement version-aware retrieval service`

Step 3.5 — Implement reindex service

Implement Step 3.5 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement controlled reindex support in the Document Library Engine.

Context:
The Engine already supports searchable representation building and retrieval.

Tasks:
1. Implement service logic to:
   - rebuild searchable representation for a document version
   - refresh indexing
   - support targeted reindex per document version
2. Keep the service reusable by the Orchestrator.
3. Keep reindex logic explicit and auditable.

Constraints:
- Do not add provider rerun policies here; that belongs to the Orchestrator.
- Keep the Engine focused on persistence/index state effects.

Definition of done:
- The Engine can rebuild corpus/index state for a document version.
- The code is ready for orchestrated reindex workflows.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: implement reindex service for searchable representations`

Step 4.1 — Define provider base contracts

Implement Step 4.1 for the project “TechDoc Library MCP Server v1”.

Goal:
Define base Python contracts/interfaces for the Provider Layer.

Context:
The architecture includes two provider families:
- document extraction providers
- metadata enrichment providers

Tasks:
1. Define provider interfaces for:
   - document extraction providers
   - metadata enrichment providers
2. Define provider result envelopes.
3. Define provider status/result structures.
4. Keep payloads opaque from the perspective of the core system.
5. Make the interfaces suitable for both internal modules and external adapters.

Constraints:
- Do not implement registry yet.
- Do not implement provider execution yet.
- Do not impose domain schemas on provider payloads.

Definition of done:
- Provider contracts are explicit and reusable.
- Future adapters can implement them cleanly.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: define provider interfaces for extraction and enrichment`

Step 4.2 — Implement provider registry

Implement Step 4.2 for the project “TechDoc Library MCP Server v1”.

Goal:
Add a provider registry and configuration-driven provider resolution.

Context:
Base provider contracts already exist.

Tasks:
1. Implement provider registration and lookup.
2. Support registration by provider type and provider name.
3. Bind provider availability to application configuration.
4. Support enable/disable behavior for provider layers.
5. Keep the registry usable by the Processing Orchestrator.

Constraints:
- Do not execute providers yet.
- Do not hardcode specific external endpoints beyond config-driven patterns.

Definition of done:
- Providers can be discovered/resolved by the Orchestrator.
- Optional layers remain disabled by default.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: implement provider registry and configuration binding`

Step 4.3 — Implement HTTP extraction provider adapter

Implement Step 4.3 for the project “TechDoc Library MCP Server v1”.

Goal:
Add an external HTTP adapter for document extraction providers.

Context:
Provider contracts and registry already exist.

Tasks:
1. Implement an HTTP-based document extraction provider adapter.
2. Use explicit request/response handling.
3. Treat returned provider payload as opaque.
4. Add timeout and error mapping behavior.
5. Keep the adapter compatible with Linux/Python runtime and configuration-driven endpoint setup.

Constraints:
- Do not impose semantic validation on provider payload.
- Do not persist provider results directly here.
- Do not bypass the Orchestrator and Engine.

Definition of done:
- The codebase can call an external document extraction service through a provider adapter.
- Failures are surfaced cleanly.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add external http adapter for document extraction providers`

Step 4.4 — Implement HTTP enrichment provider adapter

Implement Step 4.4 for the project “TechDoc Library MCP Server v1”.

Goal:
Add an external HTTP adapter for metadata enrichment providers.

Context:
Provider contracts and registry already exist.

Tasks:
1. Implement an HTTP-based metadata enrichment provider adapter.
2. Use explicit request/response handling.
3. Treat returned provider payload as opaque.
4. Add timeout and error mapping behavior.
5. Keep the adapter configuration-driven.

Constraints:
- Do not validate provider payload semantically.
- Do not persist provider results directly here.
- Do not bypass the Orchestrator and Engine.

Definition of done:
- The codebase can call an external metadata enrichment service through a provider adapter.
- The adapter is reusable and explicit.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add external http adapter for metadata enrichment providers`

Step 4.5 — Implement payload-to-search adapters

Implement Step 4.5 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement adapters that turn opaque provider payloads into searchable text representations.

Context:
Provider payloads are intentionally not domain-validated by the core system, but their results must still be usable in retrieval.

Tasks:
1. Implement adapter(s) for:
   - document extraction payload -> document representation text
   - metadata enrichment payload -> provider enrichment text
2. Keep logic robust against incomplete or irregular opaque payloads.
3. Add safe fallback behavior.
4. Preserve basic provenance/source tagging where useful.
5. Keep these adapters independent from provider transport details.

Constraints:
- Do not add semantic/domain validation.
- Do not make assumptions that only work for one provider.
- Keep the output suitable for the searchable representation builder.

Definition of done:
- Provider payloads can be transformed into indexable text.
- The Engine can use provider outputs in retrieval without owning provider-domain contracts.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add adapters from provider payloads to searchable text`

Step 5.1 — Implement orchestrator command models

Implement Step 5.1 for the project “TechDoc Library MCP Server v1”.

Goal:
Add internal command models for the Processing Orchestrator.

Context:
The Orchestrator coordinates workflows but should not own persistent domain state.

Tasks:
1. Define command models for at least:
   - ingest
   - reindex
   - delete
   - provider execution
2. Keep them explicit and typed.
3. Make them suitable for use from the MCP facade.
4. Keep them separate from persistence models.

Constraints:
- Do not implement workflows yet.
- Do not mix command models with HTTP transport DTOs unnecessarily.

Definition of done:
- The Orchestrator has clear command inputs.
- Workflow code can be built on stable internal contracts.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: add orchestrator command models`

Step 5.2 — Implement ingest workflow

Implement Step 5.2 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement the main ingestion workflow in the Processing Orchestrator.

Context:
The Document Library Engine can already persist document state, version state, and searchable representations.

Tasks:
1. Implement the ingest workflow in the Orchestrator.
2. Validate the operational minimum for ingest commands.
3. Call the Document Library Engine to:
   - save original file
   - persist base metadata
   - persist supplied extended metadata
   - persist supplied enriched metadata
4. Run version resolution through the Engine.
5. Build initial search corpus.
6. Trigger indexing.
7. Update statuses consistently.
8. Record audit events.

Constraints:
- Do not run optional provider branches yet in this step.
- Do not put persistence logic into the Orchestrator.
- Keep the workflow deterministic and testable.

Definition of done:
- The Orchestrator can execute the core ingest lifecycle.
- The workflow ends with persisted document state and index-ready/searchable state.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `feat: implement processing orchestrator ingest workflow`

Step 5.3 — Implement optional document extraction branch

Implement Step 5.3 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement the optional document extraction workflow branch in the Processing Orchestrator.

Context:
The main ingest workflow already exists. Document extraction providers are optional and disabled by default.

Tasks:
1. Add provider selection logic for document extraction.
2. Respect configuration and per-request processing options.
3. Invoke the selected extraction provider through the Provider Layer.
4. Persist extraction results only through the Document Library Engine.
5. Convert extraction results into searchable text via payload-to-search adapters.
6. Trigger search corpus update and reindex.
7. Update extraction statuses.
8. Isolate failures so they do not break the core ingest.

Constraints:
- Do not add semantic validation of extraction payloads.
- Do not let providers write directly to the database.
- Keep OCR/extraction distinct from metadata enrichment.

Definition of done:
- Document extraction works as an optional, failure-isolated branch.
- Its results can influence retrieval through the Engine.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `feat: implement optional document extraction workflow branch`

Step 5.4 — Implement optional metadata enrichment branch

Implement Step 5.4 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement the optional metadata enrichment workflow branch in the Processing Orchestrator.

Context:
The main ingest workflow already exists. Metadata enrichment providers are optional and disabled by default.

Tasks:
1. Add provider selection logic for metadata enrichment.
2. Respect configuration and per-request processing options.
3. Invoke the selected enrichment provider through the Provider Layer.
4. Persist enrichment results only through the Document Library Engine.
5. Convert enrichment results into searchable text via payload-to-search adapters.
6. Trigger search corpus update and reindex.
7. Update enrichment statuses.
8. Isolate failures so they do not break the core ingest.

Constraints:
- Do not add semantic validation of enrichment payloads.
- Do not mix enrichment with document extraction responsibilities.
- Keep supplied enriched metadata and provider-generated enrichment as separate concepts, even if both feed retrieval.

Definition of done:
- Metadata enrichment works as an optional, failure-isolated branch.
- Its results can influence retrieval through the Engine.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `feat: implement optional metadata enrichment workflow branch`

Step 5.5 — Implement delete workflow

Implement Step 5.5 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement controlled delete workflow in the Processing Orchestrator.

Context:
Delete must be orchestrated, while persistent effects are applied through the Document Library Engine.

Tasks:
1. Implement delete workflow supporting:
   - soft delete
   - hard delete
2. Route all persistent effects through the Engine.
3. Update statuses consistently.
4. Trigger index cleanup or reindex-related effects as appropriate.
5. Record audit events.

Constraints:
- Do not bypass Engine persistence.
- Keep default behavior aligned with soft delete preference.
- Keep workflow explicit and testable.

Definition of done:
- Delete is centrally orchestrated.
- Persistent and retrieval-related effects are handled coherently.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `feat: implement orchestrated delete workflow`

Step 5.6 — Implement reindex workflow

Implement Step 5.6 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement orchestrated reindex workflow.

Context:
The Engine already supports corpus/index rebuilding. The Orchestrator must provide the controlled workflow around it.

Tasks:
1. Implement reindex workflow in the Orchestrator.
2. Route rebuilding work through the Document Library Engine.
3. Add status updates and audit recording.
4. Add policy hooks for optional provider-related reruns when appropriate, but keep them minimal in v1.

Constraints:
- Do not push reindex policy into the Engine.
- Keep reindex behavior explicit and maintainable.

Definition of done:
- Reindex can be invoked as a managed workflow.
- Audit and statuses reflect the operation.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `feat: implement orchestrated reindex workflow`

Step 6.1 — Define MCP request/response schemas

Implement Step 6.1 for the project “TechDoc Library MCP Server v1”.

Goal:
Define MCP tool request/response schemas aligned with the architecture.

Context:
The internal Engine and Orchestrator services already exist.

Tasks:
1. Define request/response schemas for at least:
   - `ingest_document`
   - `search_documents`
   - `get_document`
   - `get_document_versions`
   - `delete_document`
   - `reindex_document`
   - `get_ingest_status`
2. Keep the MCP-facing contracts separate from internal persistence models.
3. Reflect support for:
   - base metadata
   - extended metadata
   - supplied enriched metadata
   - processing options for optional provider branches
4. Ensure response shapes can expose status and version context cleanly.

Constraints:
- Do not implement routing yet.
- Do not leak ORM models into MCP schemas.

Definition of done:
- MCP contracts are explicit and aligned with internal architecture.
- The facade layer has stable schemas to implement.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: define mcp tool schemas for technical document library`

Step 6.2 — Implement MCP adapter and routing

Implement Step 6.2 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement the MCP facade adapter and routing layer.

Context:
MCP request/response schemas already exist.

Tasks:
1. Implement MCP tool dispatch/routing.
2. Map MCP write operations to the Processing Orchestrator.
3. Map MCP read operations to the Document Library Engine where appropriate.
4. Add response shaping so internal outputs become MCP-facing outputs.
5. Keep MCP Facade thin and avoid embedding business persistence logic in it.

Constraints:
- Do not duplicate orchestration logic in the facade.
- Do not duplicate retrieval logic in the facade.
- Keep routing explicit and maintainable.

Definition of done:
- MCP requests are routed to the correct internal layer.
- The facade behaves as a thin adapter.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `feat: implement mcp facade routing and adapter layer`

Step 6.3 — Implement read-oriented tools

Implement Step 6.3 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement read-oriented MCP tools.

Context:
The MCP facade routing layer already exists.

Tasks:
1. Implement MCP tools for at least:
   - `search_documents`
   - `get_document`
   - `get_document_versions`
   - `get_document_metadata`
   - `get_document_processing_status`
2. Route reads primarily through the Document Library Engine.
3. Preserve version-awareness and match-context where supported.
4. Keep responses clean and MCP-friendly.

Constraints:
- Do not reimplement retrieval inside the facade.
- Keep tool behavior aligned with the Engine’s read APIs.

Definition of done:
- Read scenarios work through MCP.
- Version-aware retrieval information is surfaced properly.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `feat: implement read-oriented mcp tools`

Step 6.4 — Implement write-oriented tools

Implement Step 6.4 for the project “TechDoc Library MCP Server v1”.

Goal:
Implement write-oriented MCP tools.

Context:
The MCP facade routing layer already exists.

Tasks:
1. Implement MCP tools for at least:
   - `ingest_document`
   - `delete_document`
   - `reindex_document`
   - `get_ingest_status`
2. Route writes through the Processing Orchestrator.
3. Ensure MCP requests can carry:
   - base metadata
   - extended metadata
   - supplied enriched metadata
   - optional provider processing options
4. Surface processing status clearly in responses.

Constraints:
- Do not embed workflow logic directly in the facade.
- Keep status propagation explicit.

Definition of done:
- Core write operations work through MCP.
- The facade remains thin and correct.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `feat: implement write-oriented mcp tools`

Step 7.1 — Add production runtime settings for Linux

Implement Step 7.1 for the project “TechDoc Library MCP Server v1”.

Goal:
Prepare production-oriented Linux runtime settings.

Context:
The application now has the main architecture and MCP facade.

Tasks:
1. Add Linux-oriented runtime defaults and operational settings.
2. Ensure config supports:
   - bind host/port
   - working directory usage
   - storage paths
   - temp paths
   - environment-driven service configuration
3. Keep settings suitable for systemd deployment.
4. Review file/path handling for Linux expectations.

Constraints:
- Do not add containerization requirements unless clearly helpful.
- Keep deployment assumptions explicit and simple.

Definition of done:
- The service is operationally ready for Linux hosting.
- Runtime settings are explicit and production-friendly.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `chore: add linux runtime settings for deployment`

Step 7.2 — Add systemd unit files

Implement Step 7.2 for the project “TechDoc Library MCP Server v1”.

Goal:
Add systemd integration for Linux deployment.

Context:
The service is intended to run on Linux and should be manageable with systemd.

Tasks:
1. Add systemd service unit file(s).
2. Add env file example or operational notes as needed.
3. Define sensible restart policy and working directory usage.
4. Keep the service command aligned with the Python app entrypoint.
5. Add concise deployment notes if helpful.

Constraints:
- Do not overcomplicate service topology in v1.
- Keep systemd integration straightforward.

Definition of done:
- The project includes a usable systemd service definition.
- A Linux operator can understand how to run it.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `ops: add systemd service definition for library server`

Step 7.3 — Add PostgreSQL operational scripts/docs

Implement Step 7.3 for the project “TechDoc Library MCP Server v1”.

Goal:
Document PostgreSQL operational setup and maintenance expectations.

Context:
PostgreSQL is the core state backend for v1.

Tasks:
1. Add concise documentation for:
   - DB creation/setup
   - migration commands
   - local development DB usage
   - test DB usage
   - backup/restore notes
   - least-privilege role recommendations
2. Keep the docs practical and Linux-oriented.
3. Ensure the testing safety conventions are documented.

Constraints:
- Focus on operational clarity, not exhaustive DBA theory.
- Keep the docs aligned with the actual code/config.

Definition of done:
- PostgreSQL operational guidance exists and matches the implementation.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Create a git commit with message:
  `docs: add postgresql operational guidance`

Step 8.1 — Unit tests for Engine services

Implement Step 8.1 for the project “TechDoc Library MCP Server v1”.

Goal:
Add unit tests for Document Library Engine services.

Context:
The Engine is the authoritative stateful core and needs strong test coverage.

Tasks:
1. Add unit tests for at least:
   - versioning service
   - searchable representation builder
   - document persistence service
   - supplied/provider payload persistence handling
2. Keep tests isolated and fast where possible.
3. Use the existing test safety guard conventions.

Constraints:
- Do not depend unnecessarily on a real PostgreSQL instance for pure unit tests.
- Keep tests aligned with service boundaries.

Definition of done:
- The core Engine services are covered by meaningful unit tests.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `test: add unit tests for document library engine services`

Step 8.2 — Unit tests for Orchestrator

Implement Step 8.2 for the project “TechDoc Library MCP Server v1”.

Goal:
Add unit tests for Processing Orchestrator workflows.

Context:
The Orchestrator coordinates ingest, optional provider branches, delete, and reindex workflows.

Tasks:
1. Add unit tests for at least:
   - ingest workflow
   - document extraction branch
   - metadata enrichment branch
   - failure isolation behavior
   - delete workflow
   - reindex workflow
2. Mock or fake Engine/provider interactions where appropriate.
3. Validate status transitions and orchestration decisions.

Constraints:
- Do not collapse orchestration tests into end-to-end tests only.
- Keep workflow testing explicit.

Definition of done:
- The Orchestrator has meaningful workflow-level unit coverage.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `test: add unit tests for processing orchestrator workflows`

Step 8.3 — Integration tests with PostgreSQL

Implement Step 8.3 for the project “TechDoc Library MCP Server v1”.

Goal:
Add PostgreSQL-backed integration tests.

Context:
v1 relies on PostgreSQL as the state backend, so integration coverage is required.

Tasks:
1. Add integration tests for at least:
   - migration-up on a test database
   - ingest persistence flow
   - version resolution persistence
   - search corpus persistence/update
   - delete workflow persistence effects
   - reindex-related persistence effects
2. Enforce the strict test DB safety guard.
3. Keep integration tests realistic but maintainable.

Constraints:
- Tests must use test-only DB settings.
- Never allow fallback to a non-test DB.

Definition of done:
- The core workflow is validated against a real PostgreSQL-backed test environment.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `test: add integration tests for postgresql-backed workflows`

Step 8.4 — MCP facade integration tests

Implement Step 8.4 for the project “TechDoc Library MCP Server v1”.

Goal:
Add integration tests for the MCP facade contracts.

Context:
The MCP facade is the external interface and must correctly map to internal services.

Tasks:
1. Add integration tests for MCP-facing flows covering at least:
   - `ingest_document`
   - `search_documents`
   - `get_document`
   - `get_document_versions`
   - `delete_document`
   - `reindex_document`
   - `get_ingest_status`
2. Verify request/response mapping.
3. Verify status propagation and version-aware outputs.
4. Keep tests aligned with the actual facade design.

Constraints:
- Do not duplicate lower-level unit tests unnecessarily.
- Focus on contract-level behavior.

Definition of done:
- The MCP facade contract is verified against the implemented architecture.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `test: add integration tests for mcp facade tools`

Step 9.1 Implement content-delivery packaging for clean release bundles

You are implementing **Step 9.1 — Implement content-delivery packaging for clean release bundles**.

Goal:
- implement a reproducible packaging pipeline that forms a clean delivery package for end users.

Scope:
- allowlist-based release manifest;
- build script for staging, archive creation, and checksum generation;
- smoke validation of package contents;
- documentation for build usage and package composition.

Files to create/update:
- `release.manifest.yml`
- `scripts/build_release.py`
- `docs/content-delivery.md`
- `tests/unit/test_release_manifest.py`
- `tests/integration/test_build_release.py`

Tests:
- unit tests for manifest parsing and allowlist/exclude behavior;
- integration test for building a clean release bundle;
- verification that runtime files are included and development artifacts are excluded.

Definition of Done:
- the release bundle is built locally from an allowlist manifest;
- the package excludes tests, caches, virtualenvs, editor metadata, and other dev-only artifacts;
- the build script produces a `.tar.gz` archive and `.sha256` checksum in `dist/`.

Commit message:
`feat: add manifest-based release packaging pipeline for clean delivery bundles`

Step 9.2 — Refresh project overview and operational guides

Implement Step 9.2 for the project “TechDoc Library MCP Server v1”.

Goal:
Refresh the project documentation so README is the high-level overview and the operational guides are split by use case.

Tasks:
1. Rewrite `README.md` as the high-level project overview.
2. Add `docs/usage-guide.md` for local usage, MCP tool flows, and smoke checks.
3. Add `docs/deployment-guide.md` for Linux deployment, systemd, PostgreSQL, and restore/verification steps.
4. Keep the new docs aligned with the current architecture, component boundaries, and integrations.
5. Append the new step to the AGENTS prompt pack in the same style as the existing steps.
6. Add documentation-focused tests that verify the new pages cover the intended topics.

Constraints:
- Keep README concise and navigational.
- Keep the two new guides practical and operator-friendly.
- Do not remove the existing PostgreSQL or content-delivery documentation.

Definition of done:
- README provides the project overview, architecture, structure, components, and integration map.
- Usage and deployment guidance are separated into dedicated docs.
- The AGENTS prompt pack includes this documentation refresh as its last step.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `docs: refresh project overview and operational guides`

Step 9.3 — Ops docs corrections for service deployment

Implement Step 9.3 for the project “TechDoc Library MCP Server v1”.

Goal:
Correct the deployment-oriented documentation so the Linux service path is systemd-first and includes explicit service-user setup.

Context:
The README, usage guide, deployment guide, and AGENTS docs refresh from step 9.2 already exist.

Tasks:
1. Update docs so local development guidance can mention a virtual environment, but production deployment guidance does not imply a required virtualenv.
2. Add an explicit system user creation procedure to the Linux deployment guide.
3. Keep the deployment flow aligned with the existing systemd unit and service account naming.
4. Update the project overview and docs map where needed so readers can distinguish local development from production deployment.
5. Add documentation-focused tests for the new wording and deployment steps.

Constraints:
- Do not remove the existing deployment or PostgreSQL docs.
- Keep the change documentation-only unless a test reveals a wording mismatch with the current systemd/service layout.

Definition of done:
- The service deployment docs explain how to create and use the dedicated Linux service account.
- The usage guide clearly separates local development virtualenv usage from production deployment.
- The README and docs map reflect the service-centric deployment model.

Output requirements:
- Show changed files.
- Summarize what you implemented.
- Mention assumptions.
- Run relevant tests.
- Create a git commit with message:
  `docs: clarify service deployment user and local development guidance`

Suggested execution order


Use the prompts in this order:

  1. 0.1
  2. 0.2
  3. 0.3
  4. 0.4
  5. 0.5
  6. 0.6
  7. 1.1
  8. 1.2
  9. 1.3
  10. 1.4
  11. 2.1
  12. 2.2
  13. 2.3
  14. 2.4
  15. 2.5
  16. 3.1
  17. 3.2
  18. 3.3
  19. 3.4
  20. 3.5
  21. 4.1
  22. 4.2
  23. 4.3
  24. 4.4
  25. 4.5
  26. 5.1
  27. 5.2
  28. 5.3
  29. 5.4
  30. 5.5
  31. 5.6
  32. 6.1
  33. 6.2
  34. 6.3
  35. 6.4
  36. 7.1
  37. 7.2
  38. 7.3
  39. 8.1
  40. 8.2
  41. 8.3
  42. 8.4
  43. 9.1
  44. 9.2
  45. 9.3