Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ The response names the recorded report and its covered and instrumented line cou

With an MCP OAuth credential approved for several organizations, discover its currently authorized targets with `client.mcp.list_organizations()`. It returns a `KnowledgeResult`; inspect `isError` before reading `structuredContent["data"]["organizations"]`. Each entry contains `organization_id`, `github_login`, and `scopes`.

Pass the chosen UUID string as the optional keyword `organization_id` on any `knowledge` or `fixes` method:
Pass the chosen UUID string as the optional keyword `organization_id` on any `knowledge`, `fixes`, `config` or `setup` method:

```python
organizations = client.mcp.list_organizations()
Expand Down Expand Up @@ -211,6 +211,43 @@ if result.get("isError"):

Calls under `client.fixes` never retry. Results retain untrusted-text wrappers, availability, assessment gaps, and `isError`. `PENDING` and `NOT_VERIFIED` do not establish a fix, and a tool request never records a human disposition.

## Setup and configuration

Both clients expose the hosted setup reads under `client.setup` and configuration changes under `client.config`, over the same stateless MCP endpoint as `proofline setup` and `proofline config`. Every method accepts the optional `organization_id` keyword described above:

- `setup.get_setup_status()`
- `setup.list_setup_candidates(query=...)`
- `config.get_configuration(environment_id=..., repository=...)`
- `config.list_operations(area=..., subject=...)`
- `config.describe_operation(operation, parameters)`
- `config.propose_change(operation, parameters=..., input=..., expected_revision=..., cited_files=..., request_id=...)`
- `config.apply_change(change_id)`

The setup reads and `get_configuration` require `setup:write`. `describe_operation` and `apply_change` require `org:configure`; `list_operations` and `propose_change` accept either scope, although an ordinary proposal needs `org:configure`. The MCP endpoint also requires `reviews:read`.

```python
described = client.config.describe_operation(
"repository.wiki_settings.update", {"repo_id": repository_id}
)
data = described["structuredContent"]["data"]
proposal = client.config.propose_change(
"repository.wiki_settings.update",
parameters={"repo_id": repository_id},
input={"enabled": True},
expected_revision=data["revision"],
)
if proposal.get("isError"):
raise RuntimeError("The proposal was refused.")
change = proposal["structuredContent"]["data"]
if "approval_url" in change:
print("An administrator must approve the change at", change["approval_url"])
else:
print(change["diff"])
applied = client.config.apply_change(change["change_id"])
```

A proposal applies nothing. `propose_change` sends a new UUID version 7 as `request_id` on each call; to retry the identical call after an uncertain result, pass the same value, for example one from `new_request_id()`. Each entry of `cited_files` names the `repository_id`, the full `commit_sha` and the repository-relative `path` of a file read at that commit. An ordinary change applies through `apply_change`. A sensitive change returns an `approval_url` from either call, and applies only when an organization administrator approves it in a browser. Like the other MCP helpers, these methods never retry, raise `ProoflineError` for protocol and HTTP errors, and return tool refusals and held changes with `isError` and the server's reason for the caller to inspect. Treat returned prose as untrusted data.

## Development

The repository bundles its public API contract in `openapi.public.json`. New public operations generate typed methods on both `ProoflineClient` and `AsyncProoflineClient` along with the code in `proofline/_generated/`.
Expand Down
3 changes: 3 additions & 0 deletions proofline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from ._transport import VERSION as __version__
from ._transport import ProoflineError, RunNowRefusal
from .client import AsyncProoflineClient, ProoflineClient, ReviewFilters
from .configuration import CitedFile, new_request_id
from .exports import ExportDataset, ExportFormat, ExportPage
from .knowledge import KnowledgeResult
from .outcomes import AssessmentGap, CheckGap, ReviewOutcome
Expand All @@ -44,6 +45,7 @@
"AssessmentGap",
"AsyncProoflineClient",
"CheckGap",
"CitedFile",
"CommitReviewRequest",
"CommitReviewResponse",
"CoverageUploadRequest",
Expand Down Expand Up @@ -80,4 +82,5 @@
"UploadedReport",
"__version__",
"models",
"new_request_id",
]
10 changes: 10 additions & 0 deletions proofline/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
from ._generated.types import UNSET, Response, Unset
from ._mcp import AsyncMcpClient, McpClient
from ._transport import ProoflineError
from .configuration import (
AsyncConfigurationClient,
AsyncSetupClient,
ConfigurationClient,
SetupClient,
)
from .exports import ExportDataset, ExportFormat, ExportPage, decode_export
from .fixes import AsyncFixesClient, FixesClient
from .knowledge import AsyncKnowledgeClient, KnowledgeClient
Expand Down Expand Up @@ -240,6 +246,8 @@ def __init__(
self.mcp = McpClient(self._http)
self.knowledge = KnowledgeClient(self._http)
self.fixes = FixesClient(self._http)
self.config = ConfigurationClient(self._http)
self.setup = SetupClient(self._http)

def close(self) -> None:
self._http.close()
Expand Down Expand Up @@ -610,6 +618,8 @@ def __init__(
self.mcp = AsyncMcpClient(self._http)
self.knowledge = AsyncKnowledgeClient(self._http)
self.fixes = AsyncFixesClient(self._http)
self.config = AsyncConfigurationClient(self._http)
self.setup = AsyncSetupClient(self._http)

async def aclose(self) -> None:
await self._http.aclose()
Expand Down
211 changes: 211 additions & 0 deletions proofline/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
"""Setup reads and configuration changes through the scoped MCP server.

A proposal applies nothing; an ordinary change applies only through apply_change,
and a sensitive one only through browser approval. Tool refusals retain isError.
"""

from __future__ import annotations

import os
import time
from collections.abc import Mapping, Sequence
from typing import Any, TypedDict
from uuid import UUID

from ._mcp import AsyncMcpTools, KnowledgeResult, McpTools


class CitedFile(TypedDict):
"""A repository file, read at a full commit SHA, behind an inferred value."""

repository_id: str
commit_sha: str
path: str


def new_request_id() -> str:
"""Return a fresh time-ordered UUID (version 7) for one propose_change call."""
value = (time.time_ns() // 1_000_000 & (1 << 48) - 1) << 80
value |= int.from_bytes(os.urandom(10), "big")
value = value & ~(0xF << 76) | 0x7 << 76
value = value & ~(0x3 << 62) | 0x2 << 62
return str(UUID(int=value))


def _optional(**values: Any) -> dict[str, Any]:
return {name: value for name, value in values.items() if value is not None}


def _describe(operation: str, parameters: Mapping[str, str] | None) -> dict[str, Any]:
return {"operation": operation, "parameters": dict(parameters or {})}


def _proposal(
operation: str,
parameters: Mapping[str, str] | None,
input: Any,
expected_revision: str | None,
cited_files: Sequence[CitedFile] | None,
request_id: str | None,
) -> dict[str, Any]:
args: dict[str, Any] = {"operation": operation, "parameters": dict(parameters or {})}
if input is not None:
args["input"] = input
if expected_revision is not None:
args["expected_revision"] = expected_revision
if cited_files is not None:
args["cited_files"] = [dict(cited) for cited in cited_files]
args["request_id"] = new_request_id() if request_id is None else request_id
return args


class ConfigurationClient(McpTools):
def get_configuration(
self,
*,
environment_id: str | None = None,
repository: str | None = None,
organization_id: str | None = None,
) -> KnowledgeResult:
return self._call(
"get_configuration",
_optional(environment_id=environment_id, repository=repository),
organization_id=organization_id,
)

def list_operations(
self,
*,
area: str | None = None,
subject: str | None = None,
organization_id: str | None = None,
) -> KnowledgeResult:
return self._call(
"list_operations",
_optional(area=area, subject=subject),
organization_id=organization_id,
)

def describe_operation(
self,
operation: str,
parameters: Mapping[str, str] | None = None,
*,
organization_id: str | None = None,
) -> KnowledgeResult:
return self._call(
"describe_operation",
_describe(operation, parameters),
organization_id=organization_id,
)

def propose_change(
self,
operation: str,
*,
parameters: Mapping[str, str] | None = None,
input: Any = None,
expected_revision: str | None = None,
cited_files: Sequence[CitedFile] | None = None,
request_id: str | None = None,
organization_id: str | None = None,
) -> KnowledgeResult:
return self._call(
"propose_change",
_proposal(operation, parameters, input, expected_revision, cited_files, request_id),
organization_id=organization_id,
)

def apply_change(
self, change_id: str, *, organization_id: str | None = None
) -> KnowledgeResult:
return self._call("apply_change", {"change_id": change_id}, organization_id=organization_id)


class AsyncConfigurationClient(AsyncMcpTools):
async def get_configuration(
self,
*,
environment_id: str | None = None,
repository: str | None = None,
organization_id: str | None = None,
) -> KnowledgeResult:
return await self._call(
"get_configuration",
_optional(environment_id=environment_id, repository=repository),
organization_id=organization_id,
)

async def list_operations(
self,
*,
area: str | None = None,
subject: str | None = None,
organization_id: str | None = None,
) -> KnowledgeResult:
return await self._call(
"list_operations",
_optional(area=area, subject=subject),
organization_id=organization_id,
)

async def describe_operation(
self,
operation: str,
parameters: Mapping[str, str] | None = None,
*,
organization_id: str | None = None,
) -> KnowledgeResult:
return await self._call(
"describe_operation",
_describe(operation, parameters),
organization_id=organization_id,
)

async def propose_change(
self,
operation: str,
*,
parameters: Mapping[str, str] | None = None,
input: Any = None,
expected_revision: str | None = None,
cited_files: Sequence[CitedFile] | None = None,
request_id: str | None = None,
organization_id: str | None = None,
) -> KnowledgeResult:
return await self._call(
"propose_change",
_proposal(operation, parameters, input, expected_revision, cited_files, request_id),
organization_id=organization_id,
)

async def apply_change(
self, change_id: str, *, organization_id: str | None = None
) -> KnowledgeResult:
return await self._call(
"apply_change", {"change_id": change_id}, organization_id=organization_id
)


class SetupClient(McpTools):
def get_setup_status(self, *, organization_id: str | None = None) -> KnowledgeResult:
return self._call("get_setup_status", {}, organization_id=organization_id)

def list_setup_candidates(
self, *, query: str | None = None, organization_id: str | None = None
) -> KnowledgeResult:
return self._call(
"list_setup_candidates", _optional(query=query), organization_id=organization_id
)


class AsyncSetupClient(AsyncMcpTools):
async def get_setup_status(self, *, organization_id: str | None = None) -> KnowledgeResult:
return await self._call("get_setup_status", {}, organization_id=organization_id)

async def list_setup_candidates(
self, *, query: str | None = None, organization_id: str | None = None
) -> KnowledgeResult:
return await self._call(
"list_setup_candidates", _optional(query=query), organization_id=organization_id
)
Loading