mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-03-17 13:21:48 +01:00
add nostr-notes mcp server, restructure
This commit is contained in:
parent
700ad2abf7
commit
722ebf8d1b
1
setup.py
1
setup.py
@ -30,6 +30,7 @@ setup(
|
||||
"urllib3==2.2.2",
|
||||
"networkx==3.3",
|
||||
"scipy==1.13.1",
|
||||
"typer==0.15.1",
|
||||
"beautifulsoup4==4.12.3"
|
||||
],
|
||||
keywords=['nostr', 'nip90', 'dvm', 'data vending machine'],
|
||||
|
@ -127,7 +127,7 @@ async def nostr_client():
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
env_path = Path('../.env')
|
||||
env_path = Path('../../.env')
|
||||
if env_path.is_file():
|
||||
print(f'loading environment from {env_path.resolve()}')
|
||||
dotenv.load_dotenv(env_path, verbose=True, override=True)
|
@ -9,6 +9,19 @@
|
||||
"args": [
|
||||
"../../mcp-crypto-price/build/index.js"
|
||||
]
|
||||
},
|
||||
"nostr-notes": {
|
||||
"command": "uv",
|
||||
"args": [
|
||||
"run",
|
||||
"--with",
|
||||
"mcp[cli]",
|
||||
"--with",
|
||||
"nostr_sdk==0.39.0",
|
||||
"mcp",
|
||||
"run",
|
||||
"tests/mcp/mcp-servers/nostr-notes/server.py"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ from pathlib import Path
|
||||
import dotenv
|
||||
|
||||
from nostr_dvm.framework import DVMFramework
|
||||
from nostr_dvm.tasks.mcpbridge import MCPBridge
|
||||
from tests.mcp.dvm.mcpbridge import MCPBridge
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.dvmconfig import build_default_config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
@ -35,7 +35,7 @@ def playground(announce=False):
|
||||
|
||||
# MCP CONFIG
|
||||
config_path = str(Path.absolute(Path(__file__).parent / "mcp_server_config.json"))
|
||||
server_names = ["mcp-crypto-price"]
|
||||
server_names = ["mcp-crypto-price", "nostr-notes"]
|
||||
|
||||
|
||||
tools = asyncio.run(get_tools(config_path, server_names))
|
||||
@ -95,9 +95,9 @@ def playground(announce=False):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
env_path = Path('../.env')
|
||||
env_path = Path('../../.env')
|
||||
if not env_path.is_file():
|
||||
with open('../.env', 'w') as f:
|
||||
with open('../../.env', 'w') as f:
|
||||
print("Writing new .env file")
|
||||
f.write('')
|
||||
if env_path.is_file():
|
0
tests/mcp/mcp-servers/nostr-notes/__init__.py
Normal file
0
tests/mcp/mcp-servers/nostr-notes/__init__.py
Normal file
41
tests/mcp/mcp-servers/nostr-notes/server.py
Normal file
41
tests/mcp/mcp-servers/nostr-notes/server.py
Normal file
@ -0,0 +1,41 @@
|
||||
import re
|
||||
from datetime import timedelta
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
|
||||
mcp = FastMCP("Nostr", description="Get notes from Nostr for a given key", dependencies=["nostr_sdk==0.39.0"])
|
||||
|
||||
@mcp.tool()
|
||||
async def get_nostr_notes(npub: str, limit: int) -> str:
|
||||
from nostr_sdk import Client, Keys, NostrSigner, Filter, Kind, PublicKey
|
||||
|
||||
keys = Keys.parse("e318cb3e6ac163814dd297c2c7d745faacfbc2a826eb4f6d6c81430426a83c2b")
|
||||
client = Client(NostrSigner.keys(keys))
|
||||
|
||||
relay_list = ["wss://relay.damus.io",
|
||||
"wss://nostr.oxtr.dev",
|
||||
"wss://relay.primal.net",
|
||||
]
|
||||
|
||||
for relay in relay_list:
|
||||
await client.add_relay(relay)
|
||||
|
||||
|
||||
await client.connect()
|
||||
|
||||
f = Filter().kind(Kind(1)).author(PublicKey.parse(npub)).limit(limit)
|
||||
events = await client.fetch_events(f, timedelta(5))
|
||||
|
||||
index = 1
|
||||
notes = ""
|
||||
for event in events.to_vec():
|
||||
try:
|
||||
pattern = r"[^a-zA-Z0-9\s.!?:,-/]"
|
||||
cleaned_string = re.sub(pattern, "", event.content())
|
||||
notes = notes + str(index) + ". " + cleaned_string + "\n"
|
||||
index += 1
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
return notes
|
||||
|
Loading…
x
Reference in New Issue
Block a user