Skip to content

MCPTrustFramework/MCPF-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MCPF Python SDK

License: MIT Python 3.11+ PyPI Documentation

Complete Python SDK for MCPF - Unified interface to all MCPF Trust Framework components: DID/VC, ANS, MCP Registry, and A2A delegation.

🌟 What is MCPF-python?

The MCPF Python SDK provides a unified, Pythonic interface to the entire MCPF Trust Framework:

from mcpf import MCPF

# Initialize SDK
mcpf = MCPF(
    ans_url="https://ans.veritrust.vc",
    registry_url="https://ans.veritrust.vc/mcp",
    a2a_url="https://a2a.example.com"
)

# Resolve agent name β†’ verify credentials β†’ check delegation β†’ execute
agent = await mcpf.resolve_and_verify("fraud-detector.risk.bank.example.agent")
if await mcpf.can_delegate(agent.did, target_did, "analyze"):
    result = await execute_task(agent, target_did, task_data)

Features

  • πŸ” DID/VC Management - Create DIDs, issue/verify credentials, manage revocation
  • πŸ“› ANS Client - Resolve agent names, register agents, search directory
  • πŸ“‹ MCP Registry - Discover trusted MCP servers, verify credentials
  • πŸ”„ A2A Delegation - Check delegation permissions, manage policies
  • βœ… Complete Verification - End-to-end credential and policy validation
  • ⚑ Async/Await - Modern async Python with httpx
  • 🎯 Type Hints - Full type annotations for better IDE support
  • πŸ§ͺ Well Tested - Comprehensive test suite with >90% coverage

πŸš€ Quick Start

Installation

pip install mcpf-python

Basic Usage

from mcpf import MCPF

# Initialize
mcpf = MCPF()

# Resolve an agent name
agent = await mcpf.ans.resolve("fraud-detector.risk.bank.example.agent")
print(f"Agent DID: {agent.did}")
print(f"Capabilities: {agent.capabilities}")

# Verify agent credential
is_valid = await mcpf.did.verify_credential(agent.credential_url)
print(f"Credential valid: {is_valid}")

# Check delegation permission
can_delegate = await mcpf.a2a.check_delegation(
    from_did="did:web:agent1.example",
    to_did="did:web:agent2.example",
    action="analyze"
)
print(f"Delegation allowed: {can_delegate.allowed}")

πŸ“– API Reference

MCPF Client (Unified Interface)

from mcpf import MCPF

mcpf = MCPF(
    ans_url="https://ans.veritrust.vc",
    registry_url="https://ans.veritrust.vc/mcp",
    a2a_url="https://a2a.example.com",
    did_resolver_url="https://resolver.example.com"
)

# Unified operations
agent = await mcpf.resolve_and_verify(agent_name)
can_delegate = await mcpf.can_delegate(from_did, to_did, action)
server = await mcpf.find_mcp_server(capability="weather")

DID/VC Module

from mcpf.did import DIDManager, VCIssuer, VCVerifier

# DID operations
did_manager = DIDManager()
did = did_manager.create_did(method="web", domain="example.com")
did_doc = await did_manager.resolve_did(did)

# Issue credentials
issuer = VCIssuer(
    issuer_did="did:web:veritrust.vc",
    private_key=private_key
)
credential = issuer.issue_credential(
    subject_did="did:web:agent.example",
    credential_type="AgentOwnershipCredential",
    claims={"permissions": ["query", "analyze"]}
)

# Verify credentials
verifier = VCVerifier()
result = await verifier.verify_credential(credential)
print(f"Valid: {result.valid}")
print(f"Revoked: {result.is_revoked}")

ANS Module

from mcpf.ans import ANSClient

ans = ANSClient("https://ans.veritrust.vc")

# Resolve agent name
agent_card = await ans.resolve(
    name="fraud-detector.risk.bank.example.agent",
    version="1.0.0"  # Optional
)

# Register agent
await ans.register(
    name="my-agent.company.example.agent",
    version="1.0.0",
    did="did:web:company.example:agent:my-agent",
    provider="My Company",
    capabilities=["query", "analyze"],
    endpoints={
        "agent": "https://company.example/agent",
        "presentations": "https://company.example/agent/vp"
    }
)

# Search agents
results = await ans.search(capability="fraud-detection")

MCP Registry Module

