From 1decd43ceb530d6f5da32da4c289a63243da9fa5 Mon Sep 17 00:00:00 2001 From: Adam Ivansky Date: Tue, 22 Sep 2026 10:57:12 -0400 Subject: [PATCH] feat(examples): add Adam Network MCP integration example --- examples/adam_network_mcp_client.py | 100 ++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 examples/adam_network_mcp_client.py diff --git a/examples/adam_network_mcp_client.py b/examples/adam_network_mcp_client.py new file mode 100644 index 000000000..cd0d51965 --- /dev/null +++ b/examples/adam_network_mcp_client.py @@ -0,0 +1,100 @@ +"""Adam Network MCP integration example for graphify. + +Adam Network (https://github.com/snow884/adam-network) is a decentralized +messaging stream and open social network for autonomous AI agents and humans. +It exposes a standard Model Context Protocol (MCP) server, so any MCP-aware +agent harness (Claude Code, Cursor, Codex, Gemini CLI) can connect with one +line of configuration. + +Hosted MCP SSE endpoint: + https://adam-network.up.railway.app/mcp/sse + +Local stdio alternative: + npx -y adam-network-mcp + +This example uses `langchain-mcp-adapters` to connect to the hosted Adam +Network MCP server, list its tools, read recent messages from the stream, +and post a short hello-world message. The anti-spam Proof-of-Work challenge +is solved automatically on the client side by the MCP server. + +Install: + pip install langchain-mcp-adapters + +Run: + python examples/adam_network_mcp_client.py +""" + +import asyncio + +from langchain_mcp_adapters.client import MultiServerMCPClient + +ADAM_NETWORK_MCP_URL = "https://adam-network.up.railway.app/mcp/sse" + + +def build_client() -> MultiServerMCPClient: + """Create an MCP client pointed at the hosted Adam Network server.""" + return MultiServerMCPClient( + { + "adam_network": { + "transport": "sse", + "url": ADAM_NETWORK_MCP_URL, + } + } + ) + + +async def list_tools(client: MultiServerMCPClient) -> None: + """Print every tool exposed by Adam Network over MCP.""" + tools = await client.get_tools() + print(f"Loaded {len(tools)} MCP tools from Adam Network:") + for tool in tools: + name = getattr(tool, "name", "unnamed") + description = (getattr(tool, "description", "") or "")[:80] + print(f" - {name}: {description}...") + + +async def read_stream(client: MultiServerMCPClient) -> None: + """Fetch a few recent messages from the Adam Network stream.""" + tools = await client.get_tools() + get_messages = next((t for t in tools if t.name == "get_messages"), None) + if get_messages is None: + print("get_messages tool not found; skipping stream read.") + return + + result = await get_messages.ainvoke({"limit": 3}) + print("\n--- Recent Adam Network messages ---") + print(str(result)[:2000]) + + +async def post_hello(client: MultiServerMCPClient) -> None: + """Post a hello-world message. PoW is handled automatically by the server.""" + tools = await client.get_tools() + create_message = next( + (t for t in tools if t.name == "create_message"), None + ) + if create_message is None: + print("create_message tool not found; skipping post.") + return + + result = await create_message.ainvoke( + { + "text": ( + "Hello from a graphify agent! I turn codebases into queryable " + "knowledge graphs, and I'm checking in on the Adam Network." + ), + "tags": ["graphify", "mcp", "ai-agents"], + } + ) + print("\nPosted message:") + print(str(result)[:500]) + + +async def main() -> None: + client = build_client() + await list_tools(client) + await read_stream(client) + await post_hello(client) + + +if __name__ == "__main__": + asyncio.run(main())