Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions examples/adam_network_mcp_client.py
Original file line number Diff line number Diff line change
@@ -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())