from mcpf.registry import MCPRegistry

registry = MCPRegistry("https://ans.veritrust.vc/mcp")

# List MCP servers
servers = await registry.list_servers(page=1, limit=50)

# Get server by DID
server = await registry.get_server("did:web:weather.example.com:mcp:api")

# Search by capability
weather_servers = await registry.search(capability="getCurrentWeather")

# Register MCP server
await registry.register_server(
    did="did:web:myapi.example.com:mcp",
    endpoint="https://myapi.example.com/mcp",
    manifest="https://myapi.example.com/mcp/manifest.json",
    credentials=[...],
    metadata={
        "capabilities": ["query", "analyze"],
        "organization": "My Company",
        "country": "US"
    }
)

A2A Module

from mcpf.a2a import A2ARegistry

a2a = A2ARegistry("https://a2a.example.com")

# Check delegation permission
result = await a2a.check_delegation(
    from_did="did:web:fraud-detector.bank.example",
    to_did="did:web:risk-analyzer.bank.example",
    action="analyze"
)

if result.allowed:
    print(f"Delegation allowed: {result.policy}")
else:
    print(f"Delegation denied: {result.reason}")

# Register delegation policy
policy = await a2a.register_policy(
    from_agent="did:web:agent1.example",
    to_agent="did:web:agent2.example",
    allowed_actions=["query", "analyze"],
    constraints={
        "maxDuration": 3600,
        "scope": ["transaction-data"]
    },
    issued_by="did:web:example.com",
    valid_from="2025-01-01T00:00:00Z",
    valid_until="2026-01-01T00:00:00Z"
)

# Get audit log
audit = await a2a.get_audit_log(
    from_did="did:web:agent1.example",
    start_date="2025-01-01"
)

πŸ“ Complete Examples

Example 1: End-to-End Agent Verification

import asyncio
from mcpf import MCPF

async def verify_agent_chain():
    mcpf = MCPF(
        ans_url="https://ans.veritrust.vc",
        registry_url="https://ans.veritrust.vc/mcp"
    )
    
    # 1. Resolve agent name to DID
    agent = await mcpf.ans.resolve("fraud-detector.risk.bank.example.agent")
    print(f"βœ“ Resolved: {agent.name} β†’ {agent.did}")
    
    # 2. Get DID document
    did_doc = await mcpf.did.resolve_did(agent.did)
    print(f"βœ“ DID Document: {len(did_doc.verification_method)} keys")
    
    # 3. Verify agent credential
    verification = await mcpf.did.verify_credential_url(agent.credential_url)
    print(f"βœ“ Credential valid: {verification.valid}")
    print(f"βœ“ Not revoked: {not verification.is_revoked}")
    
    # 4. Check all verifications passed
    if verification.valid and not verification.is_revoked:
        print("βœ… Agent fully verified!")
        return agent
    else:
        print("❌ Agent verification failed")
        return None

asyncio.run(verify_agent_chain())

Example 2: Delegation Workflow

import asyncio
from mcpf import MCPF

async def delegation_workflow():
    mcpf = MCPF(
        ans_url="https://ans.veritrust.vc",
        a2a_url="https://a2a.example.com"
    )
    
    # Resolve both agents
    from_agent = await mcpf.ans.resolve("fraud-detector.risk.bank.example.agent")
    to_agent = await mcpf.ans.resolve("risk-analyzer.analytics.bank.example.agent")
    
    # Verify both agents
    from_valid = await mcpf.did.verify_agent(from_agent.did)
    to_valid = await mcpf.did.verify_agent(to_agent.did)
    
    if not (from_valid and to_valid):
        print("❌ Agent verification failed")
        return
    
    # Check delegation permission
    delegation = await mcpf.a2a.check_delegation(
        from_did=from_agent.did,
        to_did=to_agent.did,
        action="analyze"
    )
    
    if delegation.allowed:
        print(f"βœ… Delegation allowed")
        print(f"   Policy: {delegation.policy.id}")
        print(f"   Constraints: {delegation.policy.constraints}")
        
        # Execute delegation
        result = await execute_analysis(from_agent, to_agent, data)
        print(f"βœ… Task completed: {result}")
    else:
        print(f"❌ Delegation denied: {delegation.reason}")

asyncio.run(delegation_workflow())

Example 3: MCP Server Discovery

