Skip to content

Commit 0e1002d

Browse files
committed
feat: add mcp serve and http client api
1 parent 399b95d commit 0e1002d

File tree

3 files changed

+233
-153
lines changed

3 files changed

+233
-153
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python3
2+
"""Working FastMCP Client"""
3+
4+
import asyncio
5+
6+
from fastmcp import Client
7+
8+
9+
async def main():
10+
"""Main function using FastMCP Client"""
11+
12+
print("Working FastMCP Client")
13+
print("=" * 40)
14+
15+
async with Client("http://127.0.0.1:9003/mcp") as client:
16+
print("Connected to MOS MCP server!")
17+
18+
print("Available tools:")
19+
tools = await client.list_tools()
20+
for tool in tools:
21+
print("**" * 20)
22+
print(f" - {tool.name}: {tool.description}")
23+
24+
print("Available resources:")
25+
resources = await client.list_resources()
26+
for resource in resources:
27+
print(f" - {resource.uri}: {resource.description}")
28+
29+
print("Testing tool calls...")
30+
31+
print(" Getting user info...")
32+
result = await client.call_tool("get_user_info", {})
33+
print(f" Result: {result.content[0].text}")
34+
35+
print(" Creating user...")
36+
result = await client.call_tool(
37+
"create_user",
38+
{"user_id": "fastmcp_user", "role": "USER", "user_name": "FastMCP Test User"},
39+
)
40+
print(f"Result: {result.content[0].text}")
41+
42+
print(" register cube...")
43+
result = await client.call_tool(
44+
"register_cube",
45+
{
46+
"cube_name_or_path": "cube_default_user",
47+
"user_id": "fastmcp_user",
48+
"cube_id": "fastmcp_user",
49+
},
50+
)
51+
print(f" Result: {result}")
52+
53+
print(" Adding memory...")
54+
result = await client.call_tool(
55+
"add_memory",
56+
{
57+
"memory_content": "This is a test memory from FastMCP client.",
58+
"cube_id": "fastmcp_user",
59+
"user_id": "fastmcp_user",
60+
},
61+
)
62+
print(f" Result: {result.content[0].text}")
63+
64+
print(" Searching memories...")
65+
result = await client.call_tool(
66+
"search_memories", {"query": "test memory", "user_id": "fastmcp_user"}
67+
)
68+
print(f" Result: {result.content[0].text[:200]}...")
69+
70+
print(" Testing chat...")
71+
result = await client.call_tool(
72+
"chat", {"query": "Hello! Tell me about yourself.", "user_id": "fastmcp_user"}
73+
)
74+
print(f" Result: {result.content[0].text[:200]}...")
75+
76+
77+
if __name__ == "__main__":
78+
asyncio.run(main())

0 commit comments

Comments
 (0)