Skip to content

Feat/mcp python sdk - #1

Open
bondarchukb wants to merge 10 commits into
masterfrom
feat/mcp-python-sdk
Open

Feat/mcp python sdk#1
bondarchukb wants to merge 10 commits into
masterfrom
feat/mcp-python-sdk

Conversation

@bondarchukb

Copy link
Copy Markdown
Collaborator

No description provided.

Bohdan Bondarchuk and others added 10 commits March 21, 2026 14:56
- agentflow Python package: types, exceptions, voucher signing, AgentflowClient
- Voucher CBOR encoding matches TypeScript implementation byte-for-byte
- Simulation mode for demo without live ICP canister
- FastMCP server exposing 7 tools: setup_identity, call_canister,
  request_session_intent, open_session, session_call, close_session,
  get_session_status, approve_icrc2 (stub)
- end-to-end demo script (examples/demo.py)
- pip install -e python/ then agentflow-mcp to run

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…content tool

- Rename package agentflow → ic402, env vars AGENTFLOW_* → IC402_*
- Add content delivery types: ContentRef, AccessGrant, DeliveryMethod,
  ContentDelivery, ContentEntry (mirrors new src/ic402/Types.mo)
- Add fetch_content MCP tool supporting inline, httpUrl, assetCanister,
  and canisterQuery delivery methods (matches integration/mcp fetch_content)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Exposes ic402 payment tools via Gradio's MCP interface.
Tools: setup_identity, request_session_intent, open_session,
session_query, close_session, get_sessions, fetch_content.

Connect to Claude Desktop:
  { "mcpServers": { "ic402": { "url": "http://localhost:7860/gradio_api/mcp/sse" } } }

Run: python python/gradio_mcp.py --simulation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ister calls

- icp.yaml: fix init_args syntax for icp-cli v0.2.1 (path object form)
- main.mo: swap mainnet ckUSDC address for local ledger canister ID so
  openSession / getContent work against the local replica
- gradio_mcp.py: pin server_port=7861, fix MCP endpoint URL in docs
- client.py: multiple ic-py compatibility fixes:
  · Replace removed BasicIdentity with Identity(privkey=hex, type='ed25519')
  · update_raw now returns pre-decoded list — remove stale decode() call
  · Add _remap_fields() to translate hashed Candid field IDs (_1234) back
    to human-readable names (network, token, suggestedDeposit, etc.)
  · Add _candid_open_session() — typed Record encoding for SessionConfig
    and PaymentSignature (ic-py encode requires explicit type objects)
  · Add _candid_session_query() — typed Voucher record + Text encoding
  · Add _candid_text_call() — single Text arg helper used by endSession
  · Use [] instead of None for Opt null values in ic-py record encoding

All five MCP tools verified live against local ICP replica:
setup_identity → request_session_intent → open_session →
session_query (×N, voucher-signed) → get_sessions ✓

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Covers installation, quickstart, full API reference for AgentflowClient
and SessionHandle, all types and exceptions, MCP server setup (FastMCP
+ Gradio), Claude Desktop integration, voucher crypto, simulation mode,
and known limitations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
6 sections: identity setup, charge flow (402), budget guard,
voucher signing (CBOR + Ed25519 verification), session flow
(escrow + 5 streaming vouchers + receipt), content delivery types.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tabs: charge flow (402 + budget guard), voucher signing
(Ed25519 + CBOR verification), session flow (open/query/close
with live balance meter), activity log.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tabs were hidden when identity wasn't configured because st.stop()
prevented further rendering. Now shows an info message only, keeping
all four demo tabs accessible at all times.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
vhew added a commit that referenced this pull request Jun 18, 2026
…action hardening

Closes the recoverability/observability CORE of the #1 production blocker from the
readiness assessment: after the B2 fix, an outbound EVM settle/refund/close that
returns #pending/#reverted/#err parks the job (#Settling) / session (#closing) with
no remedy and invisible to the operator. Everything here is read-only or
state-transition-only -- no new broadcasts, no double-pay surface.

Observability (NEW-4):
- main.mo health() [controller]: cycle balance + job/session status counts; watch
  jobs.settling / sessions.closing for funds parked mid-settlement.
- main.mo listJobs(serviceId, ?status) [controller].
- ServiceRegistry.jobCounts / Sessions.sessionCounts / Gateway passthrough.

Manual recovery escape hatch (state assertion only -- moves NO funds; the operator
verifies the on-chain outcome, then unsticks the record so it stops pinning memory
and is GC-eligible):
- ServiceRegistry.resolveJob(jobId, terminal): #Settling -> #Settled/#Refunded/#Expired.
- Sessions.forceResolveSession(sessionId): #closing -> #closed.
- Exposed controller-only from main.mo.

Hardening:
- SEC-1 (partial): wire policy.gcRateLimit() into the hourly timer (it existed but was
  never called -> rateLimitLog grew unbounded under attacker-minted payer principals).
- SEC-4: getPolicyConfig redacts allowedCallers/blockedCallers (public query no longer
  leaks the access-control roster).

Still TODO (designed; money-path / stable-refactor -- next focused pass): auto
confirm-only reconcile (persist parked tx hash + re-poll), sweepEvm, pre-settle
cycle-balance guard, confirmation depth, 2-provider RPC resilience. B1 marked WAIVED.
See docs/production-readiness.md.

Verified: example compiles (96 locals, installable); .did regenerated; 16 mops + 72
client + 89 root tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant