examples/simple_server.py
| 1 | """ |
| 2 | Simple PQC MCP Server Example |
| 3 | |
| 4 | Runs an MCP server that verifies PQC signatures |
| 5 | on all incoming tool calls and signs all responses. |
| 6 | """ |
| 7 | |
| 8 | import asyncio |
| 9 | |
| 10 | from quantumshield.identity.agent import AgentIdentity |
| 11 | |
| 12 | from pqc_mcp_transport import PQCMCPServer |
| 13 | |
| 14 | server_identity = AgentIdentity.create("example-server") |
| 15 | server = PQCMCPServer(identity=server_identity) |
| 16 | |
| 17 | |
| 18 | @server.tool("greet", description="Greet someone by name") |
| 19 | async def greet(name: str) -> str: |
| 20 | return f"Hello, {name}! This response is PQC-signed." |
| 21 | |
| 22 | |
| 23 | @server.tool("add", description="Add two numbers") |
| 24 | async def add(a: float, b: float) -> float: |
| 25 | return a + b |
| 26 | |
| 27 | |
| 28 | @server.tool("echo", description="Echo back the input") |
| 29 | async def echo(message: str) -> str: |
| 30 | return message |
| 31 | |
| 32 | |
| 33 | async def main() -> None: |
| 34 | print(f"Server DID: {server_identity.did}") |
| 35 | print(f"Algorithm: {server_identity.signing_keypair.algorithm.value}") |
| 36 | print("Starting PQC MCP Server on http://localhost:8080") |
| 37 | print("All responses signed with ML-DSA") |
| 38 | await server.run(host="0.0.0.0", port=8080) |
| 39 | |
| 40 | |
| 41 | if __name__ == "__main__": |
| 42 | asyncio.run(main()) |
| 43 | |