-
Notifications
You must be signed in to change notification settings - Fork 1
feat: expose durable Global Ask through authenticated MCP #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
seonghobae
merged 3 commits into
fix/global-ask-graph-fact-provenance
from
feat/mcp-global-ask-current-contract
Aug 25, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ### Added | ||
|
|
||
| - Added an authenticated Streamable HTTP MCP adapter that queues and reads the | ||
| same durable Global Ask jobs as REST, with exact-resource OAuth, bounded | ||
| pre-auth request admission, owner/affiliation scope preservation, and a | ||
| fail-closed distributed quota whose capacity inputs are deployment evidence. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| """Shared durable Global Ask application service for REST and MCP.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from typing import Any | ||
| from uuid import UUID | ||
|
|
||
| import asyncpg | ||
| import redis.asyncio as redis | ||
| from fastapi import HTTPException, status | ||
|
|
||
| from backend.app.auth import CurrentAccount | ||
| from backend.app.global_ask_queue import enqueue_global_ask_job | ||
| from backend.app.source_post_revision import parse_as_of_clock | ||
|
|
||
|
|
||
| async def submit_global_ask( | ||
| *, | ||
| pool: asyncpg.Pool, | ||
| valkey: redis.Redis, | ||
| account: CurrentAccount, | ||
| question: str, | ||
| verify_external: bool, | ||
| knowledge_cutoff: str | None, | ||
| service_available: bool, | ||
| ) -> dict[str, Any]: | ||
| """Validate and enqueue one durable owner-scoped Global Ask job.""" | ||
| if not account.has_permission("post_read"): | ||
| raise HTTPException(status.HTTP_403_FORBIDDEN, "post_read permission required") | ||
| normalized_question = question.strip() | ||
| if not normalized_question: | ||
| raise HTTPException( | ||
| status.HTTP_422_UNPROCESSABLE_CONTENT, "question is required" | ||
| ) | ||
| cutoff = None | ||
| if knowledge_cutoff is not None: | ||
| try: | ||
| cutoff = parse_as_of_clock(knowledge_cutoff) | ||
| except ValueError as exc: | ||
| raise HTTPException( | ||
| status.HTTP_422_UNPROCESSABLE_CONTENT, | ||
| "knowledge_cutoff must be an ISO-8601 timestamp", | ||
| ) from exc | ||
| async with pool.acquire() as conn: | ||
| if cutoff is not None and cutoff > await conn.fetchval("select now()"): | ||
| raise HTTPException( | ||
| status.HTTP_422_UNPROCESSABLE_CONTENT, | ||
| "knowledge_cutoff must be at or before the database clock", | ||
| ) | ||
| if not service_available: | ||
| raise HTTPException( | ||
| status.HTTP_503_SERVICE_UNAVAILABLE, | ||
| "Ask Agent is unavailable. Ask an administrator to configure the analysis service, then retry.", | ||
| ) | ||
| job_id = await enqueue_global_ask_job( | ||
| conn, | ||
| valkey, | ||
| requesting_account_id=account.user_account_id, | ||
| question_text=normalized_question, | ||
| verify_external_requested=verify_external, | ||
| knowledge_cutoff=cutoff, | ||
| corporate_entity_ids=account.corporate_entity_ids, | ||
| process_unit_ids=account.process_unit_ids, | ||
| ) | ||
| return {"ask_job_id": job_id, "job_status_code": "queued"} | ||
|
|
||
|
|
||
| async def read_global_ask_job( | ||
| *, pool: asyncpg.Pool, account: CurrentAccount, ask_job_id: UUID | ||
| ) -> dict[str, Any]: | ||
| """Read one owner's durable Global Ask status and persisted result.""" | ||
| if not account.has_permission("post_read"): | ||
| raise HTTPException(status.HTTP_403_FORBIDDEN, "post_read permission required") | ||
| async with pool.acquire() as conn: | ||
| row = await conn.fetchrow( | ||
| "select requesting_account_id, job_status_code, answer_payload," | ||
| " failure_detail from global_ask_job where global_ask_job_id = $1", | ||
| ask_job_id, | ||
| ) | ||
| if row is None or str(row["requesting_account_id"]) != account.user_account_id: | ||
| raise HTTPException(status.HTTP_404_NOT_FOUND, "ask job not found") | ||
| body: dict[str, Any] = { | ||
| "ask_job_id": str(ask_job_id), | ||
| "job_status_code": row["job_status_code"], | ||
| } | ||
| if row["job_status_code"] == "succeeded" and row["answer_payload"] is not None: | ||
| payload = row["answer_payload"] | ||
| body["answer"] = json.loads(payload) if isinstance(payload, str) else payload | ||
| if row["job_status_code"] == "failed": | ||
| body["failure_detail"] = row["failure_detail"] | ||
| return body | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: Permission check now precedes blank-question check
The old REST
ask_agentreturned 422 for a blank question before enforcingpost_read. The shared service checks permission first (backend/app/global_ask_service.py:29-35), so a provisioned account withoutpost_readsubmitting a blank question now gets 403 instead of 422. The status for that edge case changed.Was this helpful? React with 👍 or 👎 to provide feedback.