feat(mcp): add agent-friendly query capabilities
Add get_mcp_capabilities so remote agents can discover enabled tool groups and preferred entrypoints. Add ask_wiki as a one-call query wrapper with structured result fields while keeping the legacy answer field for compatibility. Update MCP startup guidance and docs, and cover the new query/capability behavior with tests.
This commit is contained in:
@@ -150,8 +150,76 @@ class McpQueryTests(unittest.TestCase):
|
||||
|
||||
self.assertEqual(result["state"], "succeeded")
|
||||
self.assertIn("Based on the wiki", result["answer"])
|
||||
self.assertEqual(result["answer_markdown"], result["answer"])
|
||||
self.assertEqual(result["citations"], [])
|
||||
self.assertFalse(result["used_business_facts"])
|
||||
self.assertTrue(result["used_wiki"])
|
||||
self.assertEqual(result["data_freshness"], [])
|
||||
self.assertEqual(result["confidence"], "high")
|
||||
self.assertEqual(result["warnings"], [])
|
||||
self.assertIn("Answer body", result["opencode_output_tail"])
|
||||
|
||||
def test_query_result_extracts_structured_metadata_from_output(self):
|
||||
popen = FakePopen(returncode=None)
|
||||
|
||||
with (
|
||||
patch("obsidian_wiki.mcp_query.subprocess.run", side_effect=self._fake_static_readiness_run),
|
||||
patch("obsidian_wiki.mcp_query.subprocess.Popen", return_value=popen),
|
||||
):
|
||||
job = self.manager.start_query_job("customer situation?")
|
||||
|
||||
log_path = Path(self.manager._load_job(job["job_id"])["log_path"])
|
||||
log_path.write_text(
|
||||
"Based on [[Mini FAKRA]] and [[BJD]].\n"
|
||||
"Business facts used. Data through 2026-06-02.\n"
|
||||
"Answer body\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
popen.returncode = 0
|
||||
result = self.manager.get_query_job_result(job["job_id"])
|
||||
|
||||
self.assertEqual(result["answer_markdown"], result["answer"])
|
||||
self.assertEqual(result["citations"], ["Mini FAKRA", "BJD"])
|
||||
self.assertTrue(result["used_business_facts"])
|
||||
self.assertTrue(result["used_wiki"])
|
||||
self.assertEqual(result["data_freshness"], ["2026-06-02"])
|
||||
self.assertEqual(result["confidence"], "high")
|
||||
|
||||
def test_query_result_marks_failed_jobs_low_confidence_with_warnings(self):
|
||||
popen = FakePopen(returncode=1)
|
||||
|
||||
with (
|
||||
patch("obsidian_wiki.mcp_query.subprocess.run", side_effect=self._fake_static_readiness_run),
|
||||
patch("obsidian_wiki.mcp_query.subprocess.Popen", return_value=popen),
|
||||
):
|
||||
job = self.manager.start_query_job("what failed?")
|
||||
|
||||
log_path = Path(self.manager._load_job(job["job_id"])["log_path"])
|
||||
log_path.write_text("Traceback: failed\n", encoding="utf-8")
|
||||
result = self.manager.get_query_job_result(job["job_id"])
|
||||
|
||||
self.assertEqual(result["state"], "failed")
|
||||
self.assertEqual(result["confidence"], "low")
|
||||
self.assertTrue(any("failed" in warning.lower() for warning in result["warnings"]))
|
||||
|
||||
def test_ask_wiki_returns_timeout_payload_with_job_id(self):
|
||||
popen = FakePopen(returncode=None)
|
||||
|
||||
with (
|
||||
patch("obsidian_wiki.mcp_query.subprocess.run", side_effect=self._fake_static_readiness_run),
|
||||
patch("obsidian_wiki.mcp_query.subprocess.Popen", return_value=popen),
|
||||
):
|
||||
result = self.manager.ask_wiki(
|
||||
"slow question?",
|
||||
timeout_seconds=0,
|
||||
poll_interval_seconds=1,
|
||||
)
|
||||
|
||||
self.assertEqual(result["state"], "running")
|
||||
self.assertRegex(result["job_id"], r"^[0-9a-f]{32}$")
|
||||
self.assertEqual(result["next_poll_after_seconds"], 1)
|
||||
self.assertIn("timed out", " ".join(result["warnings"]).lower())
|
||||
|
||||
def test_jobs_queue_one_at_a_time_and_cancel_queued_job(self):
|
||||
popen = FakePopen(returncode=None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user