Sample Code & Playgrounds
Explore live test harnesses, code snippets, and delegation simulation tools for MCP-I
Sample Code & Playgrounds
Key Takeaways
- Run delegation lifecycle examples end-to-end (issue, verify, revoke)
- Use SDK-based test harnesses and simulated agent requests
- Understand how credentials, chains, and revocation interact
- Try MCP-I logic using playground scripts or interactive flows
Delegation Flow (End-to-End)
const userDid = await kyaOsClient.ensureUserHasDid("user-123");
const agentDid = "did:web:knowthat.ai:agent:concert-ticket-buyer";
const credential = await kyaOsClient.credentials.issueDelegation({
issuerDid: userDid,
subjectDid: agentDid,
scope: ["read:email"],
expiration: "2025-12-31T23:59:59Z"
});
const isValid = await kyaOsClient.verify.delegation({
credential,
subjectDid: agentDid
});
if (!isValid) {
await kyaOsClient.credentials.revoke(credential.id, {
reason: "revoked for testing"
});
}
Playground Flows (OAuth + Delegation)
const result = await kyaOsClient.sdk.oauthFlowTest({
redirectUri: "https://example.com/callback",
requestedScope: ["submit:claim"],
clientDid: "did:web:client.example"
});
Test Harness Utilities
await kyaOsClient.sdk.runTests(); // Run entire MCP-I test suite
await kyaOsClient.sdk.proxyFlowTest(); // Simulate proxy credential flow
await kyaOsClient.sdk.simulateAuthorization(); // Run delegated access scenario
Store and retrieve results:
await kyaOsClient.sdk.storeTestResult({
testId: "chain-depth-3",
status: "passed"
});
const results = await kyaOsClient.sdk.getStoredTestResults();
Chain Resolution Tools
Verify indexed credential chains:
const chain = await kyaOsClient.registry.delegation.resolveChain({
subjectDid: agentDid
});
chain.forEach(link => {
console.log("Issuer:", link.issuer, "→ Subject:", link.subject);
});
Future Playgrounds
The following tools are under development:
- Credential Builder UI
- Delegation Chain Visualizer
- Policy Rule Tester (Trust Score sandbox)