Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .changes/unreleased/Under the Hood-20250722-195218.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Under the Hood
body: Remote MCP example
time: 2025-07-22T19:52:18.225991-05:00
1 change: 1 addition & 0 deletions examples/remote_mcp/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
Empty file added examples/remote_mcp/README.md
Empty file.
62 changes: 62 additions & 0 deletions examples/remote_mcp/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import asyncio
import contextlib
import json
import os
from collections.abc import AsyncGenerator

from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
from mcp.types import TextContent


@contextlib.asynccontextmanager
async def session_context(
*, url: str, headers: dict[str, str]
) -> AsyncGenerator[ClientSession, None]:
async with (
streamablehttp_client(
url=url,
headers=headers,
) as (
read_stream,
write_stream,
_,
),
ClientSession(read_stream, write_stream) as session,
):
await session.initialize()
yield session


async def main():
async with session_context(
url=f"https://{os.environ.get('DBT_HOST')}/api/ai/v1/mcp/",
headers={
"Authorization": f"token {os.environ.get('DBT_TOKEN')}",
"x-dbt-prod-environment-id": os.environ.get("DBT_PROD_ENV_ID"),
},
) as session:
available_metrics = await session.call_tool(
name="list_metrics",
arguments={},
)
metrics_content = [
t for t in available_metrics.content if isinstance(t, TextContent)
]
metrics_names = [json.loads(m.text)["name"] for m in metrics_content]
print(f"Available metrics: {', '.join(metrics_names)}\n")
num_food_orders = await session.call_tool(
name="query_metrics",
arguments={
"metrics": [
"food_orders",
],
},
)
num_food_order_content = num_food_orders.content[0]
assert isinstance(num_food_order_content, TextContent)
print(f"Number of food orders: {num_food_order_content.text}")


if __name__ == "__main__":
asyncio.run(main())
9 changes: 9 additions & 0 deletions examples/remote_mcp/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "remote-mcp"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"mcp>=1.12.1",
]
Loading
Loading