File size: 959 Bytes
e2623bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""API + MCP connection examples (offline-safe; MCP part is illustrative)."""
from __future__ import annotations
import json, urllib.request

OLLAMA_HOST = "http://localhost:11434"
MODEL = "qwen2.5:0.5b"

# 1) Direct Ollama HTTP API, proof_id attached (never the credential):
proof_id = "afx_demo1234"
body = json.dumps({"model": MODEL, "prompt": "say hi\n[proof_id=%s]" % proof_id,
                   "stream": False}).encode()
req = urllib.request.Request(OLLAMA_HOST + "/api/generate", data=body,
                             headers={"Content-Type": "application/json"})
print("POST /api/generate -> model=%s proof_id=%s" % (MODEL, proof_id))

# 2) MCP pre-check before the model call (pseudo-flow using gate.py):
from gate import verify
decision, reason = verify("email.search", {"query": "invoice"})
print("MCP gate_tool_call(email.search) ->", decision, "-", reason)
assert decision == "allow"
print("OK - call the model only when decision == allow.")