forked from MoltyCel/moltrust-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp_server.py
More file actions
77 lines (52 loc) · 2.44 KB
/
Copy pathmcp_server.py
File metadata and controls
77 lines (52 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""MolTrust MCP Server - Trust Layer tools for AI assistants"""
from mcp.server.fastmcp import FastMCP
import httpx
API_URL = "https://api.moltrust.ch"
import os
API_KEY = os.environ.get("MOLTRUST_API_KEY", "")
mcp = FastMCP("MolTrust", instructions="Trust Layer for the Agent Economy. Verify agent identities, check reputation, issue and verify W3C Verifiable Credentials.")
def _api(method, path, json=None):
headers = {"X-API-Key": API_KEY, "Content-Type": "application/json"}
if method == "GET":
r = httpx.get(API_URL + path, headers=headers, timeout=10)
else:
r = httpx.post(API_URL + path, headers=headers, json=json, timeout=10)
return r.json()
@mcp.tool()
def register_agent(display_name: str, platform: str = "moltrust") -> dict:
"""Register a new AI agent and get a W3C DID identity."""
return _api("POST", "/identity/register", {"display_name": display_name, "platform": platform})
@mcp.tool()
def verify_agent(did: str) -> dict:
"""Check if an agent DID is registered and verified."""
return _api("GET", "/identity/verify/" + did)
@mcp.tool()
def resolve_did(did: str) -> dict:
"""Resolve a DID to its document (supports did:moltrust and did:web)."""
return _api("GET", "/identity/resolve/" + did)
@mcp.tool()
def get_reputation(did: str) -> dict:
"""Get an agent's trust score and total ratings."""
return _api("GET", "/reputation/query/" + did)
@mcp.tool()
def rate_agent(from_did: str, to_did: str, score: int) -> dict:
"""Rate another agent (1-5). Builds the trust network."""
return _api("POST", "/reputation/rate", {"from_did": from_did, "to_did": to_did, "score": score})
@mcp.tool()
def issue_credential(subject_did: str, credential_type: str = "AgentTrustCredential") -> dict:
"""Issue a W3C Verifiable Credential signed with Ed25519."""
return _api("POST", "/credentials/issue", {"subject_did": subject_did, "credential_type": credential_type})
@mcp.tool()
def verify_credential(credential: dict) -> dict:
"""Verify a Verifiable Credential's Ed25519 signature and validity."""
return _api("POST", "/credentials/verify", {"credential": credential})
@mcp.tool()
def get_did_document() -> dict:
"""Get MolTrust's own W3C DID:web document."""
return _api("GET", "/.well-known/did.json")
@mcp.tool()
def health_check() -> dict:
"""Check MolTrust API status."""
return _api("GET", "/health")
if __name__ == "__main__":
mcp.run(transport="stdio")