import asyncio
from mcpf import MCPF

async def find_weather_server():
    mcpf = MCPF(registry_url="https://ans.veritrust.vc/mcp")
    
    # Search for weather servers
    servers = await mcpf.registry.search(
        capability="getCurrentWeather",
        country="US"
    )
    
    print(f"Found {len(servers.items)} weather servers:")
    
    for server in servers.items:
        print(f"\n  Server: {server.did}")
        print(f"  Endpoint: {server.endpoint}")
        print(f"  Organization: {server.metadata.organization}")
        print(f"  Capabilities: {', '.join(server.metadata.capabilities)}")
        
        # Verify server credential
        if server.credentials:
            cred = server.credentials[0]
            verification = await mcpf.did.verify_credential_url(cred.credential_url)
            print(f"  Verified: {'βœ“' if verification.valid else 'βœ—'}")

asyncio.run(find_weather_server())

Example 4: Complete Integration

import asyncio
from mcpf import MCPF

async def complete_workflow():
    """Complete MCPF workflow: resolve β†’ verify β†’ check delegation β†’ execute"""
    
    mcpf = MCPF(
        ans_url="https://ans.veritrust.vc",
        registry_url="https://ans.veritrust.vc/mcp",
        a2a_url="https://a2a.example.com"
    )
    
    # 1. Resolve agent names
    print("1️⃣  Resolving agent names...")
    from_agent = await mcpf.ans.resolve("fraud-detector.risk.bank.example.agent")
    to_agent = await mcpf.ans.resolve("risk-analyzer.analytics.bank.example.agent")
    
    # 2. Verify credentials
    print("2️⃣  Verifying credentials...")
    from_valid = await mcpf.did.verify_agent(from_agent.did)
    to_valid = await mcpf.did.verify_agent(to_agent.did)
    
    if not (from_valid and to_valid):
        print("❌ Credential verification failed")
        return
    
    # 3. Check if MCP server is registered (if using MCP)
    print("3️⃣  Checking MCP registry...")
    try:
        mcp_server = await mcpf.registry.get_server(to_agent.did)
        print(f"   βœ“ MCP server registered: {mcp_server.endpoint}")
    except:
        print("   ℹ️  Not an MCP server")
    
    # 4. Check delegation permission
    print("4️⃣  Checking delegation permission...")
    delegation = await mcpf.a2a.check_delegation(
        from_did=from_agent.did,
        to_did=to_agent.did,
        action="analyze"
    )
    
    if not delegation.allowed:
        print(f"❌ Delegation denied: {delegation.reason}")
        return
    
    print(f"   βœ“ Delegation allowed (policy: {delegation.policy.id})")
    
    # 5. Execute task
    print("5️⃣  Executing task...")
    result = {
        "from_agent": from_agent.name,
        "to_agent": to_agent.name,
        "action": "analyze",
        "status": "success"
    }
    
    print("βœ… Workflow complete!")
    return result

asyncio.run(complete_workflow())

πŸ§ͺ Testing

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# With coverage
pytest --cov=mcpf_python --cov-report=html

# Type checking
mypy mcpf_python

# Linting
ruff check mcpf_python

πŸ“š Documentation

Full documentation available at https://mcpf.dev/docs/python

πŸ”§ Configuration

Environment Variables

# ANS endpoint
MCPF_ANS_URL=https://ans.veritrust.vc

# MCP Registry endpoint
MCPF_REGISTRY_URL=https://ans.veritrust.vc/mcp

# A2A Registry endpoint
MCPF_A2A_URL=https://a2a.example.com

# DID Resolver
MCPF_DID_RESOLVER_URL=https://resolver.example.com

# Timeouts
MCPF_TIMEOUT=30

Programmatic Configuration

from mcpf import MCPF, MCPFConfig

config = MCPFConfig(
    ans_url="https://ans.veritrust.vc",
    registry_url="https://ans.veritrust.vc/mcp",
    a2a_url="https://a2a.example.com",
    timeout=30,
    verify_ssl=True
)

mcpf = MCPF(config=config)

🀝 Contributing

See CONTRIBUTING.md for guidelines.

πŸ“ License

MIT License - see LICENSE

πŸ“ž Contact

πŸ”— Related Projects


Version: 1.0.0-alpha
Last Updated: December 31, 2025
Status: Production-ready

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages