from __future__ import annotations
import asyncio
from app.mcp_server import (
get_agent_usage_guide,
get_inventory_item,
list_inventory,
mcp,
read_doc,
search_docs,
validate_repository_tool,
)
def test_mcp_lists_core_tools() -> None:
tools = asyncio.run(mcp.list_tools())
names = {tool.name for tool in tools}
assert "search_docs" in names
assert "get_agent_usage_guide" in names
assert "read_doc" in names
assert "list_inventory" in names
assert "update_doc" in names
assert "commit_changes" in names
def test_inventory_write_tool_schema_is_self_describing() -> None:
tools = asyncio.run(mcp.list_tools())
tool = next(t for t in tools if t.name == "propose_inventory_item_change")
assert "top-level arguments" in tool.description
props = tool.inputSchema["properties"]
assert "Do not wrap" in props["patch"]["description"]
assert "Canonical inventory item id" in props["item_id"]["description"]
assert set(tool.inputSchema["required"]) == {"inventory_type", "item_id", "patch", "summary"}
def test_mcp_instructions_tell_agents_to_use_knowledge_base_proactively() -> None:
assert mcp.instructions is not None
assert "canonical knowledge base" in mcp.instructions
assert "Use it proactively" in mcp.instructions
assert "do not wait for the user" in mcp.instructions
assert "Do not store raw passwords" in mcp.instructions
assert "If a discovered fact is useful beyond the current chat" in mcp.instructions
def test_mcp_agent_usage_guide_explains_maintenance_workflow() -> None:
guide = get_agent_usage_guide()["guide"]
assert "infrastructure memory" in guide
assert "Keep it current" in guide
assert "End-of-task maintenance check" in guide
assert "Do not document" in guide
def test_mcp_tool_functions_read_repository() -> None:
doc = read_doc("10-systems/applications/gitbucket.md")
assert doc["path"] == "10-systems/applications/gitbucket.md"
assert "GitBucket" in doc["body"]
results = search_docs("GitBucket")
assert any(result["path"] == "10-systems/applications/gitbucket.md" for result in results)
inventory_types = list_inventory()
assert "services" in inventory_types
service = get_inventory_item("services", "gitbucket")
assert service["name"] == "GitBucket"
def test_mcp_validation_tool_is_clean() -> None:
report = validate_repository_tool()
assert report["status"] == "ok"