A cryptographic protocol for ensuring the integrity and authenticity of tool schemas used by AI agents. SchemaPin prevents "MCP Rug Pull" attacks by enabling developers to cryptographically sign their tool schemas and allowing clients to verify that schemas have not been altered since publication.
SchemaPin provides a robust defense against supply-chain attacks where benign schemas are maliciously replaced after being approved. The protocol uses:
ECDSA P-256 signatures for cryptographic verification
SHA-256 hashing for schema integrity
Trust-On-First-Use (TOFU) key pinning for ongoing security
RFC 8615 .well-known URIs for public key discovery
✅ Strong Security: ECDSA P-256 signatures with SHA-256 hashing
✅ Cross-Language Support: Python and JavaScript implementations
✅ Simple Integration: High-level APIs for both developers and clients
✅ Standard Compliance: Follows RFC 8615 for key discovery
✅ Comprehensive Testing: Full test suite with security validation
flowchart TD
A[Tool Developer] -->|Publishes| B["/.well-known/schemapin.json (Public Key)"]
A -->|Signs| C["Tool Schema + Signature"]
subgraph "AI Agent"
D["Fetch Schema + Signature"]
E["Fetch or Cache Public Key"]
F["Verify Signature"]
G{"Signature Valid?"}
H["Accept & Use Tool Schema"]
I["Reject / Block Tool"]
end
C --> D
B --> E
D --> F
E --> F
F --> G
G -- Yes --> H
G -- No --> I
Loading
For Tool Developers (Signing Schemas)
fromschemapin.utilsimportSchemaSigningWorkflow, create_well_known_responsefromschemapin.cryptoimportKeyManager# Generate key pairprivate_key, public_key=KeyManager.generate_keypair()
private_key_pem=KeyManager.export_private_key_pem(private_key)
# Sign your tool schemaworkflow=SchemaSigningWorkflow(private_key_pem)
schema= {
"name": "calculate_sum",
"description": "Calculates the sum of two numbers",
"parameters": {
"type": "object",
"properties": {
"a": {"type": "number", "description": "First number"},
"b": {"type": "number", "description": "Second number"}
},
"required": ["a", "b"]
}
}
signature=workflow.sign_schema(schema)
print(f"Signature: {signature}")
For AI Clients (Verifying Schemas)
fromschemapin.utilsimportSchemaVerificationWorkflow# Initialize verificationworkflow=SchemaVerificationWorkflow()
# Verify schema (auto-pins key on first use)result=workflow.verify_schema(
schema=schema,
signature_b64=signature,
tool_id="example.com/calculate_sum",
domain="example.com",
auto_pin=True
)
ifresult['valid']:
print("✅ Schema signature is valid")
# Safe to use the toolelse:
print("❌ Schema signature is invalid")
# Reject the tool
cd python
pip install -e .
cd javascript
npm install
# Clone repository
git clone https://github.com/thirdkey/schemapin.git
cd schemapin
# Set up Python environment
python3 -m venv .venv
source .venv/bin/activate
pip install -r python/requirements.txt
# Install Python package in development modecd python
pip install -e .# Run Python tests
python -m pytest tests/ -v
# Run JavaScript testscd ../javascript
npm test
# Run tool developer examplecd python/examples
python tool_developer.py
# Run client verification example
python client_verification.py