refactor(mcp): extract order services into independent project
Remove Kingdee sync, business CLI/MCP tools, and internal order-query routing now owned by the separate kingdee-orders-mcp project. Keep Wiki retrieval, file assets and ingest available in code while its deployed service is off. Retain legacy response fields with business access disabled, and document migration ownership and rollback without exposing credentials or data. Validation: 174 Wiki tests pass. Independent order service verified with 36 template parity checks, authenticated HTTP queries, and a real sync.
This commit is contained in:
@@ -16,8 +16,6 @@ from urllib.parse import urlsplit, urlunsplit
|
||||
|
||||
from obsidian_wiki import __version__
|
||||
from obsidian_wiki.config import config_value, resolve_vault_path
|
||||
from obsidian_wiki.business_facts import business_db_path_for_vault
|
||||
from obsidian_wiki.mcp_business import BUSINESS_TOOLS, BusinessQueries, register_business_tools
|
||||
from obsidian_wiki.file_assets import clean_config_value, db_path_for_vault, registry_path_for_vault
|
||||
from obsidian_wiki.mcp_ingest import (
|
||||
DEFAULT_INGEST_JOB_TIMEOUT_SECONDS,
|
||||
@@ -65,14 +63,13 @@ PUBLIC_UPLOAD_URL_ENV = "OBSIDIAN_MCP_INGEST_PUBLIC_UPLOAD_URL"
|
||||
ALLOWED_HOSTS_ENV = "OBSIDIAN_MCP_ALLOWED_HOSTS"
|
||||
ALLOWED_ORIGINS_ENV = "OBSIDIAN_MCP_ALLOWED_ORIGINS"
|
||||
MCP_SERVER_NAME = "wiki-file-assets"
|
||||
CAPABILITIES_SCHEMA_VERSION = 4
|
||||
TOOLS_VERSION = 4
|
||||
CAPABILITIES_SCHEMA_VERSION = 5
|
||||
TOOLS_VERSION = 5
|
||||
TOOL_FILE_ASSETS = "file-assets"
|
||||
TOOL_INGEST = "ingest"
|
||||
TOOL_QUERY = "query"
|
||||
TOOL_BUSINESS = "business"
|
||||
DEFAULT_ENABLED_TOOLS = {TOOL_FILE_ASSETS}
|
||||
AVAILABLE_TOOLS = {TOOL_FILE_ASSETS, TOOL_INGEST, TOOL_QUERY, TOOL_BUSINESS}
|
||||
AVAILABLE_TOOLS = {TOOL_FILE_ASSETS, TOOL_INGEST, TOOL_QUERY}
|
||||
|
||||
|
||||
def text_note_file_name(title: str | None) -> str:
|
||||
@@ -117,8 +114,6 @@ def normalize_tool_name(name: str) -> str:
|
||||
"upload": TOOL_INGEST,
|
||||
"uploads": TOOL_INGEST,
|
||||
"opencode-ingest": TOOL_INGEST,
|
||||
"business": TOOL_BUSINESS,
|
||||
"orders": TOOL_BUSINESS,
|
||||
"query": TOOL_QUERY,
|
||||
"wiki-query": TOOL_QUERY,
|
||||
"ask": TOOL_QUERY,
|
||||
@@ -210,8 +205,6 @@ def create_server(
|
||||
enable_file_assets: bool = True,
|
||||
enable_ingest: bool = False,
|
||||
enable_query: bool = False,
|
||||
enable_business: bool = False,
|
||||
business_db_path: str | Path | None = None,
|
||||
project_root: str | Path | None = None,
|
||||
ingest_runtime_root: str | Path | None = None,
|
||||
query_runtime_root: str | Path | None = None,
|
||||
@@ -289,7 +282,6 @@ def create_server(
|
||||
([TOOL_FILE_ASSETS] if enable_file_assets else [])
|
||||
+ ([TOOL_INGEST] if enable_ingest else [])
|
||||
+ ([TOOL_QUERY] if enable_query else [])
|
||||
+ ([TOOL_BUSINESS] if enable_business else [])
|
||||
),
|
||||
"ingest_enabled": enable_ingest,
|
||||
"query_enabled": enable_query,
|
||||
@@ -315,7 +307,6 @@ def create_server(
|
||||
([TOOL_FILE_ASSETS] if enable_file_assets else [])
|
||||
+ ([TOOL_INGEST] if enable_ingest else [])
|
||||
+ ([TOOL_QUERY] if enable_query else [])
|
||||
+ ([TOOL_BUSINESS] if enable_business else [])
|
||||
)
|
||||
return {
|
||||
"server_name": MCP_SERVER_NAME,
|
||||
@@ -328,17 +319,8 @@ def create_server(
|
||||
enable_file_assets=enable_file_assets,
|
||||
enable_ingest=enable_ingest,
|
||||
enable_query=enable_query,
|
||||
enable_business=enable_business,
|
||||
),
|
||||
"file_index": _file_index_capabilities(vault, db) if enable_file_assets else {"enabled": False},
|
||||
"business": {
|
||||
"enabled": enable_business,
|
||||
"tools": BUSINESS_TOOLS if enable_business else [],
|
||||
"preferred_tool": "query_business_template" if enable_business else None,
|
||||
"read_only": True,
|
||||
"requires_opencode": False,
|
||||
"requires_wiki": False,
|
||||
},
|
||||
"file_assets": {
|
||||
"enabled": enable_file_assets,
|
||||
"tools": (
|
||||
@@ -381,8 +363,8 @@ def create_server(
|
||||
if enable_query
|
||||
else []
|
||||
),
|
||||
"supports_business_facts": enable_query,
|
||||
"supports_hybrid_questions": enable_query,
|
||||
"supports_business_facts": False,
|
||||
"supports_hybrid_questions": False,
|
||||
"public_only_disables_business_facts": True,
|
||||
"supports_structured_result": enable_query,
|
||||
"max_query_chars": query_max_chars,
|
||||
@@ -481,20 +463,6 @@ def create_server(
|
||||
},
|
||||
}
|
||||
|
||||
if enable_business:
|
||||
configured_db = business_db_path or runtime_config_value("OBSIDIAN_MCP_BUSINESS_DB", "")
|
||||
business_db = Path(configured_db).expanduser() if configured_db else business_db_path_for_vault(vault)
|
||||
defaults = {}
|
||||
for key, env in (
|
||||
("internal_parties", "OBSIDIAN_BUSINESS_INTERNAL_PARTIES"),
|
||||
("internal_party_ids", "OBSIDIAN_BUSINESS_INTERNAL_PARTY_IDS"),
|
||||
("include_internal_orders", "OBSIDIAN_BUSINESS_INCLUDE_INTERNAL_ORDERS"),
|
||||
):
|
||||
value = runtime_config_value(env, "")
|
||||
if value:
|
||||
defaults[key] = value
|
||||
register_business_tools(server, BusinessQueries(business_db, defaults=defaults))
|
||||
|
||||
owns_ingest_manager = False
|
||||
if enable_ingest:
|
||||
if ingest_manager is None:
|
||||
@@ -1323,8 +1291,6 @@ def run_http_server(
|
||||
enable_file_assets: bool = True,
|
||||
enable_ingest: bool = False,
|
||||
enable_query: bool = False,
|
||||
enable_business: bool = False,
|
||||
business_db_path: str | Path | None = None,
|
||||
project_root: str | Path | None = None,
|
||||
ingest_runtime_root: str | Path | None = None,
|
||||
query_runtime_root: str | Path | None = None,
|
||||
@@ -1410,8 +1376,6 @@ def run_http_server(
|
||||
enable_file_assets=enable_file_assets,
|
||||
enable_ingest=enable_ingest,
|
||||
enable_query=enable_query,
|
||||
enable_business=enable_business,
|
||||
business_db_path=business_db_path,
|
||||
project_root=project_root,
|
||||
ingest_runtime_root=ingest_runtime_root,
|
||||
query_runtime_root=query_runtime_root,
|
||||
@@ -1451,7 +1415,6 @@ def main(argv: list[str] | None = None) -> int:
|
||||
parser = argparse.ArgumentParser(prog="obsidian-wiki-mcp", description="Run the obsidian-wiki MCP server")
|
||||
parser.add_argument("--vault", metavar="PATH", help="absolute path to the Obsidian vault")
|
||||
parser.add_argument("--db", metavar="PATH", help="SQLite file asset index path")
|
||||
parser.add_argument("--business-db", metavar="PATH", help="Existing sales-order SQLite database (independent of the file index)")
|
||||
parser.add_argument("--profile", default=None, help=f"bot profile name, default: {DEFAULT_PROFILE_NAME}")
|
||||
parser.add_argument("--max-file-bytes", type=int, default=None, help="maximum resource size, 0 disables the limit")
|
||||
parser.add_argument(
|
||||
@@ -1517,8 +1480,6 @@ def main(argv: list[str] | None = None) -> int:
|
||||
enable_file_assets = TOOL_FILE_ASSETS in enabled_tools
|
||||
enable_ingest = TOOL_INGEST in enabled_tools
|
||||
enable_query = TOOL_QUERY in enabled_tools
|
||||
enable_business = TOOL_BUSINESS in enabled_tools
|
||||
business_db_path = args.business_db or runtime_config_value("OBSIDIAN_MCP_BUSINESS_DB", "") or None
|
||||
ingest_max_file_bytes = runtime_config_int("OBSIDIAN_MCP_INGEST_MAX_FILE_BYTES", DEFAULT_INGEST_MAX_FILE_BYTES)
|
||||
ingest_max_chunk_bytes = runtime_config_int("OBSIDIAN_MCP_INGEST_MAX_CHUNK_BYTES", DEFAULT_INGEST_MAX_CHUNK_BYTES)
|
||||
ingest_max_files_per_job = runtime_config_int(
|
||||
@@ -1569,8 +1530,6 @@ def main(argv: list[str] | None = None) -> int:
|
||||
enable_file_assets=enable_file_assets,
|
||||
enable_ingest=enable_ingest,
|
||||
enable_query=enable_query,
|
||||
enable_business=enable_business,
|
||||
business_db_path=business_db_path,
|
||||
project_root=Path.cwd(),
|
||||
ingest_runtime_root=ingest_runtime_root,
|
||||
query_runtime_root=query_runtime_root,
|
||||
@@ -1613,8 +1572,6 @@ def main(argv: list[str] | None = None) -> int:
|
||||
enable_file_assets=enable_file_assets,
|
||||
enable_ingest=enable_ingest,
|
||||
enable_query=enable_query,
|
||||
enable_business=enable_business,
|
||||
business_db_path=business_db_path,
|
||||
project_root=Path.cwd(),
|
||||
ingest_runtime_root=ingest_runtime_root,
|
||||
query_runtime_root=query_runtime_root,
|
||||
@@ -1674,19 +1631,17 @@ def _upload_url_from_public_base(public_base_url: str, upload_path: str) -> str
|
||||
return urlunsplit((parsed.scheme, parsed.netloc, upload_path, "", ""))
|
||||
|
||||
|
||||
def _recommended_first_steps(*, enable_file_assets: bool, enable_ingest: bool, enable_query: bool, enable_business: bool = False) -> list[str]:
|
||||
def _recommended_first_steps(*, enable_file_assets: bool, enable_ingest: bool, enable_query: bool) -> list[str]:
|
||||
steps: list[str] = []
|
||||
if enable_business:
|
||||
steps.append("Use get_business_schema, then query_business_template for direct sales-order queries; get_business_status reports freshness.")
|
||||
if enable_query:
|
||||
steps.append("Use ask_wiki for ordinary wiki, business facts, or hybrid questions.")
|
||||
steps.append("Use ask_wiki for wiki questions.")
|
||||
if enable_file_assets:
|
||||
steps.append("Use search_file_assets before reading source file resources.")
|
||||
if enable_ingest:
|
||||
steps.append("Use ingest_text_note for short text notes.")
|
||||
steps.append("Use create_ingest_upload_ticket before remote HTTP file upload.")
|
||||
if not steps:
|
||||
steps.append("No optional MCP tool groups are enabled; ask the operator to enable business, file-assets, query, or ingest.")
|
||||
steps.append("No optional MCP tool groups are enabled; ask the operator to enable file-assets, query, or ingest.")
|
||||
return steps
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user