examples/simple_client.py
| 1 | """ |
| 2 | Simple PQC MCP Client Example |
| 3 | |
| 4 | Connects to a PQC MCP server, performs handshake, |
| 5 | and calls a tool with ML-DSA signed messages. |
| 6 | """ |
| 7 | |
| 8 | import asyncio |
| 9 | |
| 10 | from quantumshield.identity.agent import AgentIdentity |
| 11 | |
| 12 | from pqc_mcp_transport import PQCMCPClient |
| 13 | |
| 14 | |
| 15 | async def main() -> None: |
| 16 | # Create agent identity |
| 17 | agent = AgentIdentity.create("example-client", capabilities=["tools:call"]) |
| 18 | print(f"Client DID: {agent.did}") |
| 19 | |
| 20 | # Connect to server with PQC handshake |
| 21 | client = PQCMCPClient( |
| 22 | identity=agent, |
| 23 | server_url="http://localhost:8080", |
| 24 | ) |
| 25 | |
| 26 | try: |
| 27 | session = await client.connect() |
| 28 | print(f"Connected! Session: {session.session_id}") |
| 29 | print(f"Server DID: {session.peer_did}") |
| 30 | |
| 31 | # Call a tool — request is automatically signed with ML-DSA |
| 32 | result = await client.call_tool("greet", {"name": "World"}) |
| 33 | print(f"Result: {result}") |
| 34 | print(f"Response verified: {client.session.last_response_verified}") |
| 35 | |
| 36 | # Show audit log |
| 37 | for entry in session.get_audit_log(): |
| 38 | print( |
| 39 | f" [{entry.timestamp}] {entry.operation}: " |
| 40 | f"{entry.method} verified={entry.verified}" |
| 41 | ) |
| 42 | finally: |
| 43 | await client.close() |
| 44 | |
| 45 | |
| 46 | if __name__ == "__main__": |
| 47 | asyncio.run(main()) |
| 48 | |