tensorus commited on
Commit
3769171
·
verified ·
1 Parent(s): dd941b9

Upload 3 files

Browse files
mcp_client_app.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import json
3
+
4
+ import pandas as pd
5
+ import streamlit as st
6
+ from tensorus.mcp_client import TensorusMCPClient
7
+
8
+ st.title("Tensorus MCP Client Demo")
9
+ st.markdown("Interact with a Tensorus MCP server without writing any code.")
10
+
11
+ mcp_url = st.text_input("MCP server URL", TensorusMCPClient.DEFAULT_MCP_URL)
12
+
13
+
14
+ def run_async(coro):
15
+ return asyncio.run(coro)
16
+
17
+
18
+ st.header("Datasets")
19
+ if st.button("List datasets"):
20
+
21
+ async def _list():
22
+ async with TensorusMCPClient.from_http(url=mcp_url) as client:
23
+ return await client.list_datasets()
24
+
25
+ result = run_async(_list())
26
+ if result:
27
+ st.write(pd.DataFrame(result.datasets, columns=["Datasets"]))
28
+
29
+ create_name = st.text_input("New dataset name")
30
+ if st.button("Create dataset") and create_name:
31
+
32
+ async def _create():
33
+ async with TensorusMCPClient.from_http(url=mcp_url) as client:
34
+ return await client.create_dataset(create_name)
35
+
36
+ res = run_async(_create())
37
+ if res:
38
+ st.success(res.message or "Dataset created")
39
+
40
+ st.header("Ingest Tensor")
41
+ with st.form("ingest"):
42
+ ingest_ds = st.text_input("Dataset", key="ingest_ds")
43
+ tensor_shape = st.text_input("Tensor shape", value="2,2")
44
+ tensor_dtype = st.text_input("Tensor dtype", value="float32")
45
+ tensor_data = st.text_area("Tensor data (JSON)", value="[[0, 0], [1, 1]]")
46
+ metadata = st.text_area("Metadata (JSON)", value="{}")
47
+ submitted = st.form_submit_button("Ingest")
48
+
49
+ if submitted:
50
+ try:
51
+ shape = [int(x) for x in tensor_shape.split(",") if x.strip()]
52
+ data = json.loads(tensor_data)
53
+ meta = json.loads(metadata) if metadata.strip() else None
54
+
55
+ async def _ingest():
56
+ async with TensorusMCPClient.from_http(url=mcp_url) as client:
57
+ return await client.ingest_tensor(
58
+ dataset_name=ingest_ds,
59
+ tensor_shape=shape,
60
+ tensor_dtype=tensor_dtype,
61
+ tensor_data=data,
62
+ metadata=meta,
63
+ )
64
+
65
+ response = run_async(_ingest())
66
+ st.write(response)
67
+ st.success(f"Ingested tensor {response.id}")
68
+ except Exception as e:
69
+ st.error(f"Failed to ingest: {e}")
70
+
71
+ st.header("Run NQL Query")
72
+ query = st.text_input("Query", key="nql_query")
73
+ if st.button("Execute") and query:
74
+
75
+ async def _query():
76
+ async with TensorusMCPClient.from_http(url=mcp_url) as client:
77
+ return await client.execute_nql_query(query)
78
+
79
+ result = run_async(_query())
80
+ if isinstance(result.results, list):
81
+ st.write(pd.DataFrame(result.results))
82
+ else:
83
+ st.json(result.results)
mcp_client_demo.ipynb ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# Tensorus MCP Client Demo\n",
8
+ "\n",
9
+ "This notebook demonstrates basic usage of `TensorusMCPClient` for creating datasets, ingesting tensors, and running simple queries against the default MCP server."
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "metadata": {},
15
+ "execution_count": null,
16
+ "outputs": [],
17
+ "source": [
18
+ "from tensorus.mcp_client import TensorusMCPClient"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "metadata": {},
24
+ "execution_count": null,
25
+ "outputs": [],
26
+ "source": [
27
+ "import asyncio\n",
28
+ "\n",
29
+ "async def demo():\n",
30
+ " async with TensorusMCPClient.from_http() as client:\n",
31
+ " create_resp = await client.create_dataset(\"demo_ds\")\n",
32
+ " print(\"Create dataset:\", create_resp)\n",
33
+ "\n",
34
+ " ingest_resp = await client.ingest_tensor(\n",
35
+ " dataset_name=\"demo_ds\",\n",
36
+ " tensor_shape=[2, 2],\n",
37
+ " tensor_dtype=\"float32\",\n",
38
+ " tensor_data=[[1.0, 2.0], [3.0, 4.0]],\n",
39
+ " metadata={\"source\": \"demo\"}\n",
40
+ " )\n",
41
+ " print(\"Ingest tensor:\", ingest_resp)\n",
42
+ "\n",
43
+ " datasets = await client.list_datasets()\n",
44
+ " print(\"Datasets:\", datasets.datasets)\n",
45
+ "\n",
46
+ " details = await client.get_tensor_details(\"demo_ds\", ingest_resp.id)\n",
47
+ " print(\"Tensor details:\", details)\n",
48
+ "\n",
49
+ " count = await client.execute_nql_query(\"count\")\n",
50
+ " print(\"NQL count result:\", count.results)\n",
51
+ "\n",
52
+ "await demo()"
53
+ ]
54
+ }
55
+ ],
56
+ "metadata": {
57
+ "kernelspec": {
58
+ "display_name": "Python 3",
59
+ "language": "python",
60
+ "name": "python3"
61
+ },
62
+ "language_info": {
63
+ "name": "python",
64
+ "pygments_lexer": "ipython3"
65
+ }
66
+ },
67
+ "nbformat": 4,
68
+ "nbformat_minor": 5
69
+ }
mcp_client_requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # Minimal requirements for demo/mcp_client_app.py
2
+ fastmcp>=0.2.0
3
+ streamlit>=1.25.0
4
+ pandas>=1.5.0