mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-20 08:26:30 +01:00
add nostr-notes mcp server, restructure
This commit is contained in:
1
setup.py
1
setup.py
@@ -30,6 +30,7 @@ setup(
|
|||||||
"urllib3==2.2.2",
|
"urllib3==2.2.2",
|
||||||
"networkx==3.3",
|
"networkx==3.3",
|
||||||
"scipy==1.13.1",
|
"scipy==1.13.1",
|
||||||
|
"typer==0.15.1",
|
||||||
"beautifulsoup4==4.12.3"
|
"beautifulsoup4==4.12.3"
|
||||||
],
|
],
|
||||||
keywords=['nostr', 'nip90', 'dvm', 'data vending machine'],
|
keywords=['nostr', 'nip90', 'dvm', 'data vending machine'],
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ async def nostr_client():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
env_path = Path('../.env')
|
env_path = Path('../../.env')
|
||||||
if env_path.is_file():
|
if env_path.is_file():
|
||||||
print(f'loading environment from {env_path.resolve()}')
|
print(f'loading environment from {env_path.resolve()}')
|
||||||
dotenv.load_dotenv(env_path, verbose=True, override=True)
|
dotenv.load_dotenv(env_path, verbose=True, override=True)
|
||||||
@@ -9,6 +9,19 @@
|
|||||||
"args": [
|
"args": [
|
||||||
"../../mcp-crypto-price/build/index.js"
|
"../../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
|
import dotenv
|
||||||
|
|
||||||
from nostr_dvm.framework import DVMFramework
|
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.admin_utils import AdminConfig
|
||||||
from nostr_dvm.utils.dvmconfig import build_default_config
|
from nostr_dvm.utils.dvmconfig import build_default_config
|
||||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||||
@@ -35,7 +35,7 @@ def playground(announce=False):
|
|||||||
|
|
||||||
# MCP CONFIG
|
# MCP CONFIG
|
||||||
config_path = str(Path.absolute(Path(__file__).parent / "mcp_server_config.json"))
|
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))
|
tools = asyncio.run(get_tools(config_path, server_names))
|
||||||
@@ -95,9 +95,9 @@ def playground(announce=False):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
env_path = Path('../.env')
|
env_path = Path('../../.env')
|
||||||
if not env_path.is_file():
|
if not env_path.is_file():
|
||||||
with open('../.env', 'w') as f:
|
with open('../../.env', 'w') as f:
|
||||||
print("Writing new .env file")
|
print("Writing new .env file")
|
||||||
f.write('')
|
f.write('')
|
||||||
if env_path.is_file():
|
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
|
||||||
|
|
||||||
Reference in New Issue
Block a user