Files
mcp-code/logic/list_usernames.ts
pablof7z 10fbca0824 feat: Add zap command for sending Bitcoin Lightning tips
- Implemented the `zap` command in the CLI to allow users to send sats to a user, event, or snippet using a NIP-60 wallet.
- Created a new `zap.ts` file to handle the command logic and integrated it into the MCP server.
- Added wallet balance command to check the balance of a user's wallet.
- Enhanced the MCP server to register the new zap command and wallet balance command.
- Introduced caching for wallets to optimize performance and reduce redundant network requests.
- Updated database schema to include snippets table for storing code snippets.
- Improved logging functionality for better debugging and tracking of operations.
- Added functionality to save snippets to the database upon retrieval.
- Updated project overview documentation to reflect new features and structure.
- Refactored existing commands and logic for better modularity and maintainability.
2025-04-08 18:10:16 +01:00

64 lines
1.8 KiB
TypeScript

import { z } from "zod";
import { ndk } from "../ndk.js";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { getAllUsers } from "../config.js";
import { NDKPrivateKeySigner } from "@nostr-dev-kit/ndk";
/**
* List all available usernames in the system
* @returns Formatted list of available usernames
*/
export async function listUsernames() {
try {
const users = await Promise.all(
Object.values(getAllUsers()).map(async (user) => {
const signer = new NDKPrivateKeySigner(user.nsec);
const npub = (await signer.user()).npub;
return {
name: user.display_name,
npub: npub,
};
})
);
if (users.length === 0) {
return {
content: [
{
type: "text" as const,
text: "No users found. Try creating a user with the create_pubkey command first.",
},
],
};
}
const usersList = users
.map((user) => `${user.name} - ${user.npub}`)
.join("\n");
return {
content: [
{
type: "text" as const,
text: `Available users (${users.length}):\n${usersList}`,
},
],
};
} catch (error: unknown) {
const errorMessage =
error instanceof Error ? error.message : String(error);
throw new Error(`Failed to list usernames: ${errorMessage}`);
}
}
export function addListUsernamesCommand(server: McpServer) {
server.tool(
"list_usernames",
"List all available usernames in the system",
{ },
async () => {
return listUsernames();
}
);
}