Model Context Protocol (MCP) communication through Nostr.
Project description
Agentstr - Nostr Agent Tools
File Descriptions
1. nwc_client.py
A Python class (NWCClient) for interacting with a Nostr Wallet Connect (NWC) service to handle Lightning Network payments.
- Functionality:
- Initialize with an NWC connection string.
- List transactions (
list_tx). - Get wallet balance (
get_balance). - Create invoices (
make_invoice). - Check invoice status (
check_invoice). - Pay invoices (
try_pay_invoice). - Monitor payment success with callbacks (
on_payment_success).
- Usage: Used by other scripts to handle payment-related operations.
- Example: Create an invoice and monitor payment:
client = NWCClient(nwc_str) invoice = client.make_invoice(amt=5, desc='test') client.on_payment_success(invoice, callback=lambda: print('Payment succeeded'))
2. nostr_client.py
A core client (NostrClient) for interacting with the Nostr protocol.
- Functionality:
- Initialize with relay URLs, private key, and optional NWC string.
- Sign events with a private key.
- Manage relay connections (
get_relay_manager). - Read posts by tag (
read_posts_by_tag). - Fetch and update user metadata (
get_metadata_for_pubkey,update_metadata). - Send and listen for encrypted direct messages (
send_direct_message_to_pubkey,direct_message_listener).
- Usage: Foundation for other scripts to interact with Nostr relays.
- Example: Read posts with a specific tag:
client = NostrClient(relays, private_key) posts = client.read_posts_by_tag('mcp_tool_discovery')
3. nostr_mcp_client.py
A client (NostrMCPClient) for interacting with MCP servers over Nostr.
- Functionality:
- Initialize with a
NostrClientand MCP server public key. - List available tools (
list_tools). - Call tools with arguments, handling payments if required (
call_tool).
- Initialize with a
- Usage: Used to invoke tools (e.g., math operations, weather queries) on remote MCP servers.
- Example: Call a multiplication tool:
mcp_client = NostrMCPClient(nostr_client, server_public_key) result = mcp_client.call_tool("multiply", {"a": 69, "b": 420})
4. nostr_mcp_server.py
A server (NostrMCPServer) that exposes tools via Nostr and handles tool execution with optional payment requirements.
- Functionality:
- Initialize with a display name and
NostrClient. - Add tools with optional pricing in satoshis (
add_tool). - List available tools (
list_tools). - Execute tools based on incoming requests (
call_tool). - Handle direct messages to process tool calls and payments (
_direct_message_callback). - Start the server to listen for requests (
start).
- Initialize with a display name and
- Usage: Hosts tools like math operations and responds to client requests.
- Example: Add and run a math server:
server = NostrMCPServer("Math MCP Server", client) server.add_tool(lambda a, b: a + b, name="add") server.start()
5. nostr_agent_server.py
A server (NostrAgentServer) that integrates an external agent API with Nostr for chat-based interactions.
- Functionality:
- Initialize with an agent URL, satoshis cost, and
NostrClient. - Fetch agent information (
agent_info). - Handle chat requests with optional thread IDs (
chat). - Process direct messages, requiring payments if specified (
_direct_message_callback). - Start the server to listen for messages (
start).
- Initialize with an agent URL, satoshis cost, and
- Usage: Bridges Nostr with an external agent service.
- Example: Start an agent server:
server = NostrAgentServer(agent_url, 5, client) server.start()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nostr_agents-0.0.1.tar.gz.
File metadata
- Download URL: nostr_agents-0.0.1.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65649d0a6e2c614cdd0964d8a918ea3cf88f0e29cabf27386d7d15b98e81845e
|
|
| MD5 |
9e81c1f5e018d0113e1316b1503ef1ce
|
|
| BLAKE2b-256 |
36dec239786bb9022c343f6f468630365e8faecbf6bdecc78983fec1e23751cf
|
File details
Details for the file nostr_agents-0.0.1-py3-none-any.whl.
File metadata
- Download URL: nostr_agents-0.0.1-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2feb8f9832676a6ec1fd47237ffab711d365e96c084af8ea9574a1e32003acdd
|
|
| MD5 |
d4cd57aadaa4069dcc510445df0333a1
|
|
| BLAKE2b-256 |
8487f97b1dabe9a9e40940ad500e3ad9859d8e58f9bccc59516868f498c5ecb3
|