EnergyVenom's picture
Patchwise Agent Studio: Oracle AI Agent Studio cycles
af1bee9 verified
|
Raw History Blame Contribute Delete
7.11 kB

MCP connector

Audience: people connecting an AI assistant (Claude, VS Code Copilot, Cursor, Copilot Studio) to Patchwise, and the administrators who look after it.

Patchwise speaks the Model Context Protocol at https://<your-patchwise-host>/mcp. An assistant can then answer "is Procure-to-Pay ready?" or "what's waiting for me?" from live data, and, with permission, propose a test run or approve scenarios, which only happens after an explicit confirm.

Phase 1: personal access tokens

Each person makes their own token in Account → Access tokens for AI assistants (or POST /api/tokens):

Field Values
Name what it's for, e.g. "Claude on my laptop" (1 to 80 characters)
Access read (look only) or read,act (also propose and confirm)
Expires 1 to 365 days, default 90

Rules:

  • Shown once. The token (pwt_…) is displayed once at creation and stored only as a SHA-256 hash; the list shows the last 4 characters.
  • The person's current role applies. A token never grants more than its owner may do today. Demote, disable or delete the person and the token follows at once.
  • Only on /mcp and /a2a. Tokens are refused on /api/* and in the web app (A2A.md covers /a2a).
  • Revoking. Anyone can revoke their own tokens on the Account page (Access tokens for AI assistants). Administrators see and revoke everyone's in Administration (/api/admin/tokens).
  • Rate limit. 60 requests a minute per token.

Tools

Tool Needs What it does
readiness read Readiness of one business area, or all, from the latest runs
waiting_for_me read Runs waiting on a decision this person may take
list_runs read Recent runs, optionally filtered by status (max 20)
get_run read One run's status, progress and next step
report_summary read A finished run's outcome (Ready / Not ready / Held) and report links
ask read A question answered by the Ask service; it never acts
propose_test_run act + run.start Proposes a run (area, quick or browser, environment); nothing starts yet
propose_approve_scenarios act + gate.approve_cases Proposes approving the scenarios of a run at that gate
confirm act Carries out a proposal: single use, 10 minutes, same person and same token; re-checks role, run state and the emergency stop
cancel act Drops a proposal

Never offered, by design: sign-off, failure verdicts, the emergency stop, and administration. Those stay in the app, and the tools answer with a link to them.

Every proposal, confirmation and failed confirmation is in the audit log (mcp.propose, mcp.confirm, mcp.confirm.failed, plus the run's own run.started with "via": "mcp"). Tokens appear as token.created, token.revoked and token.used (once a day per token).

Connecting a client

Replace the host and keep the token out of files you share or commit. Each example reads it from an environment variable or a password prompt.

Claude Code

claude mcp add --transport http patchwise https://<host>/mcp --header "Authorization: Bearer $PATCHWISE_TOKEN"

Claude Desktop (through mcp-remote)

claude_desktop_config.json:

{
  "mcpServers": {
    "patchwise": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://<host>/mcp", "--header", "Authorization:${PATCHWISE_AUTH}"],
      "env": { "PATCHWISE_AUTH": "Bearer pwt_…" }
    }
  }
}

There is no space after Authorization:; the space lives inside the variable. This avoids an argument-quoting problem on Windows. Requires Node.js 18 or later.

VS Code (GitHub Copilot agent mode)

.vscode/mcp.json asks for the token once and keeps it in VS Code's secret storage:

{
  "inputs": [{ "type": "promptString", "id": "patchwise-token", "description": "Patchwise token (pwt_…)", "password": true }],
  "servers": {
    "patchwise": {
      "type": "http",
      "url": "https://<host>/mcp",
      "headers": { "Authorization": "Bearer ${input:patchwise-token}" }
    }
  }
}

Cursor

~/.cursor/mcp.json, with PATCHWISE_TOKEN set in your environment:

{
  "mcpServers": {
    "patchwise": {
      "url": "https://<host>/mcp",
      "headers": { "Authorization": "Bearer ${env:PATCHWISE_TOKEN}" }
    }
  }
}

Microsoft Copilot Studio

  1. In the agent, go to Tools > Add a tool > New tool > Model Context Protocol.
  2. Set the server URL to https://<host>/mcp.
  3. Choose API key authentication, put it in a header named Authorization, and give the value Bearer pwt_… when the connection is created.

Copilot Studio acts as the token's owner for everyone who uses that agent, so use a read token made by an account with the least role needed. Phase 2 removes this limitation.

Transport details

  • Transport. Streamable HTTP, stateless: POST /mcp with a JSON-RPC message or a batch of up to 20, answered as application/json. GET and DELETE return 405 (no server-sent stream, no session).
  • Methods and protocol versions. initialize, ping, tools/list and tools/call are supported. Protocol versions 2025-06-18, 2025-03-26 and 2024-11-05 are accepted.
  • Errors.
    • No valid token: 401 with WWW-Authenticate: Bearer.
    • Body over 64 KB: 413.
    • Over the rate limit: 429.
    • A browser Origin other than Patchwise's own: 403.
    • Tool failures are returned as isError results without internals.
  • No CORS. /mcp does not open CORS, and session cookies are ignored there, so a web page cannot call it with someone's sign-in.

Phase 2 plan: OAuth

Personal tokens are simple, but each person must copy one into each client, and shared agents (Copilot Studio, claude.ai connectors) act as one account. Phase 2 adds the MCP authorization flow and keeps tokens for scripts.

  1. Advertise the authorization server. Publish protected-resource metadata (RFC 9728) at /.well-known/oauth-protected-resource, and point to it from the 401 WWW-Authenticate (resource_metadata=).
  2. Choose the authorization server.
    • Either use the existing sign-in (Supabase Auth or the built-in accounts) as an OAuth 2.1 server, with PKCE, the authorization code flow, and dynamic client registration (RFC 7591) for MCP clients.
    • Or delegate to the company IdP (Entra ID).
  3. Issue scoped, audience-bound access tokens. Scopes are patchwise.read and patchwise.act, bound to https://<host>/mcp (RFC 8707 resource indicators). Tokens last 1 hour and refresh tokens rotate. The same rule holds: the person's current role is the ceiling.
  4. Ask for consent. A consent screen names the client and the scopes. Grants appear and can be revoked next to the personal tokens.
  5. Keep the boundaries. Nothing else changes: the same tool list, propose → confirm, audit, rate limits, and no sign-off or administration.